Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: append subdirectory to archive path (#7575) #7580

Merged
merged 3 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def _install(self, operation: Install | Update) -> int:
elif package.source_type == "file":
archive = self._prepare_archive(operation)
elif package.source_type == "directory":
archive = self._prepare_directory_archive(operation)
archive = self._prepare_archive(operation)
cleanup_archive = True
elif package.source_type == "url":
assert package.source_url is not None
Expand Down Expand Up @@ -569,34 +569,15 @@ def _prepare_archive(self, operation: Install | Update) -> Path:

assert package.source_url is not None
archive = Path(package.source_url)
if package.source_subdirectory:
archive = archive / package.source_subdirectory
if not Path(package.source_url).is_absolute() and package.root_dir:
archive = package.root_dir / archive

self._populate_hashes_dict(archive, package)

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

def _prepare_directory_archive(self, operation: Install | Update) -> Path:
package = operation.package
operation_message = self.get_operation_message(operation)

message = (
f" <fg=blue;options=bold>•</> {operation_message}:"
" <info>Building...</info>"
)
self._write(operation, message)

assert package.source_url is not None
if package.root_dir:
req = package.root_dir / package.source_url
else:
req = Path(package.source_url).resolve(strict=False)

if package.source_subdirectory:
req /= package.source_subdirectory

return self._prepare_archive(operation)

def _prepare_git_archive(self, operation: Install | Update) -> Path:
from poetry.vcs.git import Git

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

archive = self._prepare_directory_archive(operation)
archive = self._prepare_archive(operation)

package._source_url = original_url

Expand Down
31 changes: 31 additions & 0 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,37 @@ def test_executor_should_write_pep610_url_references_for_git(
)


def test_executor_should_append_subdirectory_for_git(
mocker: MockerFixture,
tmp_venv: VirtualEnv,
pool: RepositoryPool,
config: Config,
io: BufferedIO,
mock_file_downloads: None,
wheel: Path,
) -> None:
package = Package(
"demo",
"0.1.2",
source_type="git",
source_reference="master",
source_resolved_reference="123456",
source_url="https://github.com/demo/subdirectories.git",
source_subdirectory="two",
)

chef = Chef(config, tmp_venv, Factory.create_pool(config))
chef.set_directory_wheel(wheel)
spy = mocker.spy(chef, "prepare")

executor = Executor(tmp_venv, pool, config, io)
executor._chef = chef
executor.execute([Install(package)])

archive_arg = spy.call_args[0][0]
assert archive_arg == tmp_venv.path / "src/demo/subdirectories/two"


def test_executor_should_write_pep610_url_references_for_git_with_subdirectories(
tmp_venv: VirtualEnv,
pool: RepositoryPool,
Expand Down