-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use python -c to invoke pylint and flake8 #1113
Conversation
LGTM :) |
@cpitclaudel I must admit that I'm not sure whether I'd like to merge this pull request. Can we discuss the problems that this is supposed to solve first, over at #1055? |
@cpitclaudel Independently of the discussion in #1055 we need custom |
Ah, very good point. That is one downside of this PR. |
@cpitclaudel I'd go for Generally I think we should slowly move to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misses an :enabled
that checks whether the corresponding modules are installed.
LGTM, but I "requested changes" for the missing |
@cpitclaudel Did you get a chance to work on this pull request meanwhile? |
Barely. I'll try to get some time before the week-end |
@cpitclaudel No hurry, was just curious. |
@cpitclaudel Any update on this one? |
4f4b375
to
9185eb3
Compare
I looked into this again, but there's a problem I didn't consider at the time: backwards compatibility. If people have custom paths for flake8 or pylint, this change will break them. There's multiple ways to proceed.
WDYT? |
Is it possible to make |
Not easily (at least I think, but I'd like to be proven wrong); Flycheck has a pretty deeply-embedded notion of checker executables, where each checker has it's own binary + arguments passed to it. |
Not especially pushing for this PR, but one use-case I have where calling pylint through
This is the error I get in emacs:
I fixed that in another way, by adding: (with-eval-after-load 'flycheck
(setq flycheck-command-wrapper-function
(lambda (command)
(if (null (string-match "pylint" (car command)))
command
(let* ((new-prefix (replace-regexp-in-string "pylint$" "python" (car command)))
(new-rest (append '("-m" "pylint") (cdr command)))
(new-command (append (list new-prefix) new-rest)))
new-command))))) I also needed to set the default-directory to be the project root instead of the file's directory because other ((nil . ((eval . (setq default-directory (locate-dominating-file default-directory ".dir-locals.el"))))))
EDIT: corrected the |
Thank, that's an interesting data point. I think your solution is similar to mine. |
I'm not sure it's worth hanging onto backward compatibility on this one. In this case, there is an even simpler trick: (setf (flycheck-checker-get 'python-flake8 'command)
(cddr (flycheck-checker-get 'python-flake8 'command)) would drop the |
flycheck.el
Outdated
@@ -8022,6 +8040,10 @@ Requires Flake8 3.0 or newer. See URL | |||
(id (one-or-more (any alpha)) (one-or-more digit)) " " | |||
(message (one-or-more not-newline)) | |||
line-end)) | |||
:enabled (lambda () (and flycheck-flake8-python-executable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new variable that's not in this branch? Or did you mean flycheck-python-flake8-executable
? The latter is already checked by Flycheck.
9185eb3
to
3971a82
Compare
I updated the PR, but there's one more issue. From the docs of
The addition of the current directory means that large projects with names that conflict with the standard library, like Sphinx, can't be checked:
(this happens because Sphinx contains a "locale" module. |
3971a82
to
7c8ce34
Compare
Fixed by moving to |
7c8ce34
to
71b2c7a
Compare
2181b02
to
8154437
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm not convinced of the need for backward-compatibility on this one, but I don't write enough Python, so I'll trust your judgment.
This can go into CHANGES.rst
Improvements
section.
@@ -8764,7 +8803,8 @@ Update the error level of ERR according to | |||
|
|||
Requires Flake8 3.0 or newer. See URL | |||
`https://flake8.readthedocs.io/'." | |||
:command ("flake8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment saying why we don't call flake8
directly and linking to this PR (or #1055).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
flycheck.el
Outdated
"Determines whether CHECKER needs a `-m module-name' argument. | ||
Previous versions of Flycheck called pylint and flake8 directly; | ||
this check ensures that we don't break existing code." | ||
(not (string-match-p (concat "\\(pylint\\|flake8\\)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use rx
to make the regexp more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Sounds like the perfect time to advertise https://github.com/cpitclaudel/easy-escape, too :)
flycheck.el
Outdated
(string-trim (buffer-string)))))) | ||
|
||
(defun flycheck-python-needs-module-p (checker) | ||
"Determines whether CHECKER needs a `-m module-name' argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not really -m module-name
, since we end up using -c
instead. But the intent is the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I changed the docstring.
Part of GH-1055. Ideally we'd use 'python -m ...' instead of 'python -c ...', but Python adds the current directory to sys.path in -c and -m mode, which confuses pylint (for example, 'python -m pylint' breaks when Flychecking Sphinx, whose sources include a 'locale' directory that conflicts with Python's standard 'locale' module).
8154437
to
6e45989
Compare
Yup, I already added it :) |
Question: do we actually care about argument order in docstrings? I'm temper to turn checkdoc-arguments-in-order-flag off. |
I don't mind about the order no. |
61fbf04
to
1100f1d
Compare
OK, all green. |
Use python -m to invoke pylint and flake8
Part of GH-1055.