-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #712 from romain-intel/feat/improve-poetry-support
Add/improve support for Path dependencies and GIT dependencies
- Loading branch information
Showing
11 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
from conda_lock.models.lock_spec import ( | ||
Dependency, | ||
LockSpecification, | ||
PathDependency, | ||
PoetryMappedDependencySpec, | ||
URLDependency, | ||
VCSDependency, | ||
|
@@ -128,6 +129,17 @@ def handle_mapping( | |
if "git" in depattrs: | ||
url: Optional[str] = depattrs.get("git", None) | ||
manager = "pip" | ||
# Order is the same as the one used by poetry | ||
branch_ident = depattrs.get( | ||
"branch", depattrs.get("tag", depattrs.get("rev", None)) | ||
) | ||
if branch_ident is not None: | ||
url += "@" + branch_ident | ||
if "subdirectory" in depattrs: | ||
url += "#subdirectory=" + depattrs["subdirectory"] | ||
elif "path" in depattrs: | ||
url = depattrs.get("path", None) | ||
manager = "pip" | ||
else: | ||
poetry_version_spec = depattrs.get("version", None) | ||
url = depattrs.get("url", None) | ||
|
@@ -284,7 +296,7 @@ def parse_poetry_pyproject_toml( | |
version = poetry_version_to_conda_version(poetry_version_spec) | ||
|
||
if "git" in depattrs and url is not None: | ||
url, rev = unpack_git_url(url) | ||
url, rev, subdir = unpack_git_url(url) | ||
dependencies.append( | ||
VCSDependency( | ||
name=name, | ||
|
@@ -293,6 +305,20 @@ def parse_poetry_pyproject_toml( | |
manager=manager, | ||
vcs="git", | ||
rev=rev, | ||
subdirectory=subdir, | ||
) | ||
) | ||
elif "path" in depattrs and url is not None: | ||
path = pathlib.Path(url) | ||
path.resolve() | ||
is_dir = path.is_dir() | ||
dependencies.append( | ||
PathDependency( | ||
name=name, | ||
markers=markers, | ||
path=path.as_posix(), | ||
is_directory=is_dir, | ||
manager=manager, | ||
) | ||
) | ||
elif version is None: | ||
|
@@ -423,20 +449,23 @@ def parse_requirement_specifier( | |
return RequirementWithHash(requirement) | ||
|
||
|
||
def unpack_git_url(url: str) -> Tuple[str, Optional[str]]: | ||
def unpack_git_url(url: str) -> Tuple[str, Optional[str], Optional[str]]: | ||
if url.endswith(".git"): | ||
url = url[:-4] | ||
if url.startswith("git+"): | ||
url = url[4:] | ||
rev = None | ||
subdir = None | ||
if "@" in url: | ||
try: | ||
url, rev = url.split("@") | ||
except ValueError: | ||
# SSH URLs can have multiple @s | ||
url1, url2, rev = url.split("@") | ||
url = f"{url1}@{url2}" | ||
return url, rev | ||
if rev and "#subdirectory=" in rev: | ||
rev, subdir = rev.split("#subdirectory=") | ||
return url, rev, subdir | ||
|
||
|
||
def parse_python_requirement( | ||
|
@@ -487,7 +516,15 @@ def parse_python_requirement( | |
... ) # doctest: +NORMALIZE_WHITESPACE | ||
VCSDependency(name='conda-lock', manager='conda', category='main', extras=[], | ||
markers=None, source='https://github.com/conda/conda-lock.git', vcs='git', | ||
rev='v2.4.1') | ||
rev='v2.4.1', subdirectory=None) | ||
>>> parse_python_requirement( | ||
... "conda-lock @ git+https://github.com/conda/[email protected]#subdirectory=src", | ||
... mapping_url=DEFAULT_MAPPING_URL, | ||
... ) # doctest: +NORMALIZE_WHITESPACE | ||
VCSDependency(name='conda-lock', manager='conda', category='main', extras=[], | ||
markers=None, source='https://github.com/conda/conda-lock.git', vcs='git', | ||
rev='v2.4.1', subdirectory='src') | ||
>>> parse_python_requirement( | ||
... "some-package @ https://some-repository.org/some-package-1.2.3.tar.gz", | ||
|
@@ -504,6 +541,24 @@ def parse_python_requirement( | |
VersionedDependency(name='some-package', manager='conda', category='main', | ||
extras=[], markers="sys_platform == 'darwin'", version='*', build=None, | ||
conda_channel=None, hash=None) | ||
>>> parse_python_requirement( | ||
... "mypkg @ /path/to/some-package", | ||
... manager="pip", | ||
... mapping_url=DEFAULT_MAPPING_URL, | ||
... ) # doctest: +NORMALIZE_WHITESPACE | ||
PathDependency(name='mypkg', manager='pip', category='main', | ||
extras=[], markers=None, path='/path/to/some-package', is_directory=False, | ||
subdirectory=None) | ||
>>> parse_python_requirement( | ||
... "mypkg @ file:///path/to/some-package", | ||
... manager="pip", | ||
... mapping_url=DEFAULT_MAPPING_URL, | ||
... ) # doctest: +NORMALIZE_WHITESPACE | ||
PathDependency(name='mypkg', manager='pip', category='main', | ||
extras=[], markers=None, path='/path/to/some-package', is_directory=False, | ||
subdirectory=None) | ||
""" | ||
if ";" in requirement: | ||
requirement, markers = (s.strip() for s in requirement.rsplit(";", 1)) | ||
|
@@ -523,7 +578,7 @@ def parse_python_requirement( | |
extras = list(parsed_req.extras) | ||
|
||
if parsed_req.url and parsed_req.url.startswith("git+"): | ||
url, rev = unpack_git_url(parsed_req.url) | ||
url, rev, subdir = unpack_git_url(parsed_req.url) | ||
return VCSDependency( | ||
name=conda_dep_name, | ||
source=url, | ||
|
@@ -532,17 +587,39 @@ def parse_python_requirement( | |
vcs="git", | ||
rev=rev, | ||
markers=markers, | ||
subdirectory=subdir, | ||
) | ||
elif parsed_req.url: | ||
assert conda_version in {"", "*", None} | ||
url, frag = urldefrag(parsed_req.url) | ||
return URLDependency( | ||
if ( | ||
parsed_req.url.startswith("git+") | ||
or parsed_req.url.startswith("https://") | ||
or parsed_req.url.startswith("ssh://") | ||
): | ||
url, frag = urldefrag(parsed_req.url) | ||
return URLDependency( | ||
name=conda_dep_name, | ||
manager=manager, | ||
category=category, | ||
extras=extras, | ||
url=url, | ||
hashes=[frag.replace("=", ":")], | ||
markers=markers, | ||
) | ||
# Local file/directory URL | ||
url = parsed_req.url | ||
if url.startswith("file://"): | ||
url = url[7:] | ||
path = pathlib.Path(url) | ||
path.resolve() | ||
is_dir = path.is_dir() | ||
return PathDependency( | ||
name=conda_dep_name, | ||
manager=manager, | ||
category=category, | ||
extras=extras, | ||
url=url, | ||
hashes=[frag.replace("=", ":")], | ||
path=path.as_posix(), | ||
is_directory=is_dir, | ||
markers=markers, | ||
) | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[tool.poetry] | ||
name = "conda-lock-test-poetry" | ||
version = "0.0.1" | ||
description = "" | ||
authors = ["conda-lock"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
requests = "^2.13.0" | ||
toml = ">=0.10" | ||
tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "~5.1.0" | ||
tensorflow = { git = "git+https://github.com/tensorflow/[email protected]", subdirectory = "tensorflow/tools/pip_package" } | ||
|
||
[build-system] | ||
requires = ["poetry>=0.12"] | ||
build-backend = "poetry.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Metadata-Version: 2.1 | ||
Name: fake-private-package | ||
Version: 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[egg_info] | ||
tag_build = | ||
tag_date = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from setuptools import setup | ||
|
||
|
||
setup( | ||
name="fake-private-package", | ||
version="1.0.0", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[tool.poetry] | ||
name = "conda-lock-test-poetry" | ||
version = "0.0.1" | ||
description = "" | ||
authors = ["conda-lock"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
pytest = "~5.1.0" | ||
fake-private-package = { path = "./fake-private-package-1.0.0" } | ||
|
||
[build-system] | ||
requires = ["poetry>=0.12"] | ||
build-backend = "poetry.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters