Skip to content

Commit

Permalink
introduce default_target_dir on builders
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed May 15, 2022
1 parent 58d0c1d commit f6258d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def build(
target_dir: Path | None = None,
) -> Path:
logger.info("Building <info>sdist</info>")
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)
Expand Down Expand Up @@ -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()}")
Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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))
Expand Down

0 comments on commit f6258d7

Please sign in to comment.