Skip to content

Call to flake8 when using (mini)conda breaks the --format option #9481

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

Closed
beeb opened this issue Jan 9, 2020 · 7 comments
Closed

Call to flake8 when using (mini)conda breaks the --format option #9481

beeb opened this issue Jan 9, 2020 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@beeb
Copy link

beeb commented Jan 9, 2020

Environment data

  • VS Code version: 1.41.1
  • Extension version (available under the Extensions sidebar): 2020.1.57204
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.6 Anaconda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): miniconda (conda 4.8.1)
  • Relevant/affected Python packages and their versions: flake8 3.7.9
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): jedi

Expected behaviour

The flake8 output is formatted correctly using the supplied --format argument

Actual behaviour

The flake8 output is garbage (part of the format string and the path to the file to link). This happens any time I run flake8 with conda.exe run -n smsl even outside of VSCode. The --format argument gets messed up when calling it via conda run.

This is definitely a bug regarding conda and/or flake8 too. But....
The syntax of this call has changed apparently, IIRC it used to be calling the python executable for a given environment directly in previous versions of the extension.

Since the conda run --help doc says it's experimental, maybe it should not be used for this extension.

Steps to reproduce:

  1. create a new conda environment with python 3.7.6
  2. pip install flake8
  3. choose this env as the python executable in VSCode
  4. enable flake8 linting
  5. lint a file that contains an error
  6. observe the result in the output tab

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> ~\AppData\Local\Continuum\miniconda3\Scripts\conda.exe run -n smsl python -m flake8 --max-line-length=120 --exclude=__init__.py --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s c:\Users\...\Documents\folder\file.py
...
##########Linting Output - flake8##########
(col)d,(code)s:\Users\...\Documents\folder\file.py

As you can see, flake8 is invoked with conda run instead of just calling the python executable of the environment directly. For some reason this messes up the parsing of the --format by flake8.

After some investigating, I noticed this is the temporary .bat script that is generated by conda when running the command is:

@ECHO OFF
@SET PYTHONIOENCODING=utf-8
@SET PYTHONUTF8=1
@FOR /F "tokens=2 delims=:." %%A in ('chcp') do for %%B in (%%A) do set "_CONDA_OLD_CHCP=%%B"
@chcp 65001 > NUL
@CALL "C:\Users\...\AppData\Local\Continuum\miniconda3\condabin\conda.bat" activate "C:\Users\...\AppData\Local\Continuum\miniconda3\envs\smsl"
@IF %ERRORLEVEL% NEQ 0 EXIT /b %ERRORLEVEL%
@python -m flake8 --max-line-length=120 --exclude=__init__.py --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s C:\Users\...\Documents\folder\file.py
@IF %ERRORLEVEL% NEQ 0 EXIT /b %ERRORLEVEL%
@chcp %_CONDA_OLD_CHCP%>NUL

Since this is a batch script, the % character needs to be escaped (as %%).. Can the VSCode Python extension fix that by escaping this character while we wait that conda fixes it?

@beeb beeb added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 9, 2020
@beeb
Copy link
Author

beeb commented Jan 9, 2020

Opened an issue for conda at conda/conda#9579

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 9, 2020
@kimadeline
Copy link

kimadeline commented Jan 9, 2020

Hi @beeb 👋 thank you for reaching out and your investigation work 🔎

Issue #9490 should address that since it removes conda run usage for now.

In the meantime a workaround would be to downgrade the extension.

@beeb
Copy link
Author

beeb commented Jan 10, 2020

Okay sounds good, thanks for the feedback!

@kimadeline
Copy link

Hi @beeb ,

The conda run fix is now merged in master, so if you're interested in trying it out before the Monday release you are welcome to download our Insiders build (Settings -> "python.insidersChannel": "daily").

Thank you for your patience!

@beeb
Copy link
Author

beeb commented Jan 14, 2020

Latest release fixed this issue (not sure if I'm allowed to close it)

@kimadeline
Copy link

Thank you for the feedback 👍 Don't worry about it, we'll keep the issue open for now.

@kimadeline
Copy link

After checking with the team, closing in favour of upstream issues conda/conda#9579 and conda/conda#9598.

@ghost ghost removed the needs upstream fix label Jan 14, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants