PyCQA / PyCQA/pycodestyle

Advanced usage question: How to call the pycodestyle with custom rule in the external file

Open
#917 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

I try to write a wrapper to call the pycodestyle with the rule in the wrapper file.

My rule/wrapper looks like.


import pycodestyle


def _main(**kwargs)


    @pycodestyle.register_check
    def image_lines(logical_line):
        r"""Find the line starting from the
        - FROM
        - image:
        directives.

        I801: def a():\n    pass\na()
        I802: def b():\n    pass\na()
        """ #noqa

        if logical_line.startswith('FROM'):
            yield 0, "I801 found the FROM directive"
        elif logical_line.startswith('image:'):
            yield 0, "I802 found the image directive"


    style = pycodestyle.StyleGuide(filename=['Dockerfile', 'docker-compose.yml'], select=['I801', 'I802'])

if __name__ == '__main__':
    _main()

Can you help me? Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the wrapper's _main function, @pycodestyle.register_check, and StyleGuide configuration. Reproduce the call against Dockerfile and docker-compose.yml, checking whether the selected I801 and I802 checks run. Done means the supported way to invoke a custom external rule is clearly documented or confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.