Skip to content

Commit

Permalink
Merge pull request #145 from conda-incubator/whitespace-prune
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Feb 10, 2022
2 parents a14077f + 4595f84 commit 2fc0fa8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions conda_lock/src_parser/environment_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
from .pyproject_toml import parse_python_requirement


_whitespace = re.compile(r"\s+")
_conda_package_pattern = re.compile(r"^(?P<name>[A-Za-z0-9_-]+)\s?(?P<version>.*)?$")


def parse_conda_requirement(req: str) -> Tuple[str, str]:
match = re.match(r"^(?P<name>[A-Za-z0-9_-]+)\s?(?P<version>.*)?$", req)
match = _conda_package_pattern.match(req)
if match:
return match.group("name"), match.group("version")
return match.group("name"), _whitespace.sub("", match.group("version"))
else:
raise ValueError(f"Can't parse conda spec from '{req}'")

Expand Down
1 change: 1 addition & 0 deletions conda_lock/src_parser/meta_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def add_spec(spec: str, category: str):
manager="conda",
optional=category != "main",
category=category,
normalize_name=False,
)
dep.selectors.platform = [platform]
depenencies.append(dep)
Expand Down
6 changes: 5 additions & 1 deletion conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def parse_python_requirement(
manager: Literal["conda", "pip"] = "conda",
optional: bool = False,
category: str = "main",
normalize_name: bool = True,
) -> Dependency:
"""Parse a requirements.txt like requirement to a conda spec"""
requirement_specifier = requirement.split(";")[0].strip()
Expand All @@ -253,7 +254,10 @@ def parse_python_requirement(
collapsed_version = ",".join("".join(spec) for spec in parsed_req.specs)
conda_version = poetry_version_to_conda_version(collapsed_version)

conda_dep_name = normalize_pypi_name(name)
if normalize_name:
conda_dep_name = normalize_pypi_name(name)
else:
conda_dep_name = name
extras = list(parsed_req.extras)

if parsed_req.url: # type: ignore[attr-defined]
Expand Down
3 changes: 2 additions & 1 deletion tests/gdal/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ channels:
- conda-forge
- defaults
dependencies:
- python >=3.7,<3.8
# purposefully using a badly formatted environment.yaml here
- python >= 3.7, < 3.8
- gdal
- pip:
- toolz

0 comments on commit 2fc0fa8

Please sign in to comment.