Skip to content

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

Closed
@beeb

Description

@beeb

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?

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions