boa-restrictor 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. boa_restrictor-1.0.0/.ambient-package-update/metadata.py +45 -0
  2. boa_restrictor-1.0.0/.ambient-package-update/templates/snippets/content.tpl +42 -0
  3. boa_restrictor-1.0.0/.ambient-package-update/templates/snippets/installation.tpl +61 -0
  4. boa_restrictor-1.0.0/.ambient-package-update/templates/snippets/tagline.tpl +1 -0
  5. boa_restrictor-1.0.0/.editorconfig +18 -0
  6. boa_restrictor-1.0.0/.github/workflows/ci.yml +88 -0
  7. boa_restrictor-1.0.0/.gitignore +158 -0
  8. boa_restrictor-1.0.0/.pre-commit-config.yaml +56 -0
  9. boa_restrictor-1.0.0/.pre-commit-hooks.yaml +6 -0
  10. boa_restrictor-1.0.0/.readthedocs.yaml +31 -0
  11. boa_restrictor-1.0.0/LICENSE.md +21 -0
  12. boa_restrictor-1.0.0/MANIFEST.in +4 -0
  13. boa_restrictor-1.0.0/PKG-INFO +266 -0
  14. boa_restrictor-1.0.0/README.md +219 -0
  15. boa_restrictor-1.0.0/SECURITY.md +18 -0
  16. boa_restrictor-1.0.0/boa_restrictor/__init__.py +3 -0
  17. boa_restrictor-1.0.0/boa_restrictor/cli/__init__.py +0 -0
  18. boa_restrictor-1.0.0/boa_restrictor/cli/configuration.py +25 -0
  19. boa_restrictor-1.0.0/boa_restrictor/cli/main.py +74 -0
  20. boa_restrictor-1.0.0/boa_restrictor/common/__init__.py +0 -0
  21. boa_restrictor-1.0.0/boa_restrictor/common/noqa.py +23 -0
  22. boa_restrictor-1.0.0/boa_restrictor/common/rule.py +29 -0
  23. boa_restrictor-1.0.0/boa_restrictor/projections/__init__.py +0 -0
  24. boa_restrictor-1.0.0/boa_restrictor/projections/occurrence.py +10 -0
  25. boa_restrictor-1.0.0/boa_restrictor/rules/__init__.py +7 -0
  26. boa_restrictor-1.0.0/boa_restrictor/rules/asterisk_required.py +41 -0
  27. boa_restrictor-1.0.0/boa_restrictor/rules/return_type_hints.py +36 -0
  28. boa_restrictor-1.0.0/docs/Makefile +20 -0
  29. boa_restrictor-1.0.0/docs/conf.py +82 -0
  30. boa_restrictor-1.0.0/docs/make.bat +35 -0
  31. boa_restrictor-1.0.0/pyproject.toml +265 -0
  32. boa_restrictor-1.0.0/scripts/unix/install_requirements.sh +3 -0
  33. boa_restrictor-1.0.0/scripts/unix/publish_to_pypi.sh +2 -0
  34. boa_restrictor-1.0.0/scripts/windows/install_requirements.ps1 +3 -0
  35. boa_restrictor-1.0.0/scripts/windows/publish_to_pypi.ps1 +2 -0
  36. boa_restrictor-1.0.0/tests/__init__.py +0 -0
  37. boa_restrictor-1.0.0/tests/cli/__init__.py +0 -0
  38. boa_restrictor-1.0.0/tests/cli/test_configuration.py +34 -0
  39. boa_restrictor-1.0.0/tests/cli/test_main.py +87 -0
  40. boa_restrictor-1.0.0/tests/common/__init__.py +0 -0
  41. boa_restrictor-1.0.0/tests/common/test_noqa.py +20 -0
  42. boa_restrictor-1.0.0/tests/common/test_rule.py +25 -0
  43. boa_restrictor-1.0.0/tests/rules/__init__.py +0 -0
  44. boa_restrictor-1.0.0/tests/rules/test_asterisk_required.py +185 -0
  45. boa_restrictor-1.0.0/tests/rules/test_return_type_hints.py +39 -0
@@ -0,0 +1,45 @@
1
+ from ambient_package_update.metadata.author import PackageAuthor
2
+ from ambient_package_update.metadata.constants import (
3
+ DEV_DEPENDENCIES,
4
+ LICENSE_MIT,
5
+ SUPPORTED_DJANGO_VERSIONS,
6
+ SUPPORTED_PYTHON_VERSIONS,
7
+ )
8
+ from ambient_package_update.metadata.executables import ScriptExecutable
9
+ from ambient_package_update.metadata.maintainer import PackageMaintainer
10
+ from ambient_package_update.metadata.package import PackageMetadata
11
+ from ambient_package_update.metadata.readme import ReadmeContent
12
+ from ambient_package_update.metadata.ruff_ignored_inspection import RuffIgnoredInspection
13
+
14
+ METADATA = PackageMetadata(
15
+ package_name="boa-restrictor",
16
+ github_package_group="ambient-innovation",
17
+ authors=[
18
+ PackageAuthor(
19
+ name="Ambient Digital",
20
+ email="hello@ambient.digital",
21
+ ),
22
+ ],
23
+ maintainer=PackageMaintainer(name="Ambient Digital", url="https://ambient.digital/", email="hello@ambient.digital"),
24
+ company="Ambient Innovation: GmbH",
25
+ license=LICENSE_MIT,
26
+ license_year=2024,
27
+ development_status="4 - Beta",
28
+ has_migrations=False,
29
+ readme_content=ReadmeContent(uses_internationalisation=False),
30
+ main_branch="main",
31
+ is_django_package=False,
32
+ dependencies=['tomli; python_version < "3.11"'],
33
+ supported_django_versions=SUPPORTED_DJANGO_VERSIONS,
34
+ supported_python_versions=SUPPORTED_PYTHON_VERSIONS,
35
+ optional_dependencies={
36
+ "dev": [
37
+ *DEV_DEPENDENCIES,
38
+ ],
39
+ },
40
+ ruff_ignore_list=[
41
+ RuffIgnoredInspection(key="TD002", comment="Missing issue link on the line following this TODO"),
42
+ RuffIgnoredInspection(key="TD003", comment="Missing issue link on the line following this TODO"),
43
+ ],
44
+ script_executables=[ScriptExecutable(name="boa-restrictor", import_path="boa_restrictor.cli.main:main")],
45
+ )
@@ -0,0 +1,42 @@
1
+ ## Rules
2
+
3
+ ### Positional arguments not allowed (PBR001)
4
+
5
+ This rule enforces that functions and methods don't contain any positional arguments.
6
+
7
+ This will make refactorings easier, is more explicit,
8
+ and you avoid the [boolean bug trap](https://adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/).
9
+
10
+ *Wrong:*
11
+
12
+ ```python
13
+ def my_func(a, b):
14
+ pass
15
+ ```
16
+
17
+ *Correct:*
18
+
19
+ ```python
20
+ def my_func(*, a, b):
21
+ pass
22
+ ```
23
+
24
+ ### Return type hints required if a return statement exists (PBR002)
25
+
26
+ This rule will enforce that you add a return type-hint to all methods and functions that contain a `return` statement.
27
+ This way we can be more explicit and let the IDE help the next developer because it will add warnings if you use
28
+ wrong types.
29
+
30
+ *Wrong:*
31
+
32
+ ```python
33
+ def my_func(a, b):
34
+ return a * b
35
+ ```
36
+
37
+ *Correct:*
38
+
39
+ ```python
40
+ def my_func(a, b) -> int:
41
+ return a * b
42
+ ```
@@ -0,0 +1,61 @@
1
+ ## Installation
2
+
3
+ Add the following to your .pre-commit-config.yaml file:
4
+
5
+ ```yml
6
+ - repo: https://github.com/ambient-innovation/boa-restrictor
7
+ rev: v{{ version }}
8
+ hooks:
9
+ - id: boa-restrictor
10
+ args: [ --config=pyproject.toml ]
11
+ ```
12
+
13
+ Now you can run the linter manually:
14
+
15
+ pre-commit run --all-files boa-restrictor
16
+
17
+
18
+ ## Configuration
19
+
20
+ ### Exclude certain files
21
+
22
+ You can easily exclude certain files, for example, your tests, by using the `exclude` parameter from `pre-commit`:
23
+
24
+ ```yml
25
+ - repo: https://github.com/ambient-innovation/boa-restrictor
26
+ rev: v{{ version }}
27
+ hooks:
28
+ - id: boa-restrictor
29
+ ...
30
+ exclude: |
31
+ (?x)^(
32
+ /.*/tests/.*
33
+ |.*/test_.*\.py
34
+ )$
35
+ ```
36
+
37
+ ### Exclude configuration rule
38
+
39
+ You can disable any rule in your `pyproject.toml` file as follows:
40
+
41
+ ```toml
42
+ [tool.boa-restrictor]
43
+ exclude = [
44
+ "PBR001",
45
+ "PBR002",
46
+ ]
47
+ ```
48
+
49
+ ### Ruff support
50
+
51
+ If you are using `ruff`, you need to tell it about our linting rules. Otherwise, ruff will remove all `# noqa`
52
+ statements from your codebase.
53
+
54
+ ```toml
55
+ [tool.ruff.lint]
56
+ # Avoiding flagging (and removing) any codes starting with `PBR` from any
57
+ # `# noqa` directives, despite Ruff's lack of support for `boa-restrictor`.
58
+ external = ["PBR"]
59
+ ```
60
+
61
+ https://docs.astral.sh/ruff/settings/#lint_extend-unsafe-fixes
@@ -0,0 +1 @@
1
+ Welcome to the **boa-restrictor** - a custom Python linter from Ambient
@@ -0,0 +1,18 @@
1
+ # http://editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.{py,rst,ini}]
12
+ indent_style = space
13
+ indent_size = 4
14
+ ij_continuation_indent_size = 8
15
+
16
+ [*.yml]
17
+ indent_style = space
18
+ indent_size = 2
@@ -0,0 +1,88 @@
1
+ name: Unit tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ linting:
11
+ runs-on: ubuntu-24.04
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up Python 3.12
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+
20
+ - name: Install required packages
21
+ run: pip install pre-commit
22
+
23
+ - name: Run pre-commit hooks
24
+ run: pre-commit run --all-files --hook-stage push
25
+
26
+
27
+ tests:
28
+ name: Python ${{ matrix.python-version }}, django ${{ matrix.django-version }}
29
+ runs-on: ubuntu-24.04
30
+ strategy:
31
+ matrix:
32
+ python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', ]
33
+ django-version: ['42', '50', '51', ]
34
+
35
+ exclude:
36
+ - python-version: '3.9'
37
+ django-version: 50
38
+ - python-version: '3.9'
39
+ django-version: 51
40
+
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ - name: setup python
44
+ uses: actions/setup-python@v5
45
+ with:
46
+ python-version: ${{ matrix.python-version }}
47
+ - name: Install tox
48
+ run: pip install tox
49
+ - name: Run Tests
50
+ env:
51
+ TOXENV: django${{ matrix.django-version }}
52
+ run: tox
53
+ - name: Upload coverage data
54
+ uses: actions/upload-artifact@v4
55
+ with:
56
+ name: coverage-data-${{ matrix.python-version }}-${{ matrix.django-version }}
57
+ path: '${{ github.workspace }}/.coverage.*'
58
+ include-hidden-files: true
59
+ if-no-files-found: error
60
+
61
+ coverage:
62
+ name: Coverage
63
+ runs-on: ubuntu-24.04
64
+ needs: tests
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+
68
+ - uses: actions/setup-python@v5
69
+ with:
70
+ python-version: '3.12'
71
+
72
+ - name: Install dependencies
73
+ run: python -m pip install --upgrade coverage[toml]
74
+
75
+ - name: Download data
76
+ uses: actions/download-artifact@v4
77
+ with:
78
+ path: ${{ github.workspace }}
79
+ pattern: coverage-data-*
80
+ merge-multiple: true
81
+
82
+ - name: Combine coverage and fail if it's <100.0%
83
+ run: |
84
+ python -m coverage combine
85
+ python -m coverage html --skip-covered --skip-empty
86
+ python -m coverage report --fail-under=100.0
87
+ echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY
88
+ python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
@@ -0,0 +1,158 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pdm
86
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
87
+ #pdm.lock
88
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
89
+ # in version control.
90
+ # https://pdm.fming.dev/#use-with-ide
91
+ .pdm.toml
92
+
93
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
94
+ __pypackages__/
95
+
96
+ # Celery stuff
97
+ celerybeat-schedule
98
+ celerybeat.pid
99
+
100
+ # SageMath parsed files
101
+ *.sage.py
102
+
103
+ # Environments
104
+ .env
105
+ .venv
106
+ env/
107
+ venv/
108
+ ENV/
109
+ env.bak/
110
+ venv.bak/
111
+
112
+ # Spyder project settings
113
+ .spyderproject
114
+ .spyproject
115
+
116
+ # Rope project settings
117
+ .ropeproject
118
+
119
+ # mkdocs documentation
120
+ /site
121
+
122
+ # mypy
123
+ .mypy_cache/
124
+ .dmypy.json
125
+ dmypy.json
126
+
127
+ # Pyre type checker
128
+ .pyre/
129
+
130
+ # pytype static type analyzer
131
+ .pytype/
132
+
133
+ # Cython debug symbols
134
+ cython_debug/
135
+
136
+ # PyCharm
137
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
138
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
139
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
140
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
141
+ .idea/
142
+
143
+ # Requirements.txt is managed by pip-tools
144
+ requirements.txt
145
+
146
+ # sphinx build folder
147
+ _build
148
+
149
+ # Compiled source #
150
+ ###################
151
+ *.com
152
+ *.class
153
+ *.dll
154
+ *.exe
155
+ *.o
156
+
157
+ # Test databases
158
+ *.sqlite
@@ -0,0 +1,56 @@
1
+ # you find the full pre-commit-tools docu under:
2
+ # https://pre-commit.com/
3
+
4
+ repos:
5
+ - repo: https://github.com/astral-sh/ruff-pre-commit
6
+ rev: v0.7.4
7
+ hooks:
8
+ # Run the Ruff linter.
9
+ - id: ruff
10
+ args: [--fix, --exit-non-zero-on-fix]
11
+ # Run the Ruff formatter.
12
+ - id: ruff-format
13
+
14
+ - repo: https://github.com/adamchainz/blacken-docs
15
+ rev: 1.19.1
16
+ hooks:
17
+ - id: blacken-docs
18
+ additional_dependencies:
19
+ - black==24.10.0
20
+ files: '(?:README\.md|docs\/.*\.(?:md|rst))'
21
+
22
+ - repo: https://github.com/asottile/pyupgrade
23
+ rev: v3.19.0
24
+ hooks:
25
+ - id: pyupgrade
26
+ args: [ --py39-plus ]
27
+ stages: [ pre-push ]
28
+
29
+ - repo: https://github.com/adamchainz/django-upgrade
30
+ rev: 1.22.1
31
+ hooks:
32
+ - id: django-upgrade
33
+ args: [--target-version, "4.2"]
34
+ stages: [ pre-push ]
35
+
36
+ - repo: https://github.com/adamchainz/djade-pre-commit
37
+ rev: 1.3.2
38
+ hooks:
39
+ - id: djade
40
+ args: [--target-version, "4.2"]
41
+ exclude: |
42
+ (?x)^(
43
+ charts/.*
44
+ |.*\.py
45
+ )$
46
+
47
+ - repo: https://github.com/pre-commit/pre-commit-hooks
48
+ rev: v5.0.0
49
+ hooks:
50
+ - id: no-commit-to-branch
51
+ args:
52
+ [
53
+ "--pattern",
54
+ '^^(?!(?:feature|hotfix|bugfix|refactor|maintenance)/[\w\d\-_#]+).*$',
55
+ ]
56
+ stages: [ pre-commit ]
@@ -0,0 +1,6 @@
1
+ - id: boa-restrictor
2
+ name: Boa Restrictor Linter by Ambient
3
+ description: A custom Python linter by Ambient
4
+ entry: boa-restrictor
5
+ language: python
6
+ types: [ python ]
@@ -0,0 +1,31 @@
1
+ # .readthedocs.yaml
2
+ # Read the Docs configuration file
3
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4
+
5
+ # Required
6
+ version: 2
7
+
8
+ # Set the OS, Python version and other tools you might need
9
+ build:
10
+ os: ubuntu-24.04
11
+ tools:
12
+ python: "3.12"
13
+
14
+ # Build documentation in the "docs/" directory with Sphinx
15
+ sphinx:
16
+ configuration: docs/conf.py
17
+
18
+ # Optionally build your docs in additional formats such as PDF and ePub
19
+ # formats:
20
+ # - pdf
21
+ # - epub
22
+
23
+ # Optional but recommended, declare the Python requirements required
24
+ # to build your documentation
25
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
26
+ python:
27
+ install:
28
+ - method: pip
29
+ path: .
30
+ extra_requirements:
31
+ - dev
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ambient Innovation: GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE.md
3
+ recursive-exclude * *.pyc
4
+ recursive-include boa-restrictor *.py *.html *.js *.cfg *.mo *.po