Skip to content

Commit

Permalink
fix: ignore venv directory and non poetry pyproject.toml files (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal authored Dec 13, 2024
1 parent a525c9f commit fe519a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/poetry_plugin_freeze/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from cleo.helpers import option
from poetry.console.commands.command import Command
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.pyproject.exceptions import PyProjectException
from poetry.core.version.markers import MultiMarker, SingleMarker
from poetry.packages import DependencyPackage
from poetry.utils.env import EnvManager
from poetry.core.masonry.metadata import Metadata
from poetry.core.masonry.utils.helpers import distribution_name
from poetry.core.version.markers import union as marker_union
Expand All @@ -39,15 +41,27 @@ class FreezeCommand(Command):
),
]

def project_roots(self, root):
env = EnvManager(self.poetry).get()

excludes = []
if env.is_venv():
excludes.append(env.path)

return project_roots(root, *excludes)

def handle(self) -> int:
self.line("freezing wheels")
root_dir = self._io and self._io.input.option("directory") or Path.cwd()

fridge = {}
for project_root in project_roots(root_dir):
iced = IcedPoet(project_root, self.option("wheel-dir"), self.option("exclude"))
iced.check()
fridge[iced.name] = iced
for project_root in self.project_roots(root_dir):
try:
iced = IcedPoet(project_root, self.option("wheel-dir"), self.option("exclude"))
iced.check()
fridge[iced.name] = iced
except PyProjectException:
pass

for iced in fridge.values():
iced.set_fridge(fridge)
Expand All @@ -66,9 +80,17 @@ def activate(self, application):
application.command_loader.register_factory("freeze-wheel", factory)


def project_roots(root):
def config_path_excluded(config_path, *excludes):
for exclude in excludes:
if str(config_path).startswith(str(exclude)):
return True
return False


def project_roots(root, *excludes):
for config_path in Path(root).rglob("pyproject.toml"):
yield config_path.parent
if not config_path_excluded(config_path, *excludes):
yield config_path.parent


def get_sha256_digest(content: bytes):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def test_project_roots(fixture_root):
]


def test_excluded_config_path_project_roots(fixture_root):
assert sorted(project_roots(fixture_root, fixture_root / "nested_packages" / "others")) == [
fixture_root / "nested_packages"
]


def parse_md(md_text: bytes):
return Parser().parsestr(md_text.decode("utf8"))

Expand Down

0 comments on commit fe519a4

Please sign in to comment.