Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring #243

Merged
merged 3 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
For the most up-to-date instructions see the github actions [test.yml workflow](./github/workflows.test.yml)

1. Ensure conda and mamba are installed. Install [mambaforge](https://github.com/conda-forge/miniforge#mambaforge) if you're otherwise not sure which one to pick.
2. `mamba create -n conda-lock-dev pip pytest-cov pytest-xdist pip`
2. `mamba create -n conda-lock-dev pip pytest-cov pytest-xdist`
3. `conda activate conda-lock-dev`
4. `python -m pip install -r requirements-dev.txt`
5. `pip install -e . --no-deps --force-reinstall`
Expand Down
20 changes: 12 additions & 8 deletions conda_lock/pypi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ def solve_pypi(
locked = Repository()

python_packages = dict()
for dep in conda_locked.values():
if dep.name.startswith("__"):
locked_dep: src_parser.LockedDependency
for locked_dep in conda_locked.values():
if locked_dep.name.startswith("__"):
continue
try:
pypi_name = conda_name_to_pypi_name(dep.name).lower()
pypi_name = conda_name_to_pypi_name(locked_dep.name).lower()
except KeyError:
continue
# Prefer the Python package when its name collides with the Conda package
# for the underlying library, e.g. python-xxhash (pypi: xxhash) over xxhash
# (pypi: no equivalent)
if pypi_name not in python_packages or pypi_name != dep.name:
python_packages[pypi_name] = dep.version
if pypi_name not in python_packages or pypi_name != locked_dep.name:
python_packages[pypi_name] = locked_dep.version
# treat conda packages as both locked and installed
for name, version in python_packages.items():
for repo in (locked, installed):
Expand Down Expand Up @@ -275,7 +276,10 @@ def solve_pypi(
else:
link = chooser.choose_for(op.package)
url = link.url_without_fragment
hash = src_parser.HashModel(**{link.hash_name: link.hash})
hashes: Dict[str, str] = {}
if link.hash_name is not None and link.hash is not None:
hashes[link.hash_name] = link.hash
hash = src_parser.HashModel.parse_obj(hashes)

requirements.append(
src_parser.LockedDependency(
Expand All @@ -299,13 +303,13 @@ def solve_pypi(
# prefer conda packages so add them afterwards
}

for conda_name, dep in conda_locked.items():
for conda_name, locked_dep in conda_locked.items():
try:
pypi_name = conda_name_to_pypi_name(conda_name).lower()
except KeyError:
# no conda-name found, assuming conda packages do NOT intersect with the pip package
continue
planned[pypi_name] = dep
planned[pypi_name] = locked_dep

src_parser._apply_categories(requested=pip_specs, planned=planned)

Expand Down