Pyall is a linter that tries to keep the
__all__ in your Python modules always up to date.
pyall requires Python 3.8+ and can be easily installed using most common Python packaging tools. We recommend installing the latest stable release from PyPI with pip:
$ pip install pyall
the file directory you are in) ->
You can give as many file or directory paths as you want.
$ pyall example
$ pyall example example1 example2 example/example.py
(optional: default ‘\.(py)$’) file include pattern
$ pyall --include mypackage
$ pyall --include "mypackage|tests
(optional: default ‘^$’) file exclude pattern
$ pyall --exclude __init__.py
$ pyall --exclude "__init__.py|tests|.tox
Default public states.¶
- Variables are defined with an upper letters.
VARIABLE = "variable" PUBLIC_VARIABLE = "variable"
- functions, or classes that do not begin with an underscore are public.
def function(): ... class Klass: ...
Make It not-public¶
Write the comment
# pyall: not-public on the line containing the variable, function and class that you want to make public.
VARIABLE = "variable" # pyall: not-public def function(): # pyall: not-public ... class Klass: # pyall: not-public ...
Default not-public states.¶
- The variable is not public unless all characters are uppercase.
variable = "variable" Variable = "variable"
- Variables, functions, and classes that begin with an underscore are not public.
_VARIABLE = "variable" def _function(): ... class _Klass: ...
Make It Public¶
Write the comment
# pyall: public on the line containing the variable, function and class that you want to make public.
_variable = "variable" # pyall: public def _function(): # pyall: public ... class _Klass: # pyall: public ...
Command line options¶
You can list many options by running pyall –help
usage: Pyall [-h] [-r] [-d] [--include include] [--exclude exclude] [-v] [sources [sources ...]] Pyall is a linter that tries to keep the __all __ in your Python modules always up to date. positional arguments: sources Enter the directories and file paths you want to analyze. optional arguments: -h, --help show this help message and exit -r, --refactor Auto-sync __all__ list in python modules automatically. -d, --diff Prints a diff of all the changes Pyall would make to a file. --include include File include pattern. --exclude exclude File exclude pattern. -v, --version Prints version of pyall
Adding pre-commit plugins to your project¶
Add a file called .pre-commit-config.yaml to the root of your project. The pre-commit config file describes what repositories and hooks are installed.
repos: - repo: https://github.com/hakancelik96/pyall rev: stable hooks: - id: pyall args: [--refactor]
PUBLIC_VARIABLE = "variable" def _not_public_function(): ... class PublicKlass: ... class _NotPublicKlass: ... public_variable = "variable" # pyall: public
$ pyall /example.py -r
__all__ = ['PUBLIC_VARIABLE', 'PublicKlass', 'public_variable'] PUBLIC_VARIABLE = "variable" def _not_public_function(): ... class PublicKlass: ... class _NotPublicKlass: ... public_variable = "variable" # pyall: public
Created: July 24, 2021