Skip to content

Commit

Permalink
Parse SSH git requirements in poetry config. (pantsbuild#13344)
Browse files Browse the repository at this point in the history
Reqs of the form [email protected]:foo/bar.git must be rewritten
to ssh://[email protected]/foo/bar.git to become valid PEP 440 requirements.

[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
benjyw authored Oct 25, 2021
1 parent f03278a commit 8a28934
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/python/pants/backend/python/macros/poetry_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import itertools
import logging
import os
import urllib.parse
from dataclasses import dataclass
from pathlib import Path, PurePath
from typing import Any, Iterable, Iterator, Mapping, Sequence, cast
Expand Down Expand Up @@ -239,6 +240,10 @@ def handle_dict_attr(

git_lookup = attributes.get("git")
if git_lookup is not None:
# If no URL scheme (e.g., `{git = "[email protected]:foo/bar.git"}`) we assume ssh,
# i.e., we convert to git+ssh://[email protected]/foo/bar.git.
if not urllib.parse.urlsplit(git_lookup).scheme:
git_lookup = f"ssh://{git_lookup.replace(':', '/', 1)}"
rev_lookup = produce_match("#", attributes.get("rev"))
branch_lookup = produce_match("@", attributes.get("branch"))
tag_lookup = produce_match("@", attributes.get("tag"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ def assert_git(extra_opts: PyprojectAttr, suffix: str) -> None:
)


def test_handle_git_ssh(empty_pyproject_toml: PyProjectToml) -> None:
attr = PyprojectAttr({"git": "[email protected]:requests/requests.git"})
assert (
handle_dict_attr("requests", attr, empty_pyproject_toml)
== "requests @ git+ssh://[email protected]/requests/requests.git"
)


def test_handle_path_arg(tmp_path: Path) -> None:
build_root = tmp_path / "build_root"

Expand Down

0 comments on commit 8a28934

Please sign in to comment.