question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 #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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

2reactions
kimadelinecommented, Jan 10, 2020

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!

1reaction
beebcommented, Jan 14, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Flake8 — flake8 6.0.0 documentation
Each command-line option that you want to specify in your config file can be named in either of two ways: Using underscores (...
Read more >
conda-build Documentation
Conda -build contains commands and tools to use conda to build your own packages. It also provides helpful tools to.
Read more >
How to Use Conda With Github Actions - Ben Heil
This step runs the flake8 linter to check the python code in the directory. The first line installs flake8 into the base environment....
Read more >
conda Documentation - Read the Docs for Business
Package, dependency and environment management for any language—Python, R, Ruby, Lua, Scala, Java, JavaScript,. C/ C++, FORTRAN. Conda is an ...
Read more >
The 10 tools I wish I knew when I started working with Python
10 Tools I Wish I Knew When I Started Working with Python. Learn how venvs, flake8, black, isort, pytest, commitizen, semantic-release, pre-commit hooks,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found