Hi all, I’ve already got a question! How do I get ...
# general
c
Hi all, I’ve already got a question! How do I get my pyproject.toml file section for pylint to use an existing .pylintrc file?
Copy code
[tool.pylint]
rcfile = ?
b
Is that a Pants question or a
pylint
one? 👀 Pants has https://www.pantsbuild.org/docs/reference-pylint#config
c
Probably both, but leaning towards pants… Thanks for the link!
b
h
if you look right below though at
config_discovery
, Pants should be autodetecting pyproject.toml for you! https://www.pantsbuild.org/docs/reference-pylint#config_discovery If not, there may be a bug?
ohhhh, you want to put the config in an
rcfile
and have
pyproject.toml
tell Pylint to use that file? How come not put the config in pyproject.toml?
c
@hundreds-father-404 Yep, I’d like to have the
pyproject.tom
file [tool.pylint] section reference the .pylintrc file. I thought about putting the configuration right in the .toml file, but I inherited it from someone and it’s pretty large.
👍 1
b
pylint's config is insane(ly large) 😮
c
Agreed…. since I’m relatively new to the team (and Python is relatively new to the organization), I figured I’d use the .pylintrc from the other established Python program in use.
👍 2
h
Sounds good, then I think yeah the
--config
option is the way to go 🙂 We generally encourage when adopting Pants trying to separate out PRs to improve the repo from PRs to adopt Pants itself. And we tried to design Pants to be flexible to support that, that you don't have to rewrite or rearchitect your whole repo
c
Well, this is a new project and I’m trying to improve the developer experience for the team. This is why I’m trying it on a new Python project, not an existing one. That way I get to control the README.md and document how I’d like to proceed.
👍 1
This looks like it does the trick in the
pyproject.toml
file:
Copy code
[tool.pylint]
pylint-config = "/config/.pylintrc"
:)
h
ALong with also setting
[pylint].config
in
pants.toml
?
c
I didn’t do that…
h
Oh, hm. I think I see why this works now. So the tricky thing with config files is that you can't just have Pants tell Pylint to load the config via e.g.
--config
. The file needs to also be included in the "execution sandbox" (tmpdir). I thought that this would fail because
/config/.pylintrc
isn't being included. But I guess config discovery is including both
pyproject.toml
and the
.pylintrc
files
🤯 1
But I'm not 100% certain this will work in every case. Are you running
./pants lint ::
? Could you try running
./pants lint path/to/file.py
on a file that is not underneath the
config/
folder?
c
Running this command:
Copy code
./pants lint project/app/main.py
gives me these results:
Copy code
16:10:51.72 [INFO] Completed: Format with isort - isort made no changes.
16:10:51.81 [WARN] Completed: Format with Black - black made changes.
  project/app/main.py
16:10:52.45 [ERROR] Completed: Lint using Pylint - pylint failed (exit code 2).
************* Module project.app.main
project/app/main.py:11:0: E0401: Unable to import 'project.app.auth.router' (import-error)
project/app/main.py:12:0: E0401: Unable to import 'project.app.users.router' (import-error)

------------------------------------------------------------------
Your code has been rated at 4.44/10 (previous run: 4.44/10, +0.00)



✕ black failed.
✓ isort succeeded.
✕ pylint failed.
Which looks like it did the right thing to me. This is with only:
Copy code
[tool.pylint]
pylint-config = "/config/.pylintrc"
in the `pyproject.toml`file.
Is this helpful?
h
one thing you can do to debug is use `--keep-sandboxes=always`: https://www.pantsbuild.org/docs/troubleshooting#debug-tip-inspect-the-sandbox-with---keep-sandboxes Then look inside the sandbox to make sure the config files you expect are there. I'm still a little skeptical that this is working correctly! It would be surprise me if so
c
I ran the command with the keep-sandboxes option, but I don’t understand what you mean by “look inside the sandbox…“?
h
did it log where the sandbox folder is at? I mean like using
ls
inside that folder to make sure the files are there
c
Ah, yes, it did create a
/private….
path.
b
(sometimes it won't if the result of the operation is cached, then just add a comment to the file)
c
Not sure what I should be looking for in there. Sorry, quite the pants noob….
Sorry, I have to run and pick up our dog from daycare. 🙂 I’ll be back on here tomorrow I’m sure! (EST)