{"id":13468630,"url":"https://github.com/klen/pylama","last_synced_at":"2025-05-14T07:08:10.272Z","repository":{"id":4316908,"uuid":"5450742","full_name":"klen/pylama","owner":"klen","description":"Code audit tool for python.","archived":false,"fork":false,"pushed_at":"2024-06-21T06:45:05.000Z","size":4322,"stargazers_count":1051,"open_issues_count":64,"forks_count":100,"subscribers_count":18,"default_branch":"develop","last_synced_at":"2025-05-06T02:02:55.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Cloudoki/backbone-notifications","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klen.png","metadata":{"files":{"readme":"README.rst","changelog":"Changelog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-08-17T10:10:10.000Z","updated_at":"2025-04-30T18:49:30.000Z","dependencies_parsed_at":"2024-10-29T11:20:34.067Z","dependency_job_id":null,"html_url":"https://github.com/klen/pylama","commit_stats":{"total_commits":557,"total_committers":49,"mean_commits":11.36734693877551,"dds":0.2405745062836625,"last_synced_commit":"53ad214de0aa9534e59bcd5f97d9d723d16cfdb8"},"previous_names":[],"tags_count":141,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpylama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpylama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpylama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klen%2Fpylama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klen","download_url":"https://codeload.github.com/klen/pylama/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253561432,"owners_count":21927787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:15.353Z","updated_at":"2025-05-14T07:08:10.249Z","avatar_url":"https://github.com/klen.png","language":"Python","funding_links":[],"categories":["Code Analysis","Python","Command-line Tools","代码分析和 Lint 工具","Code Analysis and Linter","\u003ca id=\"df8a5514775570707cce56bb36ca32c8\"\u003e\u003c/a\u003e审计\u0026\u0026安全审计\u0026\u0026代码审计","Code Analysis [🔝](#readme)","Awesome Python"],"sub_categories":["\u003ca id=\"34569a6fdce10845eae5fbb029cd8dfa\"\u003e\u003c/a\u003e代码审计","Code Analysis"],"readme":"|logo| Pylama\n#############\n\n.. _badges:\n\n.. image:: https://github.com/klen/pylama/workflows/tests/badge.svg\n    :target: https://github.com/klen/pylama/actions/workflows/tests.yml\n    :alt: Tests Status\n\n.. image:: https://github.com/klen/pylama/workflows/docs/badge.svg\n    :target: https://klen.github.io/pylama\n    :alt: Documentation Status\n\n.. image:: https://img.shields.io/pypi/v/pylama\n    :target: https://pypi.org/project/pylama/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/pylama\n    :target: https://pypi.org/project/pylama/\n    :alt: Python Versions\n\n.. _description:\n\nCode audit tool for Python. Pylama wraps these tools:\n\n* pycodestyle_ (formerly pep8) © 2012-2013, Florent Xicluna;\n* pydocstyle_ (formerly pep257 by Vladimir Keleshev) © 2014, Amir Rachum;\n* PyFlakes_ © 2005-2013, Kevin Watters;\n* Mccabe_ © Ned Batchelder;\n* Pylint_ © 2013, Logilab;\n* Radon_ © Michele Lacchia\n* eradicate_ © Steven Myint;\n* Mypy_ © Jukka Lehtosalo and contributors;\n* Vulture_ © Jendrik Seipp and contributors;\n\n\n.. _documentation:\n\nDocs are available at https://klen.github.io/pylama/. Pull requests with\ndocumentation enhancements and/or fixes are awesome and most welcome.\n\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements:\n=============\n\n- Python (3.7, 3.8, 3.9, 3.10)\n- If your tests are failing on Win platform you are missing: ``curses`` -\n  http://www.lfd.uci.edu/~gohlke/pythonlibs/ (The curses library supplies a\n  terminal-independent screen-painting and keyboard-handling facility for\n  text-based terminals)\n\nFor python versions \u003c 3.7 install pylama 7.7.1\n\n\n.. _installation:\n\nInstallation:\n=============\n**Pylama** can be installed using pip: ::\n\n    $ pip install pylama\n\nTOML configuration can be enabled optionally: ::\n\n    $ pip install pylama[toml]\n\nYou may optionally install the requirements with the library: ::\n\n    $ pip install pylama[mypy]\n    $ pip install pylama[pylint]\n    $ pip install pylama[eradicate]\n    $ pip install pylama[radon]\n    $ pip install pylama[vulture]\n\nOr install them all: ::\n\n    $ pip install pylama[all]\n\n\n.. _quickstart:\n\nQuickstart\n==========\n\n**Pylama** is easy to use and really fun for checking code quality.  Just run\n`pylama` and get common output from all pylama plugins (pycodestyle_,\nPyFlakes_, etc.)\n\nRecursively check the current directory. ::\n\n    $ pylama\n\nRecursively check a path. ::\n\n    $ pylama \u003cpath_to_directory_or_file\u003e\n\nIgnore errors ::\n\n    $ pylama -i W,E501\n\n.. note:: You can choose a group of errors like `D`, `E1`, etc, or special errors like `C0312`\n\nChoose code checkers ::\n\n    $ pylama -l \"pycodestyle,mccabe\"\n\n\n.. _options:\n\nSet Pylama (checkers) options\n=============================\n\nCommand line options\n--------------------\n\n::\n\n    $ pylama --help\n\n    usage: pylama [-h] [--version] [--verbose] [--options FILE] [--linters LINTERS] [--from-stdin] [--concurrent] [--format {pydocstyle,pycodestyle,pylint,parsable,json}] [--abspath]\n                  [--max-line-length MAX_LINE_LENGTH] [--select SELECT] [--ignore IGNORE] [--skip SKIP] [--sort SORT] [--report REPORT] [--hook] [--max-complexity MAX_COMPLEXITY]\n                  [--pydocstyle-convention {pep257,numpy,google}] [--pylint-confidence {HIGH,INFERENCE,INFERENCE_FAILURE,UNDEFINED}]\n                  [paths ...]\n\n    Code audit tool for python.\n\n    positional arguments:\n      paths                 Paths to files or directories for code check.\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      --version             show program's version number and exit\n      --verbose, -v         Verbose mode.\n      --options FILE, -o FILE\n                            Specify configuration file. Looks for pylama.ini, setup.cfg, tox.ini, or pytest.ini in the current directory (default: None)\n      --linters LINTERS, -l LINTERS\n                            Select linters. (comma-separated). Choices are eradicate,mccabe,mypy,pycodestyle,pydocstyle,pyflakes,pylint,isort.\n      --from-stdin          Interpret the stdin as a python script, whose filename needs to be passed as the path argument.\n      --concurrent, --async\n                            Enable async mode. Useful for checking a lot of files.\n      --format {pydocstyle,pycodestyle,pylint,parsable,json}, -f {pydocstyle,pycodestyle,pylint,parsable,json}\n                            Choose output format.\n      --abspath, -a         Use absolute paths in output.\n      --max-line-length MAX_LINE_LENGTH, -m MAX_LINE_LENGTH\n                            Maximum allowed line length\n      --select SELECT, -s SELECT\n                            Select errors and warnings. (comma-separated list)\n      --ignore IGNORE, -i IGNORE\n                            Ignore errors and warnings. (comma-separated)\n      --skip SKIP           Skip files by masks (comma-separated, Ex. */messages.py)\n      --sort SORT           Sort result by error types. Ex. E,W,D\n      --report REPORT, -r REPORT\n                            Send report to file [REPORT]\n      --hook                Install Git (Mercurial) hook.\n      --max-complexity MAX_COMPLEXITY\n                            Max complexity threshold\n\n.. note:: additional options may be available depending on installed linters\n\n.. _modeline:\n\nFile modelines\n--------------\n\nYou can set options for **Pylama** inside a source file. Use\na pylama *modeline* for this, anywhere in the file.\n\nFormat: ::\n\n    # pylama:{name1}={value1}:{name2}={value2}:...\n\n\nFor example, ignore warnings except W301: ::\n\n     # pylama:ignore=W:select=W301\n\n\nDisable code checking for current file: ::\n\n     # pylama:skip=1\n\nThose options have a higher priority.\n\n.. _skiplines:\n\nSkip lines (noqa)\n-----------------\n\nJust add ``# noqa`` at the end of a line to ignore:\n\n::\n\n    def urgent_fuction():\n        unused_var = 'No errors here' # noqa\n\n\n.. _config:\n\nConfiguration file\n==================\n\n**Pylama** looks for a configuration file in the current directory.\n\nYou can use a “global” configuration, stored in `.pylama.ini` in your home\ndirectory. This will be used as a fallback configuration.\n\nThe program searches for the first matching configuration file in the\ndirectories of command line argument. Pylama looks for the configuration in\nthis order: ::\n\n    ./pylama.ini\n    ./pyproject.toml\n    ./setup.cfg\n    ./tox.ini\n    ./pytest.ini\n    ~/.pylama.ini\n\nThe ``--option`` / ``-o`` argument can be used to specify a configuration file.\n\nINI-style configuration\n-----------------------\n\nPylama searches for sections whose names start with `pylama`.\n\nThe `pylama` section configures global options like `linters` and `skip`.\n\n::\n\n    [pylama]\n    format = pylint\n    skip = */.tox/*,*/.env/*\n    linters = pylint,mccabe\n    ignore = F0401,C0111,E731\n\nSet code-checkers' options\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can set options for a special code checkers with pylama configurations.\n\n::\n\n    [pylama:pyflakes]\n    builtins = _\n\n    [pylama:pycodestyle]\n    max_line_length = 100\n\n    [pylama:pylint]\n    max_line_length = 100\n    disable = R\n\nSee code-checkers' documentation for more info. Note that dashes are\nreplaced by underscores (e.g. Pylint's ``max-line-length`` becomes\n``max_line_length``).\n\n\nSet options for file (group of files)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can set options for special file (group of files)\nwith sections:\n\nThe options have a higher priority than in the `pylama` section.\n\n::\n\n    [pylama:*/pylama/main.py]\n    ignore = C901,R0914,W0212\n    select = R\n\n    [pylama:*/tests.py]\n    ignore = C0110\n\n    [pylama:*/setup.py]\n    skip = 1\n\nTOML configuration\n-----------------------\n\nPylama searches for sections whose names start with `tool.pylama`.\n\nThe `tool.pylama` section configures global options like `linters` and `skip`.\n\n::\n\n    [tool.pylama]\n    format = \"pylint\"\n    skip = \"*/.tox/*,*/.env/*\"\n    linters = \"pylint,mccabe\"\n    ignore = \"F0401,C0111,E731\"\n\nSet code-checkers' options\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can set options for a special code checkers with pylama configurations.\n\n::\n\n    [tool.pylama.linter.pyflakes]\n    builtins = \"_\"\n\n    [tool.pylama.linter.pycodestyle]\n    max_line_length = 100\n\n    [tool.pylama.linter.pylint]\n    max_line_length = 100\n    disable = \"R\"\n\nSee code-checkers' documentation for more info. Note that dashes are\nreplaced by underscores (e.g. Pylint's ``max-line-length`` becomes\n``max_line_length``).\n\n\nSet options for file (group of files)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can set options for special file (group of files)\nwith sections:\n\nThe options have a higher priority than in the `tool.pylama` section.\n\n::\n\n    [[tool.pylama.files]]\n    path = \"*/pylama/main.py\"\n    ignore = \"C901,R0914,W0212\"\n    select = \"R\"\n\n    [[tool.pylama.files]]\n    path = \"pylama:*/tests.py\"\n    ignore = \"C0110\"\n\n    [[tool.pylama.files]]\n    path = \"pylama:*/setup.py\"\n    skip = 1\n\n\nPytest integration\n==================\n\nPylama has Pytest_ support. The package automatically registers itself as a pytest\nplugin during installation. Pylama also supports the `pytest_cache` plugin.\n\nCheck files with pylama ::\n\n    pytest --pylama ...\n\nThe recommended way to set pylama options when using pytest — configuration\nfiles (see below).\n\n\nWriting a linter\n================\n\nYou can write a custom extension for Pylama.\nThe custom linter should be a python module. Its name should be like 'pylama_\u003cname\u003e'.\n\nIn 'setup.py', 'pylama.linter' entry point should be defined. ::\n\n    setup(\n        # ...\n        entry_points={\n            'pylama.linter': ['lintername = pylama_lintername.main:Linter'],\n        }\n        # ...\n    )\n\n'Linter' should be an instance of 'pylama.lint.Linter' class.\nIt must implement two methods:\n\n1. ``allow`` takes a `path` argument and returns true if the linter can check this file for errors.\n2. ``run`` takes a `path` argument and `meta` keyword arguments and returns a list of errors.\n\nExample:\n--------\n\nJust a virtual 'WOW' checker.\n\nsetup.py: ::\n\n    setup(\n        name='pylama_wow',\n        install_requires=[ 'setuptools' ],\n        entry_points={\n            'pylama.linter': ['wow = pylama_wow.main:Linter'],\n        }\n        # ...\n    )\n\npylama_wow.py: ::\n\n    from pylama.lint import Linter as BaseLinter\n\n    class Linter(BaseLinter):\n\n        def allow(self, path):\n            return 'wow' in path\n\n        def run(self, path, **meta):\n            with open(path) as f:\n                if 'wow' in f.read():\n                    return [{\n                        lnum: 0,\n                        col: 0,\n                        text: '\"wow\" has been found.',\n                        type: 'WOW'\n                    }]\n\n\nRun pylama from python code\n---------------------------\n::\n\n    from pylama.main import check_paths, parse_options\n\n    # Use and/or modify 0 or more of the options defined as keys in the variable my_redefined_options below.\n    # To use defaults for any option, remove that key completely.\n    my_redefined_options = {\n        'linters': ['pep257', 'pydocstyle', 'pycodestyle', 'pyflakes' ...],\n        'ignore': ['D203', 'D213', 'D406', 'D407', 'D413' ...],\n        'select': ['R1705' ...],\n        'sort': 'F,E,W,C,D,...',\n        'skip': '*__init__.py,*/test/*.py,...',\n        'async': True,\n        'force': True\n        ...\n    }\n    # relative path of the directory in which pylama should check\n    my_path = '...'\n\n    options = parse_options([my_path], **my_redefined_options)\n    errors = check_paths(my_path, options, rootdir='.')\n\n\n.. _bagtracker:\n\nBug tracker\n-----------\n\nIf you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/pylama/issues\n\n\n.. _contributing:\n\nContributing\n------------\n\nDevelopment of `pylama` happens at GitHub: https://github.com/klen/pylama\n\nContributors\n^^^^^^^^^^^^\n\nSee CONTRIBUTORS_.\n\n\n.. _license:\n\nLicense\n-------\n\nThis is free software. You are permitted to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of it, under the terms of the MIT\nLicense. See LICENSE file for the complete license.\n\nThis software is provided WITHOUT ANY WARRANTY; without even the implied\nwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See\nLICENSE file for the complete disclaimer.\n\n\n.. _links:\n\n.. _CONTRIBUTORS: https://github.com/klen/pylama/graphs/contributors\n.. _Mccabe: http://nedbatchelder.com/blog/200803/python_code_complexity_microtool.html\n.. _pydocstyle: https://github.com/PyCQA/pydocstyle/\n.. _pycodestyle: https://github.com/PyCQA/pycodestyle\n.. _PyFlakes: https://github.com/pyflakes/pyflakes\n.. _Pylint: http://pylint.org\n.. _Pytest: http://pytest.org\n.. _klen: http://klen.github.io/\n.. _eradicate: https://github.com/myint/eradicate\n.. _Mypy: https://github.com/python/mypy\n.. _Vulture: https://github.com/jendrikseipp/vulture\n\n.. |logo| image:: https://raw.github.com/klen/pylama/develop/docs/_static/logo.png\n                  :width: 100\n.. _Radon: https://github.com/rubik/radon\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fpylama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklen%2Fpylama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklen%2Fpylama/lists"}