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

conda-lock 1.4.1 fails to generate lock file from pyproject.toml with mixed conda-forge/PyPI dependencies #55

Closed
cameronraysmith opened this issue Feb 6, 2023 · 3 comments
Labels
external issue with external tool
Milestone

Comments

@cameronraysmith
Copy link
Collaborator

cameronraysmith commented Feb 6, 2023

This issue is related to

Conda-lock configuration is specified near

[tool.conda-lock]

PyPI dependencies are marked explicitly as in

cospar = { version = "0.1.9", source = "pypi" }

A command similar to

conda-lock \
--conda mamba \
--extras dev \
--filter-extras \
--no-dev-dependencies \
--virtual-package-spec conda/virtual-packages.yml \
--log-level DEBUG \
-f pyproject.toml \
-p linux-64

from the repo root with conda-lock version 1.4.0 fails to produce a valid conda lock file due to failure to resolve PyPI dependencies whose name contains a hyphen vs underscore.

The specific error is related to the translation of package names between conda and PyPI with matplotlib_base vs matplotlib-base vs matplotlib

conda-lock stderr
Traceback (most recent call last):
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 488, in seperator_munge_get
    return d[key]
KeyError: 'matplotlib-base'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 491, in seperator_munge_get
    return d[key.replace("-", "_")]
KeyError: 'matplotlib_base'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".local/bin/conda-lock", line 8, in <module>
    sys.exit(main())
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 1353, in lock
    lock_func(
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 1083, in run_lock
    make_lock_files(
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 408, in make_lock_files
    lock_content = lock_content | create_lockfile_from_spec(
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 801, in create_lockfile_from_spec
    deps = _solve_for_arch(
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/conda_lock.py", line 737, in _solve_for_arch
    pip_deps = solve_pypi(
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/pypi_solver.py", line 327, in solve_pypi
    src_parser._apply_categories(requested=pip_specs, planned=planned)
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 502, in _apply_categories
    for dep in seperator_munge_get(planned, item).dependencies
  File ".local/pipx/venvs/conda-lock/lib/python3.9/site-packages/conda_lock/src_parser/__init__.py", line 493, in seperator_munge_get
    return d[key.replace("_", "-")]
KeyError: 'matplotlib-base'

The approach described here would likely work, but since it would still require maintenance of two separate lists of dependencies it is not necessarily better than manually synchronizing pyproject.toml with environment.yml.

@cameronraysmith cameronraysmith added the external issue with external tool label Feb 6, 2023
@cameronraysmith cameronraysmith added this to the packaging milestone Feb 13, 2023
@cameronraysmith cameronraysmith modified the milestones: packaging, 0.1.2 Mar 16, 2023
@cameronraysmith cameronraysmith modified the milestones: 0.1.2, 0.1.3 Apr 19, 2023
@cameronraysmith
Copy link
Collaborator Author

cameronraysmith commented May 18, 2023

fixed in conda/conda-lock#290

pipx install git+https://github.com/conda/conda-lock.git

installs conda-lock, version 1.4.1.dev119+g4a667bd on 5/20/2023.

conda-lock \
--conda mamba \
--filter-extras \
--no-dev-dependencies \
--virtual-package-spec conda/virtual-packages.yml \
--log-level INFO \
-f pyproject.toml \
-p linux-64

succeeds with appropriate annotation in pyproject.toml of packages only available on PyPI, e.g.

seaborn = { version = "0.11.2", source = "pypi" }

and the resulting conda-lock.yml is installable with

conda-lock install -n [ENVIRONMENT NAME] --file conda-lock.yml

@cameronraysmith cameronraysmith changed the title conda-lock 1.4.0 fails to generate lock file from pyproject.toml with mixed conda-forge/PyPI dependencies conda-lock 1.4.1 fails to generate lock file from pyproject.toml with mixed conda-forge/PyPI dependencies May 20, 2023
@qinqian
Copy link
Collaborator

qinqian commented Jun 20, 2023

can we close this issue? @cameronraysmith

@cameronraysmith
Copy link
Collaborator Author

reopen this when switching to conda-lock

@cameronraysmith cameronraysmith closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external issue with external tool
Projects
None yet
Development

No branches or pull requests

2 participants