You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
If I have Python-related files in my workspace, automatically activate the extension #4765
Goal - Lets not wait for the user to open a python file to activate the extension
If the user has some of the following files we could probably activate the extension without having to wait for the user to open a python file:
pip env files
poetry files
setup.py
setup.cfg?
tox.ini
pyproject.toml
pytest.ini
requirements.txt
test_requirements.txt
.pylintrc
.flake8
__init__.py
manage.py
src/__init__.py
tests/__init__.py
meta.yml
environment.yml
anaconda-project.yml
.pep8
.pycodestyle
Reacted by Carlos, Zane Dufour, krzysztof urbaniak, Sebastien Tremblay-Johnston, MBetters, Jiacheng, andres-pcg, Yoni Chechik, Tim Chard, iutlu and 10 more
Luciana Abud (@luabud) we have an external PR for this issue.
FYI, this was meant to be an experiment, hence the label.
We might also want to list down each file that we want to support/look for.
Sorry, I missed that question.
I can see only one way of doing this.
When extension loads, we modify package.json file, then next time they load extension package.json file will contain the required changes and things will work as expected.
I.e. extension will need to modify package.json during runtime, instead of shipping it.
We might need to change how this experiment works, else we'll get telemetry for users who open VSC once and we'll (via telemetry) get notified they are in the experiment, when in fact they aren't (not until they re-load VS Code).
I can send another PR (and so could you! 😉 ) but it's up to the team that maintains the project (Brett Cannon (@brettcannon) , Luciana Abud (@luabud) , etc.) whether they approve of it and ultimately whether it gets merged.
Laurent Sorber (@lsorber)environment.yml is a little tricky because it's used by conda in all languages they support, e.g. R. So we would over-trigger in that instance and we have already received a lot of complaints in the past about launching when we weren't wanted. And because this is declarative in package.json we can't programmatically say "trigger for environment.yml if it lists a Python version" or something.
Brett Cannon (@brettcannon) thanks for clarifying, that makes sense. Would it be possible to trigger activation based on their being a virtual/conda environment associated with the workspace? That should have pretty high recall and precision I expect.
Laurent Sorber (@lsorber) I like that idea if it's possible. I think all my python projects have python.pythonPath set in the workspace's settings.json file
Laurent Sorber (@lsorber) VS Code only "knows" that there's a Python environment because our extension makes that true. Technically VS Code itself couldn't care less about any of this; all it cares about is knowing when to launch our extension. We then bring in the concept of a Python environment after we start up. So this issue is specifically about when to launch our extension which itself brings in the concept of Python environments.
Brett Cannon (@brettcannon) I see, then how about a minimal startup to check whether there's a Python environment associated with the workspace and if not (and nothing else would trigger the extension) immediately shut down again?
Maybe this could be taken to the vscode repo itself and see if they can add another type of activation event? Is there any sort of (not very intensive) activation event that could work for conda, and could even be useful for other developers?
Brett Cannon (@brettcannon) why would that be expensive? I'm referring to simply checking whether the user associated a Python environment with the workspace in their workspace settings.json.
Making the presence of a workspace-specific setting a new type of trigger sounds like it could be a solution (based on my limited understanding of VS Code).
Reacted by Dhaval Soneji, Richard Höchenberger and Yuri Thomas
why would that be expensive? I'm referring to simply checking whether the user associated a Python environment with the workspace in their workspace settings.json.
We would still have to launch the extension to detect this. Plus not every user who sets up a Python environment wants to load the extension every time (e.g. C/C++ users who have some Python code to gather test data). The existence of settings is not enough information to infer that activation of the extension is desirable in all cases. Hence why we have only trigger automatic loading on project-level files instead of any Python file existing.
Now if you're proposing a hypothetical check for a setting, then that's different, but not at all under our control as that would have to come from VS Code.
Activity
znd4 commentedon May 15, 2019
I know you included etc., but I'd like to explicitly call out
meta.yml,environment.yml, and maybe evenanaconda-project.yml. :)wis commentedon Jun 17, 2019
also
.pep8and I think.pycodestyle[-]Auto activate extension based on files in the workspace[/-][-]If I have Python-related files in my workspace, automatically activate the extension [/-]DonJayamanne commentedon Mar 30, 2020
Luciana Abud (@luabud) we have an external PR for this issue.
FYI, this was meant to be an experiment, hence the label.
We might also want to list down each file that we want to support/look for.
karthiknadig commentedon Mar 31, 2020
Don Jayamanne (@DonJayamanne) this is a change to
package.json. Is there a way to add this to experiment?DonJayamanne commentedon Apr 27, 2020
Sorry, I missed that question.
I can see only one way of doing this.
When extension loads, we modify package.json file, then next time they load extension package.json file will contain the required changes and things will work as expected.
I.e. extension will need to modify package.json during runtime, instead of shipping it.
We might need to change how this experiment works, else we'll get telemetry for users who open VSC once and we'll (via telemetry) get notified they are in the experiment, when in fact they aren't (not until they re-load VS Code).
33 remaining items
lsorber commentedon Apr 8, 2021
Dhaval Soneji (@Soneji) Could you also add a trigger for
environment.ymlfor conda users? 🙏Soneji commentedon Apr 8, 2021
hey Laurent Sorber (@lsorber)
I can send another PR (and so could you! 😉 ) but it's up to the team that maintains the project (Brett Cannon (@brettcannon) , Luciana Abud (@luabud) , etc.) whether they approve of it and ultimately whether it gets merged.
Soneji commentedon Apr 8, 2021
Also, if we're increasing the list of files, we should definitely add the poetry files too (from the first comment), like
pyproject.tomlbrettcannon commentedon Apr 8, 2021
Laurent Sorber (@lsorber)
environment.ymlis a little tricky because it's used by conda in all languages they support, e.g. R. So we would over-trigger in that instance and we have already received a lot of complaints in the past about launching when we weren't wanted. And because this is declarative inpackage.jsonwe can't programmatically say "trigger forenvironment.ymlif it lists a Python version" or something.Dhaval Soneji (@Soneji) we have actually been triggering for
pyproject.tomlfor at least 7 months now, so Poetry users are all good 😄lsorber commentedon Apr 8, 2021
Brett Cannon (@brettcannon) thanks for clarifying, that makes sense. Would it be possible to trigger activation based on their being a virtual/conda environment associated with the workspace? That should have pretty high recall and precision I expect.
brettcannon commentedon Apr 9, 2021
Laurent Sorber (@lsorber) only if there's a way to statically list a file to trigger against. All the details of what we can trigger on can be found at https://code.visualstudio.com/api/references/activation-events. We purposefully don't blindly trigger due to how big/heavy the extension is.
lsorber commentedon Apr 9, 2021
Right, but VS Code knows whether there's a Python environment associated with the workspace, so that seems like it would be a perfect trigger, or not?
benlindsay commentedon Apr 9, 2021
Laurent Sorber (@lsorber) I like that idea if it's possible. I think all my python projects have
python.pythonPathset in the workspace's settings.json filebrettcannon commentedon Apr 9, 2021
Laurent Sorber (@lsorber) VS Code only "knows" that there's a Python environment because our extension makes that true. Technically VS Code itself couldn't care less about any of this; all it cares about is knowing when to launch our extension. We then bring in the concept of a Python environment after we start up. So this issue is specifically about when to launch our extension which itself brings in the concept of Python environments.
lsorber commentedon Apr 9, 2021
Brett Cannon (@brettcannon) I see, then how about a minimal startup to check whether there's a Python environment associated with the workspace and if not (and nothing else would trigger the extension) immediately shut down again?
brettcannon commentedon Apr 12, 2021
Laurent Sorber (@lsorber) that is still a very expensive thing to do (and especially for conda).
Soneji commentedon Apr 12, 2021
Maybe this could be taken to the vscode repo itself and see if they can add another type of activation event? Is there any sort of (not very intensive) activation event that could work for conda, and could even be useful for other developers?
lsorber commentedon Apr 12, 2021
Brett Cannon (@brettcannon) why would that be expensive? I'm referring to simply checking whether the user associated a Python environment with the workspace in their workspace
settings.json.Making the presence of a workspace-specific setting a new type of trigger sounds like it could be a solution (based on my limited understanding of VS Code).
brettcannon commentedon Apr 13, 2021
We would still have to launch the extension to detect this. Plus not every user who sets up a Python environment wants to load the extension every time (e.g. C/C++ users who have some Python code to gather test data). The existence of settings is not enough information to infer that activation of the extension is desirable in all cases. Hence why we have only trigger automatic loading on project-level files instead of any Python file existing.
Now if you're proposing a hypothetical check for a setting, then that's different, but not at all under our control as that would have to come from VS Code.
Otherwise you can open a feature request at https://github.com/microsoft/vscode-python/discussions/categories/ideas and see if enough people can convince us to ignore non-Python conda users and thus trigger on
environment.yml(or you find some other file we can use to trigger on).