Skip to content
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

Improve docs clarity on loading custom checkers #7276

Closed
wants to merge 8 commits into from
Closed

Improve docs clarity on loading custom checkers #7276

wants to merge 8 commits into from

Conversation

daogilvie
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ“œ Docs

Description

Short

This PR just updates the documentation page on writing custom checkers. It adds
information about some restrictions between how init-hook changes the loading
path and when you can use that to import your custom module.

Long (in the commit message)

Whilst the docs on testing custom checkers do touch on the fact the
module has to be in your load path, there are some restrictions that
were not made clear before.
Specifically, the init-hook configuration item (which is often used
explicitly to change the sys.path) is not automatically sufficient. If
the init hook is in a file, but the load-plugins argument is passed in
the CLI, then the plugins are loaded before the init-hook has run, and
so will not be imported. In this case, the failure can also be silent,
so the outcome is a lint that will simply not contain any information
from the checker, as opposed to a run that will error.
This corner case may merit fixing in a separate PR, that is to be
confirmed.

Closes #7264

Whilst the docs on testing custom checkers do touch on the fact the
module has to be in your load path, there are some restrictions that
were not made clear before.
Specifically, the init-hook configuration item (which is often used
explicitly to change the sys.path) is not automatically sufficient. If
the init hook is in a file, but the load-plugins argument is passed in
the CLI, then the plugins are loaded before the init-hook has run, and
so will not be imported. In this case, the failure can also be silent,
so the outcome is a lint that will simply not contain any information
from the checker, as opposed to a run that will error.
This corner case may merit fixing in a separate PR, that is to be
confirmed.

Closes #7264
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you start this note with something like:
The preferred way of making plugins available is by installing them as a package, etc.?

@@ -223,6 +223,18 @@ Now we can debug our checker!
environment variable or by adding the ``my_plugin.py``
file to the ``pylint/checkers`` directory if running from source.

If your pylint config has an init-hook that modifies
``sys.path`` to include the module's parent directory, this
will also work, but only if:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
will also work, but only if:
will also work, but only if either:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this myself, mortified, good spot thanks @DanielNoord!

daogilvie added 2 commits August 8, 2022 15:43
As per suggestion from @DanielNoord, this makes it clearer that
installing the custom module is the recommended way.
@daogilvie
Copy link
Contributor Author

@DanielNoord thank your for such a quick review! I've updated as per your suggestions, what do you think?

@coveralls
Copy link

coveralls commented Aug 8, 2022

Pull Request Test Coverage Report for Build 3008066091

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 215 unchanged lines in 18 files lost coverage.
  • Overall coverage increased (+0.08%) to 95.333%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/modified_iterating_checker.py 1 97.7%
pylint/testutils/_primer/primer_command.py 1 95.65%
pylint/epylint.py 2 83.33%
pylint/extensions/docparams.py 2 98.53%
pylint/testutils/_primer/primer_compare_command.py 2 96.43%
pylint/utils/file_state.py 2 95.41%
pylint/lint/expand_modules.py 3 94.74%
pylint/testutils/_primer/primer_prepare_command.py 5 21.43%
pylint/checkers/classes/special_methods_checker.py 8 94.97%
pylint/config/find_default_config_files.py 8 89.16%
Totals Coverage Status
Change from base Build 2819506531: 0.08%
Covered Lines: 17017
Relevant Lines: 17850

πŸ’› - Coveralls

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait on the discussion in the issue before merging this. L229-L240 might need to change.

Rest looks good to me! Thanks @daogilvie πŸ˜„

doc/whatsnew/fragments/7264.other Outdated Show resolved Hide resolved
doc/development_guide/how_tos/custom_checkers.rst Outdated Show resolved Hide resolved
doc/development_guide/how_tos/custom_checkers.rst Outdated Show resolved Hide resolved
doc/development_guide/how_tos/custom_checkers.rst Outdated Show resolved Hide resolved
@daogilvie
Copy link
Contributor Author

No problem! Thank you for very patiently reviewing my first attempt at a documentation PR πŸ˜‚ I have some bad habits in terms of brevity and language to unlearn.

I'll make the changes above and then, as you say, pause this until after any potential changes in behaviour.

daogilvie and others added 5 commits August 8, 2022 18:00
Thanks to @DanielNoord

Co-authored-by: DaniΓ«l van Noord <[email protected]>
This is not the way.

Co-authored-by: DaniΓ«l van Noord <[email protected]>
This is a much clearer way of explaining what is meant by this recommendation.

Co-authored-by: DaniΓ«l van Noord <[email protected]>
@daogilvie
Copy link
Contributor Author

Side note: I have made the commits individually in the UI for convenience, as your suggestions made sense to me straight away. Is that something you as maintainers prefer or dislike? Would it be better to have one commit for all recommendations? I didn't seem to have the "add to batch" button available.

@DanielNoord
Copy link
Collaborator

Side note: I have made the commits individually in the UI for convenience, as your suggestions made sense to me straight away. Is that something you as maintainers prefer or dislike?

Usually I/We prefer one commit, but it doesn't matter too much. As long as you don't rebase or force push the Github UI is pretty good at showing what changed and what remained the same after new commits.

Would it be better to have one commit for all recommendations? I didn't seem to have the "add to batch" button available.

I know, very annoying. It only shows up in the files view which you can select at the top of PR. There you can add to batch and then do one single commit.

@Pierre-Sassoulas Pierre-Sassoulas added Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry labels Aug 25, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot !

@Pierre-Sassoulas Pierre-Sassoulas removed the Skip news πŸ”‡ This change does not require a changelog entry label Aug 25, 2022
@DanielNoord DanielNoord added the Blocked 🚧 Blocked by a particular issue label Aug 25, 2022
@daogilvie daogilvie closed this by deleting the head repository Sep 7, 2022
@Pierre-Sassoulas
Copy link
Member

@daogilvie should we close this ? It seems it would be a valuable addition to the doc ?

@DanielNoord why do we have a blocked label ?

@daogilvie
Copy link
Contributor Author

Oh goodness I completely forgot about this. It was blocked pending resolution of the other PR.


* the ``init-hook`` and the ``load-plugins`` list are both
defined in a pylintrc file, or...
* the ``init-hook`` is passed as a command-line argument and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's explicitly state what doesn't work

@@ -0,0 +1,3 @@
Dev documentation is now clearer about custom checker loading.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs a fragment. I'll add the skip news label.

@DanielNoord DanielNoord removed the Blocked 🚧 Blocked by a particular issue label Sep 18, 2022
@DanielNoord DanielNoord added the Skip news πŸ”‡ This change does not require a changelog entry label Sep 18, 2022
@daogilvie
Copy link
Contributor Author

I have just pushed a commit with the review fixes in, but I think my deletion of the previous fork has left this PR in a bad state. @DanielNoord @Pierre-Sassoulas I think I may have to close this PR and re-open a new one from the replacement fork for this to work. Do you mind?

@Pierre-Sassoulas
Copy link
Member

Not at all, don't hesitate to ping me for a review :)

@daogilvie
Copy link
Contributor Author

Replaced with #7502

@daogilvie
Copy link
Contributor Author

Not at all, don't hesitate to ping me for a review :)

I don't seem to be able to do this directly (the reviewers section of the PR gives me no options), sorry.

@Pierre-Sassoulas
Copy link
Member

You can use @Pierre-Sassoulas :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation πŸ“— Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot get pylint to register custom checker, is there a missing step in the docs?
4 participants