Skip to content

Commit bb1bb61

Browse files
committed
Lazy gather data for Project.
1 parent 0c9ac88 commit bb1bb61

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/makeapp/apptools.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ def __init__(self, project_path: Path = None, *, log_level: int = None):
363363
self.vcs = VcsHelper.get(project_path)
364364
self.venv = VenvHelper(project_path)
365365

366-
with chdir(self.project_path):
367-
self._gather_data()
368-
369366
def configure_logging(self, verbosity_lvl: int = None, format: str = '%(message)s'):
370367
"""Switches on logging at a given level.
371368
@@ -377,33 +374,38 @@ def configure_logging(self, verbosity_lvl: int = None, format: str = '%(message)
377374

378375
def _gather_data(self):
379376
"""Gathers data relevant for project related functions."""
380-
project_path = self.project_path
381377

382-
LOG.debug(f'Gathering info from `{project_path}` directory ...')
378+
if self.package or self.changelog:
379+
return
383380

384-
marker_file = 'pyproject.toml'
381+
with chdir(self.project_path):
382+
project_path = self.project_path
385383

386-
if not os.path.isfile(marker_file):
387-
raise ProjectorExeption(f'No `{marker_file}` file found in the current directory.')
384+
LOG.debug(f'Gathering info from `{project_path}` directory ...')
388385

389-
self.vcs.check()
386+
marker_file = 'pyproject.toml'
390387

391-
parent_dirname = project_path.parent.name
388+
if not os.path.isfile(marker_file):
389+
raise ProjectorExeption(f'No `{marker_file}` file found in the current directory.')
392390

393-
packages = self.find_packages(project_path, prefer=parent_dirname)
394-
if not packages:
395-
# src layout
396-
packages = self.find_packages(project_path / 'src', prefer=parent_dirname)
391+
self.vcs.check()
397392

398-
LOG.debug(f'Found packages: {packages}')
393+
parent_dirname = project_path.parent.name
399394

400-
if not packages:
401-
raise ProjectorExeption('No package found.')
395+
packages = self.find_packages(project_path, prefer=parent_dirname)
396+
if not packages:
397+
# src layout
398+
packages = self.find_packages(project_path / 'src', prefer=parent_dirname)
402399

403-
package = packages[0]
400+
LOG.debug(f'Found packages: {packages}')
404401

405-
self.package = PackageData.get(package_path=package)
406-
self.changelog = ChangelogData.get()
402+
if not packages:
403+
raise ProjectorExeption('No package found.')
404+
405+
package = packages[0]
406+
407+
self.package = PackageData.get(package_path=package)
408+
self.changelog = ChangelogData.get()
407409

408410
def pull(self):
409411
"""Pulls changes from a remote repository"""
@@ -417,6 +419,7 @@ def get_release_info(self, increment: str | None = None) -> tuple[str, str]:
417419
If not set, will be deduced from changelog data.
418420
419421
"""
422+
self._gather_data()
420423
changelog = self.changelog
421424

422425
increment = increment or changelog.deduce_version_increment()
@@ -435,6 +438,7 @@ def release(self, next_version_str: str, version_summary: str):
435438
* Adds changelog info
436439
* Tags VCS
437440
"""
441+
self._gather_data()
438442
vcs = self.vcs
439443

440444
with chdir(self.project_path):
@@ -458,6 +462,7 @@ def add_change(self, descriptions: list[str] | tuple[str, ...] | str, *, stage_m
458462
:param stage_modified: Whether to stage modified files to commit.
459463
460464
"""
465+
self._gather_data()
461466
LOG.debug('Adding change ...')
462467

463468
with chdir(self.project_path):
@@ -502,8 +507,6 @@ def publish(self):
502507
DistHelper.upload()
503508

504509
def venv_init(self, *, reset: bool = False, register_tool: bool = False):
505-
LOG.info(f'Initializing virtual environment [{reset=}, {register_tool=}] ...')
506-
507510
self.venv.initialize(reset=reset)
508511

509512
register_tool and self.venv.register_tool()

src/makeapp/helpers/venvs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def __init__(self, project_path: str):
1616
self.venv_path = Path(project_path) / self.dirname
1717

1818
def initialize(self, *, reset: bool = False):
19+
LOG.info(f'Initializing virtual environment [{reset=}] ...')
20+
1921
if reset:
2022
self.remove()
2123

0 commit comments

Comments
 (0)