Skip to content

Commit

Permalink
Fix doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Sep 15, 2024
1 parent e0a8e01 commit f456d79
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@
def pypi_name_to_conda_name(name: str, mapping_url: str) -> str:
"""Convert a PyPI package name to a conda package name.
>>> pypi_name_to_conda_name("build")
>>> from conda_lock.lookup import DEFAULT_MAPPING_URL
>>> pypi_name_to_conda_name("build", mapping_url=DEFAULT_MAPPING_URL)
'python-build'
>>> pypi_name_to_conda_name("zpfqzvrj")
>>> pypi_name_to_conda_name("zpfqzvrj", mapping_url=DEFAULT_MAPPING_URL)
'zpfqzvrj'
"""
cname = canonicalize_pypi_name(name)
Expand Down Expand Up @@ -472,43 +473,54 @@ def parse_python_requirement(
) -> Dependency:
"""Parse a requirements.txt like requirement to a conda spec.
>>> parse_python_requirement("my_package") # doctest: +NORMALIZE_WHITESPACE
>>> from conda_lock.lookup import DEFAULT_MAPPING_URL
>>> parse_python_requirement(
... "my_package",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='my-package', manager='conda', category='main', extras=[],
markers=None, version='*', build=None, conda_channel=None, hash=None)
The PyPI name `build` will be translated to `python-build` for conda.
>>> parse_python_requirement("build") # doctest: +NORMALIZE_WHITESPACE
>>> parse_python_requirement(
... "build",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='python-build', manager='conda', category='main',
extras=[], markers=None, version='*', build=None, conda_channel=None, hash=None)
No translation is done for `manager="pip"`.
>>> parse_python_requirement("build", manager="pip") # doctest: +NORMALIZE_WHITESPACE
>>> parse_python_requirement("build", manager="pip", mapping_url=DEFAULT_MAPPING_URL) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='build', manager='pip', category='main',
extras=[], markers=None, version='*', build=None, conda_channel=None, hash=None)
>>> parse_python_requirement(
... "My_Package[extra]==1.23"
... "My_Package[extra]==1.23",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='my-package', manager='conda', category='main',
extras=['extra'], markers=None, version='==1.23', build=None,
conda_channel=None, hash=None)
>>> parse_python_requirement(
... "conda-lock @ git+https://github.com/conda/[email protected]"
... "conda-lock @ git+https://github.com/conda/[email protected]",
... 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')
>>> parse_python_requirement(
... "some-package @ https://some-repository.org/some-package-1.2.3.tar.gz"
... "some-package @ https://some-repository.org/some-package-1.2.3.tar.gz",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
URLDependency(name='some-package', manager='conda', category='main', extras=[],
markers=None, url='https://some-repository.org/some-package-1.2.3.tar.gz',
hashes=[''])
>>> parse_python_requirement(
... "some-package ; sys_platform == 'darwin'"
... "some-package ; sys_platform == 'darwin'",
... mapping_url=DEFAULT_MAPPING_URL,
... ) # doctest: +NORMALIZE_WHITESPACE
VersionedDependency(name='some-package', manager='conda', category='main',
extras=[], markers="sys_platform == 'darwin'", version='*', build=None,
Expand Down

0 comments on commit f456d79

Please sign in to comment.