acoustic-librarian-3937
02/15/2022, 5:35 PM[GLOBAL]
pants_version = "2.9.0"
backend_packages = [
"pants.backend.python.lint.black",
"pants.backend.python.lint.flake8"
]
How do I correctly set up my path such that VS code is able to find the executable for black
and flake8
to allow it to invoke those linters/formatters? I am creating a virtual environment the pre-export way but I don't see black or flake8 binaries in the bin directory for that venvhundreds-father-404
02/15/2022, 5:42 PMacoustic-librarian-3937
02/15/2022, 6:03 PM./pants lint ::
would solve this for me. (I think that is what the GitHub issue is advocating for, correct me if I am misunderstanding it). I am coming from a JS background. In that world it is fairly common for folks to include an executable tool such as a formatter or linter as a dev dependency to allow the build system to use it.
Ultimately it would be cool if I could click "format document" or "run linting" in VS Code, and know that it would run in the same way that ./pants fmt
or ./pants lint
would. For now, I am just running pip install $tool
in that virtual env and hoping I get a compatible version with the same config.hundreds-father-404
02/15/2022, 6:09 PMpython_requirement
for both your own normal code and the tool lockfile, like [black].version
and [black].extra_requirements
. This would make it more feasible to include Black in the result of ./pants export ::
2. Export dedicated virtualenvs per tool, which would let you point your IDE to use the Black binary from that tool's venv, for example. Pretty feasible for us to implement
3. Mix in the tool venvs with your user requirements venv. The benefit is you have only one venv w/ everything in it, but the downside is that it's likely to cause issues trying to mix them. Not very feasible fwict
4. First-class VSCode support, which we're working on via BSP https://github.com/pantsbuild/pants/issues/13260. I wonder if that will allow us to wire into VSCode's fmt support automatically, not sure
cc @nutritious-hair-72580hundreds-father-404
02/15/2022, 6:09 PMnutritious-hair-72580
02/15/2022, 6:19 PM./pants export ::
(or at least optionally). Looks like both VSCode and PyCharm support custom paths for black, flake8, etc.
I’d put in the docs the VSCode settings.json
example config - e.g.
{
"python.linting.flake8Path": "./dist/tools(?)/..."
}
I’m not sure if/how the equivalent is done programmatically in PyCharm, but it’d be pretty easy to infer from VSCode settings as a start.happy-kitchen-89482
02/15/2022, 6:20 PM./pants lint
itself rather than trying to replicate what ./pants lint
does.happy-kitchen-89482
02/15/2022, 6:20 PMhappy-kitchen-89482
02/15/2022, 6:21 PMnutritious-hair-72580
02/15/2022, 6:23 PM./pants lint
will give you hint/problems in the GUI when things are wrong. The VSCode extension (I’m not sure if it’s in the one python extension or a separate flake8 one) handles that.nutritious-hair-72580
02/15/2022, 6:25 PMacoustic-librarian-3937
02/15/2022, 6:38 PMI know very little about vscode, but ideally it would run linters by invokingitself rather than trying to replicate what./pants lint
does../pants lint
Is that not easy to set up?AFAIK it is handled by the python extension https://marketplace.visualstudio.com/items?itemName=ms-python.python which is maintained by Microsoft and touted as the "best" option for getting python development set up in VS Code. That extension has a list of linters it knows how to work with https://code.visualstudio.com/docs/python/linting#_specific-linters which enables the hints in the UI. As @nutritious-hair-72580 mentioned those linters can be configured to use a custom path
A custom path is generally unnecessary as the Python extension resolves the path to the linter based on the Python interpreter being used (see Environments). To use a different version of a linter, specify its path in the appropriate custom path setting. For example, if your selected interpreter is a virtual environment but you want to use a linter that's installed in a global environment, then set the appropriate path setting to point to the global environment's linter.So I think option #2, giving the tool its own virtual environment would be fine for me
acoustic-librarian-3937
02/15/2022, 6:45 PMhundreds-father-404
02/15/2022, 6:54 PMacoustic-librarian-3937
02/15/2022, 7:02 PMacoustic-librarian-3937
02/15/2022, 7:05 PMhundreds-father-404
02/15/2022, 7:10 PMacoustic-librarian-3937
02/15/2022, 7:36 PM.unwrap()
seems like something I might be able to do without much help! I will clone the project and see what things look likehappy-kitchen-89482
02/15/2022, 9:06 PMacoustic-librarian-3937
02/15/2022, 9:13 PMnutritious-hair-72580
02/16/2022, 9:37 AM