Skip to content

Commit c45c94e

Browse files
harrymanderradoering
authored andcommitted
fix: append subdirectory to archive path (#7580)
(cherry picked from commit f27308f)
1 parent ef8ace3 commit c45c94e

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

src/poetry/installation/executor.py

+4-23
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def _install(self, operation: Install | Update) -> int:
506506
elif package.source_type == "file":
507507
archive = self._prepare_archive(operation)
508508
elif package.source_type == "directory":
509-
archive = self._prepare_directory_archive(operation)
509+
archive = self._prepare_archive(operation)
510510
cleanup_archive = True
511511
elif package.source_type == "url":
512512
assert package.source_url is not None
@@ -569,34 +569,15 @@ def _prepare_archive(self, operation: Install | Update) -> Path:
569569

570570
assert package.source_url is not None
571571
archive = Path(package.source_url)
572+
if package.source_subdirectory:
573+
archive = archive / package.source_subdirectory
572574
if not Path(package.source_url).is_absolute() and package.root_dir:
573575
archive = package.root_dir / archive
574576

575577
self._populate_hashes_dict(archive, package)
576578

577579
return self._chef.prepare(archive, editable=package.develop)
578580

579-
def _prepare_directory_archive(self, operation: Install | Update) -> Path:
580-
package = operation.package
581-
operation_message = self.get_operation_message(operation)
582-
583-
message = (
584-
f" <fg=blue;options=bold>•</> {operation_message}:"
585-
" <info>Building...</info>"
586-
)
587-
self._write(operation, message)
588-
589-
assert package.source_url is not None
590-
if package.root_dir:
591-
req = package.root_dir / package.source_url
592-
else:
593-
req = Path(package.source_url).resolve(strict=False)
594-
595-
if package.source_subdirectory:
596-
req /= package.source_subdirectory
597-
598-
return self._prepare_archive(operation)
599-
600581
def _prepare_git_archive(self, operation: Install | Update) -> Path:
601582
from poetry.vcs.git import Git
602583

@@ -619,7 +600,7 @@ def _prepare_git_archive(self, operation: Install | Update) -> Path:
619600
original_url = package.source_url
620601
package._source_url = str(source.path)
621602

622-
archive = self._prepare_directory_archive(operation)
603+
archive = self._prepare_archive(operation)
623604

624605
package._source_url = original_url
625606

tests/installation/test_executor.py

+31
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,37 @@ def test_executor_should_write_pep610_url_references_for_git(
776776
)
777777

778778

779+
def test_executor_should_append_subdirectory_for_git(
780+
mocker: MockerFixture,
781+
tmp_venv: VirtualEnv,
782+
pool: RepositoryPool,
783+
config: Config,
784+
io: BufferedIO,
785+
mock_file_downloads: None,
786+
wheel: Path,
787+
) -> None:
788+
package = Package(
789+
"demo",
790+
"0.1.2",
791+
source_type="git",
792+
source_reference="master",
793+
source_resolved_reference="123456",
794+
source_url="https://github.com/demo/subdirectories.git",
795+
source_subdirectory="two",
796+
)
797+
798+
chef = Chef(config, tmp_venv, Factory.create_pool(config))
799+
chef.set_directory_wheel(wheel)
800+
spy = mocker.spy(chef, "prepare")
801+
802+
executor = Executor(tmp_venv, pool, config, io)
803+
executor._chef = chef
804+
executor.execute([Install(package)])
805+
806+
archive_arg = spy.call_args[0][0]
807+
assert archive_arg == tmp_venv.path / "src/demo/subdirectories/two"
808+
809+
779810
def test_executor_should_write_pep610_url_references_for_git_with_subdirectories(
780811
tmp_venv: VirtualEnv,
781812
pool: RepositoryPool,

0 commit comments

Comments
 (0)