macro128 / pdm-conda

A PDM plugin to resolve/install/uninstall project dependencies with Conda
33 stars 1 forks source link

AttributeError: 'PythonEnvironment' object has no attribute 'env_dependencies' #24

Closed Firionus closed 9 months ago

Firionus commented 9 months ago

Steps to reproduce

Dockerfile ```Dockerfile FROM continuumio/miniconda3:23.9.0-0 RUN apt-get update RUN apt-get install -y curl RUN curl -sSL https://pdm-project.org/install-pdm.py | python3 - ENV PATH="/root/.local/bin:${PATH}" RUN pdm self add pdm-conda ```
Console Dump from Docker Container ``` (base) root@67adafac36ce:/# pdm add -gv cowsay Changes are written to pyproject.toml. Adding packages to default dependencies: cowsay STATUS: Resolving dependencies pdm.termui: ======== Start resolving requirements ======== pdm.termui: pip pdm.termui: setuptools pdm.termui: wheel pdm.termui: cowsay pdm.termui: python>=3.11.5,<3.11.6 pdm.termui: Adding requirement pip pdm.termui: Adding requirement setuptools pdm.termui: Adding requirement wheel pdm.termui: Adding requirement cowsay pdm.termui: Adding requirement python>=3.11.5,<3.11.6 pdm.termui: ======== Starting round 0 ======== STATUS: Resolving: new pin python>=3.11.5,<3.11.6 pdm.termui: Pinning: python None pdm.termui: ======== Ending round 0 ======== pdm.termui: ======== Starting round 1 ======== STATUS: Resolving: new pin cowsay 6.1 pdm.termui: Pinning: cowsay 6.1 pdm.termui: ======== Ending round 1 ======== pdm.termui: ======== Starting round 2 ======== STATUS: Resolving: new pin pip 23.3.1 pdm.termui: Pinning: pip 23.3.1 pdm.termui: ======== Ending round 2 ======== pdm.termui: ======== Starting round 3 ======== STATUS: Resolving: new pin setuptools 68.2.2 pdm.termui: Pinning: setuptools 68.2.2 pdm.termui: ======== Ending round 3 ======== pdm.termui: ======== Starting round 4 ======== STATUS: Resolving: new pin wheel 0.41.3 pdm.termui: Pinning: wheel 0.41.3 pdm.termui: ======== Ending round 4 ======== pdm.termui: ======== Starting round 5 ======== pdm.termui: ======== Resolution Result ======== pdm.termui: Stable pins: pdm.termui: python None pdm.termui: cowsay 6.1 pdm.termui: pip 23.3.1 pdm.termui: setuptools 68.2.2 pdm.termui: wheel 0.41.3 STATUS: Fetching hashes for resolved packages... pdm.termui: Fetching hashes for cowsay@6.1 pdm.termui: Fetching hashes for wheel@0.41.3 pdm.termui: Fetching hashes for pip@23.3.1 pdm.termui: Fetching hashes for setuptools@68.2.2 🔒 Lock successful Changes are written to pyproject.toml. STATUS: Resolving packages from lockfile... STATUS: Fetching hashes for resolved packages... Synchronizing working set with resolved packages: 1 to add, 3 to update, 0 to remove pdm.termui: Removing distribution pip unearth.preparer: Downloading (2.1 MB) ✔ Update pip 23.2.1 -> 23.3.1 successful pdm.termui: Removing distribution setuptools unearth.preparer: Downloading (807 kB) Error processing line 1 of /opt/conda/lib/python3.11/site-packages/distutils-precedence.pth: Traceback (most recent call last): File "", line 186, in addpackage File "", line 1, in ModuleNotFoundError: No module named '_distutils_hack' Remainder of file ignored ✔ Update setuptools 68.0.0 -> 68.2.2 successful pdm.termui: Removing distribution wheel unearth.preparer: Downloading (65 kB) ✔ Update wheel 0.41.2 -> 0.41.3 successful unearth.preparer: Downloading (25 kB) ✔ Install cowsay 6.1 successful 🎉 All complete! (base) root@67adafac36ce:/# pdm remove -gv cowsay Removing packages from default dependencies: cowsay Changes are written to pyproject.toml. STATUS: Resolving dependencies pdm.termui: ======== Start resolving requirements ======== pdm.termui: pip pdm.termui: setuptools pdm.termui: wheel pdm.termui: python>=3.11.5,<3.11.6 pdm.termui: Adding requirement pip pdm.termui: Adding requirement setuptools pdm.termui: Adding requirement wheel pdm.termui: Adding requirement python>=3.11.5,<3.11.6 pdm.termui: ======== Starting round 0 ======== STATUS: Resolving: new pin python>=3.11.5,<3.11.6 pdm.termui: Pinning: python None pdm.termui: ======== Ending round 0 ======== pdm.termui: ======== Starting round 1 ======== STATUS: Resolving: new pin pip 23.3.1 pdm.termui: Pinning: pip 23.3.1 pdm.termui: ======== Ending round 1 ======== pdm.termui: ======== Starting round 2 ======== STATUS: Resolving: new pin setuptools 68.2.2 pdm.termui: Pinning: setuptools 68.2.2 pdm.termui: ======== Ending round 2 ======== pdm.termui: ======== Starting round 3 ======== STATUS: Resolving: new pin wheel 0.41.3 pdm.termui: Pinning: wheel 0.41.3 pdm.termui: ======== Ending round 3 ======== pdm.termui: ======== Starting round 4 ======== pdm.termui: ======== Resolution Result ======== pdm.termui: Stable pins: pdm.termui: python None pdm.termui: pip 23.3.1 pdm.termui: setuptools 68.2.2 pdm.termui: wheel 0.41.3 STATUS: Fetching hashes for resolved packages... pdm.termui: Fetching hashes for wheel@0.41.3 pdm.termui: Fetching hashes for pip@23.3.1 pdm.termui: Fetching hashes for setuptools@68.2.2 🔒 Lock successful Changes are written to pdm.lock. STATUS: Resolving packages from lockfile... STATUS: Fetching hashes for resolved packages... Traceback (most recent call last): File "/root/.local/bin/pdm", line 8, in sys.exit(main()) ^^^^^^ File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/core.py", line 295, in main return Core().main(args or sys.argv[1:]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/core.py", line 208, in main raise cast(Exception, err).with_traceback(traceback) from None File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/core.py", line 203, in main self.handle(project, options) File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/core.py", line 157, in handle command.handle(project, options) File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm_conda/cli/commands/remove.py", line 45, in handle super().handle(project, options) File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/cli/commands/remove.py", line 50, in handle self.do_remove( File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/cli/commands/remove.py", line 113, in do_remove do_sync( File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/cli/actions.py", line 215, in do_sync synchronizer.synchronize() File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm/installers/synchronizers.py", line 387, in synchronize to_add, to_update, to_remove = self.compare_with_working_set() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm_conda/installers/synchronizers.py", line 53, in compare_with_working_set to_remove = [p for p in to_remove if p not in self.environment.env_dependencies] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.local/share/pdm/venv/lib/python3.11/site-packages/pdm_conda/installers/synchronizers.py", line 53, in to_remove = [p for p in to_remove if p not in self.environment.env_dependencies] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'PythonEnvironment' object has no attribute 'env_dependencies' (base) root@67adafac36ce:/# cowsay -t "I'm still here" ______________ | I'm still here | ============== \ \ ^__^ (oo)\_______ (__)\ )\/\ ||----w | || || ```

Actual behavior

Expected behavior

Environment Information

(base) root@67adafac36ce:/# pdm info -g
PDM version:
  2.10.1
Python Interpreter:
  /opt/conda/bin/python (3.11)
Project Root:
  /root/.config/pdm/global-project
Local Packages:

(base) root@67adafac36ce:/# pdm info --env -g
{
  "implementation_name": "cpython",
  "implementation_version": "3.11.5",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.15.0-88-generic",
  "platform_system": "Linux",
  "platform_version": "#98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023",
  "python_full_version": "3.11.5",
  "platform_python_implementation": "CPython",
  "python_version": "3.11",
  "sys_platform": "linux"
}
macro128 commented 9 months ago

Hi! I never tested the plugin behavior when using --global flag, if you want to alter some packages from the base environment just activate it and run pdm inside, if you initialized pdm-conda configs on pyproject.toml then it should work correctly. If you invoke pdm add --conda cowsay --runner micromamba --channel conda-forge or use the following configuration

[tool.pdm.conda]
runner = "micromamba"
channels = ["conda-forge"]
as-default-manager = true

Then pdm should modify the active conda environment using micromamba correctly.

I might fix --global flag compatibility in the future but it's not a priority right now.

Firionus commented 9 months ago

Hey :wave: ,

thanks for the response. I think for we can close this. Since 2.10.2 pdm disallows changing the global conda env.