Skip to content

Home

Get Started

Pyall is a linter that tries to keep the __all__ in your Python modules always up to date.

pre-commit.ci status test

Pypi PyPI - Python Version Downloads License

Forks Issues Stars

Codecov Contributors Last Commit

Installation

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

Sources

(optional: default the file directory you are in) -> Path(".")

You can give as many file or directory paths as you want.

Usage

  • $ pyall
  • $ pyall example
  • $ pyall example example1 example2 example/example.py

Include

(optional: default ‘\.(py)$’) file include pattern

Usage

  • $ pyall --include mypackage
  • $ pyall --include "mypackage|tests

Exclude

(optional: default ‘^$’) file exclude pattern

Usage

  • $ 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

Once you have pre-commit installed, adding pre-commit plugins to your project is done with the .pre-commit-config.yaml configuration file.

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]

Examples

/example.py

PUBLIC_VARIABLE = "variable"

def _not_public_function():
  ...

class PublicKlass:
  ...


class _NotPublicKlass:
  ...


public_variable = "variable" # pyall: public

Command line: $ pyall /example.py -r

Output

__all__ = ['PUBLIC_VARIABLE', 'PublicKlass', 'public_variable']

PUBLIC_VARIABLE = "variable"

def _not_public_function():
  ...

class PublicKlass:
  ...


class _NotPublicKlass:
  ...


public_variable = "variable" # pyall: public

Last update: July 24, 2021
Created: July 24, 2021