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

Support for VSCode extension #141

Open
vemel opened this issue Nov 18, 2021 · 6 comments
Open

Support for VSCode extension #141

vemel opened this issue Nov 18, 2021 · 6 comments
Labels
question Further information is requested

Comments

@vemel
Copy link
Contributor

vemel commented Nov 18, 2021

Hello!

I have recently published a VSCode extension for automated install of boto3-stubs. Currently I support pip, pipenv and poetry installers, but I have a plan to add conda as well.

As far as I understand, not all boto3-stubs service packages are built for conda, so it looks like I should filter out only packages that are supported.

Could you please guide me how to make sure:

  1. that conda is used in current project. Should I just search for conda in pip freeze?
  2. that conda-forge source is added to conda
  3. does conda install 'boto3-stubs[ec2,s3]' command work, or I should pass packages separately?

Regards, Vlad.

@vemel vemel added the question Further information is requested label Nov 18, 2021
@vemel vemel changed the title Support VSCode extension Support for VSCode extension Nov 18, 2021
@maresb
Copy link
Contributor

maresb commented Nov 18, 2021

Hi! I'm very glad you're interested in supporting conda!

Currently the only stubs on conda-forge are those from boto3-stubs[essential]. (I think we can rethink this now with your build-on-change feature.) They are installed via the master package boto3-stubs-essential. The individual package names are:

  • mypy_boto3_cloudformation
  • mypy_boto3_dynamodb
  • mypy_boto3_ec2
  • mypy_boto3_lambda
  • mypy_boto3_rds
  • mypy-boto3-s3 (Note the exceptional - characters here!)
  • mypy_boto3_sqs

To check whether conda is used in a project, I can think of a few ways...

In VS Code's Python extension, the interpreter will be marked with "conda" as in the following screenshot showing my py2test environment:
image

I think that somehow accessing this would be the best way.

When a Conda environment is selected and a terminal window is open, two commands are pasted into the shell:

source /[path to conda root]/bin/activate
conda activate [name of the environment]

The bin/activate script redefines conda as a shell function (which overrides any conda executable in the path), and the resulting conda activate environmentname shell function invocation does some tricks like modifying $PATH and the shell prompt. (The activate step is necessary because the conda executable would run in a subprocess which can't modify the shell's environment.)

Inside of an activated Conda environment, the correct shell command to install mypy_boto3_cloudformation and mypy_boto3_dynamodb is:

mamba install --channel=conda-forge mypy_boto3_cloudformation mypy_boto3_dynamodb

if mamba can be found in the path inside the activated environment. Mamba is a popular modern drop-in replacement for Conda. It should be preferred, because in many situations conda takes hours to run. In case mamba doesn't exist, then you should fall back to conda.

Does this answer your questions? Thanks so much for your work on this! 😄

@vemel
Copy link
Contributor Author

vemel commented Nov 18, 2021

So, I believe logic should be following:

  • Get interpreter from Python extension. It should be a conda env
  • if mamba is PATH and env is conda, then I add it to installers list
  • if conda is PATH and env is conda, then I add it to installers list
  • In pre-installation activate it with conda activate
  • Install with mamba/conda install --channel=conda-forge <packages>
  • Show warning about selected packages that do not exist in conda-forge. I think I will hardcode package names for now

Thank you a lot for the explanation. Any special steps to do to remove a package?

@maresb
Copy link
Contributor

maresb commented Nov 19, 2021

Almost. Before checking if mamba/conda is in PATH the environment should be activated. So the first four steps should be

  • Get interpreter from Python extension. If it is a conda env...
  • activate it with source .../bin/activate and conda activate envname
  • if mamba is in PATH, then I add it to installers list
  • if conda is PATH, then I add it to installers list

Removing is mamba/conda remove <packages>

@vemel
Copy link
Contributor Author

vemel commented Nov 19, 2021

So, python-vscode does the following:

  • gets interpreter path selected by user
  • lists all conda envs and picks the one where python path matches selected
  • if not found, uses base
  • there is a different command to activate venv on windows

Checking that env is conda is quite easy: we are checking that parent dir for python interpreter path contains conda-meta.
I also noticed that conda envs not always have pip, or probably never have it, so I added a nicer error when pip is not available

I implemented everything except env lookup.

@maresb
Copy link
Contributor

maresb commented Nov 19, 2021

Nice! Are you able to activate the environment and check for conda/mamba?

@vemel
Copy link
Contributor Author

vemel commented Nov 22, 2021

Yes, I am. However, picking the right env is tricky. I am debugging it now, and I hope I release it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants