From cb3ed03fc3b7cae73e61f97cc179a08700bb2327 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 7 May 2022 17:18:05 +0100 Subject: [PATCH] introduce default_target_dir on builders --- src/poetry/core/masonry/builders/builder.py | 6 +++++- src/poetry/core/masonry/builders/sdist.py | 8 ++++---- src/poetry/core/masonry/builders/wheel.py | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/poetry/core/masonry/builders/builder.py b/src/poetry/core/masonry/builders/builder.py index ccda80644..517b2ee2c 100644 --- a/src/poetry/core/masonry/builders/builder.py +++ b/src/poetry/core/masonry/builders/builder.py @@ -40,7 +40,7 @@ def __init__( self._poetry = poetry self._package = poetry.package - self._path = poetry.file.parent + self._path: Path = poetry.file.parent self._excluded_files: set[str] | None = None self._executable = Path(executable or sys.executable) @@ -93,6 +93,10 @@ def __init__( def executable(self) -> Path: return self._executable + @property + def default_target_dir(self) -> Path: + return self._path / "dist" + def build(self, target_dir: Path | None) -> Path: raise NotImplementedError() diff --git a/src/poetry/core/masonry/builders/sdist.py b/src/poetry/core/masonry/builders/sdist.py index 1c708db23..ecdd08a49 100644 --- a/src/poetry/core/masonry/builders/sdist.py +++ b/src/poetry/core/masonry/builders/sdist.py @@ -60,7 +60,7 @@ def build( target_dir: Path | None = None, ) -> Path: logger.info("Building sdist") - target_dir = target_dir or self._path / "dist" + target_dir = target_dir or self.default_target_dir if not target_dir.exists(): target_dir.mkdir(parents=True) @@ -326,15 +326,15 @@ def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile additional_files.update(self.convert_script_files()) # Include project files - additional_files.add("pyproject.toml") + additional_files.add(Path("pyproject.toml")) # add readme if it is specified if "readme" in self._poetry.local_config: additional_files.add(self._poetry.local_config["readme"]) - for file in additional_files: + for additional_file in additional_files: file = BuildIncludeFile( - path=file, project_root=self._path, source_root=self._path + path=additional_file, project_root=self._path, source_root=self._path ) if file.path.exists(): logger.debug(f"Adding: {file.relative_to_source_root()}") diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 7ec872b86..aa87dde31 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -91,9 +91,9 @@ def build( ) -> Path: logger.info("Building wheel") - dist_dir = target_dir or (self._poetry.file.parent / "dist") - if not dist_dir.exists(): - dist_dir.mkdir() + target_dir = target_dir or self.default_target_dir + if not target_dir.exists(): + target_dir.mkdir() (fd, temp_path) = tempfile.mkstemp(suffix=".whl") @@ -119,7 +119,7 @@ def build( self._write_metadata(zip_file) self._write_record(zip_file) - wheel_path = dist_dir / self.wheel_filename + wheel_path = target_dir / self.wheel_filename if wheel_path.exists(): wheel_path.unlink() shutil.move(temp_path, str(wheel_path))