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

Feat: add support for Conda environments #749

Merged
merged 4 commits into from
Nov 22, 2021

Conversation

agoose77
Copy link
Contributor

@agoose77 agoose77 commented Nov 19, 2021

Pull Request Check List

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

This PR adds support for CONDA_PREFIX where virtual environments are implemented using Conda.

@agoose77 agoose77 marked this pull request as ready for review November 19, 2021 13:03
@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2021

Codecov Report

Merging #749 (8d14c40) into main (9ed9e07) will decrease coverage by 0.14%.
The diff coverage is 22.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #749      +/-   ##
==========================================
- Coverage   83.53%   83.39%   -0.15%     
==========================================
  Files          73       73              
  Lines        6154     6167      +13     
  Branches     1101     1103       +2     
==========================================
+ Hits         5141     5143       +2     
- Misses        720      731      +11     
  Partials      293      293              
Flag Coverage Δ
unittests 83.18% <22.22%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pdm/models/candidates.py 87.86% <0.00%> (-0.37%) ⬇️
pdm/utils.py 79.22% <16.66%> (-2.54%) ⬇️
pdm/project/core.py 89.53% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ed9e07...8d14c40. Read the comment docs.

pdm/utils.py Outdated Show resolved Hide resolved
pdm/models/candidates.py Outdated Show resolved Hide resolved
@agoose77
Copy link
Contributor Author

I don't have time to work on this right now, but I'm thinking about the following changes:

  • Add is_venv to PythonInfo or Environment, to replace (remove) pdm.utils.is_venv_python
  • Replace call to get_env_prefix in
    virtual_env_prefix = get_env_prefix()
    if virtual_env_prefix:
    src_dir = virtual_env_prefix / "src"
    with a check of python/environment.is_venv

This would change the behaviour — right now, as you point out, we don't check if project.python.interpreter is a virtual environment.

@frostming
Copy link
Collaborator

frostming commented Nov 22, 2021

I don't have time to work on this right now, but I'm thinking about the following changes:

  • Add is_venv to PythonInfo or Environment, to replace (remove) pdm.utils.is_venv_python
  • Replace call to get_env_prefix in
    virtual_env_prefix = get_env_prefix()
    if virtual_env_prefix:
    src_dir = virtual_env_prefix / "src"

    with a check of python/environment.is_venv

This would change the behaviour — right now, as you point out, we don't check if project.python.interpreter is a virtual environment.

That is a good change, while I prefer to bind it to Environment. Go ahead with it!

@agoose77
Copy link
Contributor Author

agoose77 commented Nov 22, 2021

I think we might want to refactor the virtual-environment support here, but I think we should do so in a different PR.

I experimented with adding this information to the PythonInfo class, because I feel that this knowledge belongs with the interpreter. However, it's a bigger change than just adding Conda support, so I'm holding off on it.

For my future benefit:
The Environment class currently distinguishes between using PEP 582 scheme or the sysconfig scheme for installing packages. This distinction is made as follows:

  • If the user is inside a venv and passes use_venv=True, then we disable PEP582
  • If the user passes -g, then we disable PEP 582

Another name for these classes might be PEP582Environment and GlobalEnvironment

@frostming frostming merged commit 367c3c2 into pdm-project:main Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants