Skip to content

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

Closed

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 (View→Output, 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?

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Jan 9, 2020
  2. beeb commented on Jan 9, 2020

    @beeb
    Author

    Opened an issue for conda at conda/conda#9579

  3. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Jan 9, 2020
  4. kimadeline commented on Jan 9, 2020

    @kimadeline

    Hi Valentin B. (@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.

  5. beeb commented on Jan 10, 2020

    @beeb
    Author

    Okay sounds good, thanks for the feedback!

  6. kimadeline commented on Jan 10, 2020

    @kimadeline

    Hi Valentin B. (@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!

  7. beeb commented on Jan 14, 2020

    @beeb
    Author

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

  8. kimadeline commented on Jan 14, 2020

    @kimadeline

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

  9. kimadeline commented on Jan 14, 2020

    @kimadeline

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

  10. locked as resolved and limited conversation to collaborators on Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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