Skip to content

Commit

Permalink
Add support for subdirectories in git urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ashnair1 authored and radoering committed Aug 10, 2022
1 parent 3921a57 commit 0d43406
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ def _install_directory(self, operation: Install | Update) -> int:
else:
req = Path(package.source_url).resolve(strict=False)

if package.source_subdirectory:
req /= package.source_subdirectory

pyproject = PyProjectTOML(os.path.join(req, "pyproject.toml"))

if pyproject.is_poetry_project():
Expand Down Expand Up @@ -762,6 +765,8 @@ def _create_git_url_reference(self, package: Package) -> dict[str, Any]:
"commit_id": package.source_resolved_reference,
},
}
if package.source_subdirectory:
reference["subdirectory"] = package.source_subdirectory

return reference

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = "^3.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = "^3.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = "~2.7 || ^3.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Empty file.
34 changes: 34 additions & 0 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,40 @@ def test_executor_should_write_pep610_url_references_for_git(
)


def test_executor_should_write_pep610_url_references_for_git_with_subdirectories(
tmp_venv: VirtualEnv,
pool: Pool,
config: Config,
io: BufferedIO,
mock_file_downloads: None,
):
package = Package(
"two",
"2.0.0",
source_type="git",
source_reference="master",
source_resolved_reference="123456",
source_url="https://github.com/demo/subdirectories.git",
source_subdirectory="two",
)

executor = Executor(tmp_venv, pool, config, io)
executor.execute([Install(package)])
verify_installed_distribution(
tmp_venv,
package,
{
"vcs_info": {
"vcs": "git",
"requested_revision": "master",
"commit_id": "123456",
},
"url": package.source_url,
"subdirectory": package.source_subdirectory,
},
)


def test_executor_should_use_cached_link_and_hash(
tmp_venv: VirtualEnv,
pool: Pool,
Expand Down

0 comments on commit 0d43406

Please sign in to comment.