commented-configparser 2.0.0__tar.gz → 2.2.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 (38) hide show
  1. commented_configparser-2.2.0/.github/workflows/pypi-publish.yml +56 -0
  2. commented_configparser-2.2.0/.github/workflows/python-tests.yml +119 -0
  3. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/.gitignore +1 -1
  4. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/.pre-commit-config.yaml +3 -21
  5. commented_configparser-2.2.0/CONTRIBUTING.md +120 -0
  6. {commented_configparser-2.0.0/src/commented_configparser.egg-info → commented_configparser-2.2.0}/PKG-INFO +14 -31
  7. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/README.md +6 -1
  8. commented_configparser-2.2.0/noxfile.py +203 -0
  9. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/pyproject.toml +12 -23
  10. commented_configparser-2.2.0/requirements/constraints.txt +38 -0
  11. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/requirements/requirements-dev.txt +8 -3
  12. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/requirements/requirements-test.txt +0 -1
  13. {commented_configparser-2.0.0 → commented_configparser-2.2.0/src/commented_configparser.egg-info}/PKG-INFO +14 -31
  14. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commented_configparser.egg-info/SOURCES.txt +2 -1
  15. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commented_configparser.egg-info/requires.txt +3 -4
  16. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commentedconfigparser/commentedconfigparser.py +12 -11
  17. commented_configparser-2.0.0/.github/workflows/python-tests.yml +0 -108
  18. commented_configparser-2.0.0/CONTRIBUTING.md +0 -186
  19. commented_configparser-2.0.0/noxfile.py +0 -160
  20. commented_configparser-2.0.0/requirements/requirements.txt +0 -6
  21. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/.flake8 +0 -0
  22. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/LICENSE +0 -0
  23. /commented_configparser-2.0.0/requirements/requirements.in → /commented_configparser-2.2.0/requirements/requirements.txt +0 -0
  24. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/setup.cfg +0 -0
  25. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commented_configparser.egg-info/dependency_links.txt +0 -0
  26. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commented_configparser.egg-info/top_level.txt +0 -0
  27. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commentedconfigparser/__init__.py +0 -0
  28. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/src/commentedconfigparser/py.typed +0 -0
  29. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/commentedconfigparser_test.py +0 -0
  30. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/header_expected.ini +0 -0
  31. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/header_input.ini +0 -0
  32. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/multi01_input.ini +0 -0
  33. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/multi02_input.ini +0 -0
  34. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/multi_expected.ini +0 -0
  35. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/pydocs_expected.ini +0 -0
  36. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/pydocs_input.ini +0 -0
  37. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/regression_original_expected.ini +0 -0
  38. {commented_configparser-2.0.0 → commented_configparser-2.2.0}/tests/regression_original_input.ini +0 -0
@@ -0,0 +1,56 @@
1
+ name: "Publish Python distribution to PyPI"
2
+ # Uses:
3
+ # https://github.com/actions/setup-python : 0b93645e9fea7318ecaed2b359559ac225c90a2b
4
+ # https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5
+ # https://github.com/actions/download-artifact : fa0a91b85d4f404e444e00e005971372dc801d16
6
+ # https://github.com/actions/upload-artifact : 6f51ac03b9356f520e9adb1b1b7802705f340c2b
7
+ # https://github.com/actions/pypa/gh-action-pypi-publish : 76f52bc884231f62b9a034ebfe128415bbaabdfc
8
+
9
+ on:
10
+ release:
11
+ types: [published]
12
+
13
+ jobs:
14
+ build:
15
+ name: "Build distribution"
16
+ runs-on: "ubuntu-latest"
17
+
18
+ steps:
19
+ - uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
20
+ with:
21
+ persist-credentials: false
22
+
23
+ - name: "Set up Python"
24
+ uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
25
+ with:
26
+ python-version: "3.12"
27
+
28
+ - name: "Build the package"
29
+ run: "python -m pip install nox; nox --session build"
30
+
31
+ - name: "Store the distribution packages"
32
+ uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
33
+ with:
34
+ name: "python-package-distributions"
35
+ path: "dist/"
36
+
37
+ publish-to-pypi:
38
+ name: "Publish Python Distribution to PyPI"
39
+ if: startsWith(github.ref, 'refs/tags/')
40
+ needs: ["build"]
41
+ runs-on: "ubuntu-latest"
42
+ environment:
43
+ name: "pypi"
44
+ url: "https://pypi.org/p/commented-configparser"
45
+ permissions:
46
+ id-token: "write"
47
+
48
+ steps:
49
+ - name: "Download all the dists"
50
+ uses: "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16"
51
+ with:
52
+ name: "python-package-distributions"
53
+ path: "dist/"
54
+
55
+ - name: "Publish distribution to PyPI"
56
+ uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc"
@@ -0,0 +1,119 @@
1
+ name: "python tests and coverage"
2
+ # Uses:
3
+ # https://github.com/actions/setup-python : 0b93645e9fea7318ecaed2b359559ac225c90a2b
4
+ # https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5
+ # https://github.com/actions/download-artifact : fa0a91b85d4f404e444e00e005971372dc801d16
6
+ # https://github.com/actions/upload-artifact : 6f51ac03b9356f520e9adb1b1b7802705f340c2b
7
+
8
+ on:
9
+ pull_request:
10
+ branches:
11
+ - "main"
12
+ push:
13
+ branches:
14
+ - "main"
15
+
16
+ jobs:
17
+ settings:
18
+ runs-on: "ubuntu-latest"
19
+ name: "Define workflow settings"
20
+ outputs:
21
+ default-python-version: "3.12"
22
+ steps:
23
+ - name: "Define settings"
24
+ run: ""
25
+
26
+ run-tests-and-coverage:
27
+ name: "Run pytest with coverage."
28
+ needs: ["settings"]
29
+ runs-on: "${{ matrix.os }}"
30
+ strategy:
31
+ fail-fast: false
32
+ matrix:
33
+ os:
34
+ - "windows-latest"
35
+ - "ubuntu-latest"
36
+ python-version:
37
+ - "3.9"
38
+ - "3.10"
39
+ - "3.11"
40
+ - "3.12"
41
+ - "3.13"
42
+ - "3.14"
43
+
44
+ steps:
45
+ - name: "Repo checkout"
46
+ uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
47
+
48
+ - name: "Set up Python ${{ matrix.python-version }}"
49
+ uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
50
+ with:
51
+ python-version: "${{ matrix.python-version }}"
52
+ allow-prereleases: true
53
+
54
+ - name: "Install nox"
55
+ run: |
56
+ python -m pip install --upgrade nox
57
+
58
+ - name: "Run tests and coverage via nox"
59
+ run: |
60
+ nox --session test -- partial-coverage
61
+
62
+ - name: "Save coverage artifact"
63
+ uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
64
+ with:
65
+ name: "coverage-artifact-${{ matrix.os}}-${{ matrix.python-version}}"
66
+ path: ".coverage.*"
67
+ retention-days: 1
68
+ include-hidden-files: true
69
+
70
+ coverage-compile:
71
+ name: "Compile coverage reports."
72
+ needs: ["settings", "run-tests-and-coverage"]
73
+ runs-on: "ubuntu-latest"
74
+ steps:
75
+ - name: "Repo checkout"
76
+ uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
77
+
78
+ - name: "Set up Python"
79
+ uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
80
+ with:
81
+ python-version: "${{ needs.settings.outputs.default-python-version }}"
82
+
83
+ - name: "Install nox"
84
+ run: |
85
+ python -m pip install --upgrade nox
86
+
87
+ - name: "Download coverage artifacts"
88
+ uses: "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16"
89
+ with:
90
+ pattern: "coverage-artifact-*"
91
+ merge-multiple: true
92
+
93
+ - name: "Compile coverage data, print report"
94
+ run: |
95
+ nox --session coverage_combine
96
+ export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
97
+ echo "TOTAL=$TOTAL" >> $GITHUB_ENV
98
+ echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
99
+
100
+ linting:
101
+ name: "Check linting and formatting requirements"
102
+ needs: ["settings"]
103
+ runs-on: "ubuntu-latest"
104
+ steps:
105
+ - name: "Repo checkout"
106
+ uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
107
+
108
+ - name: "Set up Python"
109
+ uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
110
+ with:
111
+ python-version: "${{ needs.settings.outputs.default-python-version }}"
112
+
113
+ - name: "Install nox"
114
+ run: |
115
+ python -m pip install --upgrade nox
116
+
117
+ - name: "Run formatters and linters"
118
+ run: |
119
+ nox --session lint
@@ -1,6 +1,6 @@
1
1
  temp_*
2
2
  .env
3
- venv/
3
+ .venv/
4
4
  *egg-info/
5
5
  .tox/
6
6
  .coverage
@@ -4,7 +4,7 @@ exclude: ^.+\.ini$
4
4
  repos:
5
5
  # Batch of helpful formatters and patterns
6
6
  - repo: https://github.com/pre-commit/pre-commit-hooks
7
- rev: "v4.6.0"
7
+ rev: "v5.0.0"
8
8
  hooks:
9
9
  - id: check-json
10
10
  - id: check-toml
@@ -12,12 +12,10 @@ repos:
12
12
  - id: trailing-whitespace
13
13
  - id: end-of-file-fixer
14
14
  - id: check-docstring-first
15
- - id: debug-statements
16
- - id: mixed-line-ending
17
15
 
18
16
  # Adds a standard feel to import segments
19
17
  - repo: https://github.com/pycqa/isort
20
- rev: 5.13.2
18
+ rev: 6.0.1
21
19
  hooks:
22
20
  - id: isort
23
21
  args:
@@ -29,22 +27,6 @@ repos:
29
27
 
30
28
  # Format code. No, I don't like everything black does either.
31
29
  - repo: https://github.com/psf/black-pre-commit-mirror
32
- rev: 24.4.2
30
+ rev: 25.1.0
33
31
  hooks:
34
32
  - id: black
35
-
36
- # Flake8 for linting, line-length adjusted to match Black default
37
- - repo: https://github.com/PyCQA/flake8
38
- rev: 7.1.0
39
- hooks:
40
- - id: flake8
41
- additional_dependencies:
42
- - flake8-builtins
43
- - flake8-pep585
44
- - pep8-naming
45
-
46
- # Type enforcement for Python
47
- - repo: https://github.com/pre-commit/mirrors-mypy
48
- rev: v1.11.1
49
- hooks:
50
- - id: mypy
@@ -0,0 +1,120 @@
1
+ # Contributing
2
+
3
+ Before contributing, please either ask to claim an existing open issue or create
4
+ a new issue to discuss your proposed changes with the owner(s) of this repo
5
+ before making any changes.
6
+
7
+ Any pull requests without a clearly defined issue being solved will be closed.
8
+
9
+ ### Bug reports
10
+
11
+ Found a bug but do not have time or do not wish to contribute a fix? Please
12
+ submit an issue for our awareness. Your feedback drives the continued
13
+ development of the project!
14
+
15
+ ### Pull Request
16
+
17
+ All pull requests must:
18
+
19
+ - Pass all linting and formatting checks
20
+ - Have tests that cover all branches of the added feature
21
+ - If the PR is a bug fix there must be a test that duplicates the bug, proving
22
+ it is fixed
23
+
24
+ ### Code Style
25
+
26
+ Follow the patterns seen in the code. Walk where others have walked.
27
+
28
+ Be sure to run the expected formatters and linters prior to opening the PR.
29
+
30
+ ### Tests
31
+
32
+ - Smaller tests are easier to work with
33
+ - Mock at a minimum
34
+ - No test should be dependent on another
35
+ - No test should be dependent on secrets/tokens
36
+
37
+ ---
38
+
39
+ # Local developer installation
40
+
41
+ The following steps outline how to install this repo for local development.
42
+
43
+ ## Prerequisites
44
+
45
+ ### Clone repo
46
+
47
+ ```bash
48
+ git clone https://github.com/Preocts/commented-configparser
49
+
50
+ cd commented-configparser
51
+ ```
52
+
53
+ ### [Install nox](https://nox.thea.codes/en/stable/index.html)
54
+
55
+ It is recommended to use a tool such as `pipx` or `uvx` to install nox. nox is
56
+ needed to run the provided sessions for developer setup, linting, tests, and
57
+ dependency management. It is optional, but these instructions will not cover
58
+ manually steps outside of nox.
59
+
60
+
61
+ ## Nox Sessions
62
+
63
+ ### Developer Install
64
+
65
+ This builds the `/.venv`, installs the editable
66
+ package, and installs all dependency files.
67
+
68
+ ```bash
69
+ nox -s dev
70
+ ```
71
+
72
+ ### Run tests with coverage
73
+
74
+ ```bash
75
+ nox -s test
76
+ ```
77
+
78
+ ### Run formatters and linters
79
+
80
+ ```bash
81
+ nox -s lint
82
+ ```
83
+
84
+ ### Build dist
85
+
86
+ ```bash
87
+ nox -s build
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Updating dependencies
93
+
94
+ New dependencys can be added to the `requirements-*.txt` file. It is recommended
95
+ to only use pins when specific versions or upgrades beyond a certain version are
96
+ to be avoided. Otherwise, allow `pip-compile` to manage the pins in the
97
+ generated `constraints.txt` file.
98
+
99
+ Once updated following the steps below, the package can be installed if needed.
100
+
101
+ ### Update the generated files with changes
102
+
103
+ ```bash
104
+ nox -s update-deps
105
+ ```
106
+
107
+ ### Upgrade all generated dependencies
108
+
109
+ ```bash
110
+ nox -s upgrade-deps
111
+ ```
112
+
113
+ ---
114
+
115
+ ## [pre-commit](https://pre-commit.com)
116
+
117
+ > A framework for managing and maintaining multi-language pre-commit hooks.
118
+
119
+ This repo is setup with a `.pre-commit-config.yaml` with the expectation that
120
+ any code submitted for review already passes all selected pre-commit checks.
@@ -1,52 +1,30 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: commented-configparser
3
- Version: 2.0.0
3
+ Version: 2.2.0
4
4
  Summary: Custom ConfigParser class that preserves comments in file when writing
5
5
  Author-email: Preocts <preocts@preocts.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 Preocts
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
-
6
+ License-Expression: MIT
28
7
  Project-URL: homepage, https://github.com/Preocts/commented-configparser
29
- Classifier: License :: OSI Approved :: MIT License
30
8
  Classifier: Programming Language :: Python :: 3
31
9
  Classifier: Programming Language :: Python :: 3 :: Only
32
10
  Classifier: Programming Language :: Python :: Implementation :: CPython
33
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.9
34
12
  Description-Content-Type: text/markdown
35
13
  License-File: LICENSE
36
14
  Provides-Extra: dev
37
- Requires-Dist: pre-commit; extra == "dev"
38
- Requires-Dist: black; extra == "dev"
39
- Requires-Dist: mypy; extra == "dev"
40
15
  Requires-Dist: flake8; extra == "dev"
41
16
  Requires-Dist: flake8-builtins; extra == "dev"
42
17
  Requires-Dist: flake8-pep585; extra == "dev"
18
+ Requires-Dist: black; extra == "dev"
19
+ Requires-Dist: isort; extra == "dev"
20
+ Requires-Dist: mypy; extra == "dev"
43
21
  Provides-Extra: test
44
22
  Requires-Dist: pytest; extra == "test"
45
23
  Requires-Dist: pytest-randomly; extra == "test"
46
24
  Requires-Dist: coverage; extra == "test"
47
- Requires-Dist: nox; extra == "test"
25
+ Dynamic: license-file
48
26
 
49
- [![Python 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | 3.13](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://www.python.org/downloads)
27
+ [![Python 3.9 | 3.10 | 3.11 | 3.12 | 3.13 | 3.14](https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://www.python.org/downloads)
50
28
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
51
29
  [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
52
30
 
@@ -55,6 +33,11 @@ Requires-Dist: nox; extra == "test"
55
33
 
56
34
  # commented-configparser
57
35
 
36
+ - [Contributing Guide and Developer Setup Guide](./CONTRIBUTING.md)
37
+ - [License: MIT](./LICENSE)
38
+
39
+ ---
40
+
58
41
  A custom ConfigParser class that preserves comments and option casing when writing loaded config out.
59
42
 
60
43
  This library gives you a custom class of the standard library's `configparser.ConfigParger` which will preserve the comments of a loaded config file when writing that file back out.
@@ -1,4 +1,4 @@
1
- [![Python 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | 3.13](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://www.python.org/downloads)
1
+ [![Python 3.9 | 3.10 | 3.11 | 3.12 | 3.13 | 3.14](https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://www.python.org/downloads)
2
2
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
3
3
  [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
4
4
 
@@ -7,6 +7,11 @@
7
7
 
8
8
  # commented-configparser
9
9
 
10
+ - [Contributing Guide and Developer Setup Guide](./CONTRIBUTING.md)
11
+ - [License: MIT](./LICENSE)
12
+
13
+ ---
14
+
10
15
  A custom ConfigParser class that preserves comments and option casing when writing loaded config out.
11
16
 
12
17
  This library gives you a custom class of the standard library's `configparser.ConfigParger` which will preserve the comments of a loaded config file when writing that file back out.
@@ -0,0 +1,203 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import pathlib
5
+ import shutil
6
+ import sys
7
+ from functools import partial
8
+
9
+ import nox
10
+
11
+ # Control factors for finding pieces of the module
12
+ MODULE_NAME = "commentedconfigparser"
13
+ TESTS_PATH = "tests"
14
+ COVERAGE_FAIL_UNDER = 100
15
+ VENV_PATH = "./.venv"
16
+ LINT_PATH = "./src"
17
+ REQUIREMENTS_PATH = "./requirements"
18
+
19
+ # What we allowed to clean (delete)
20
+ CLEANABLE_TARGETS = [
21
+ "./dist",
22
+ "./build",
23
+ "./.nox",
24
+ "./.coverage",
25
+ "./.coverage.*",
26
+ "./coverage.json",
27
+ "./**/.mypy_cache",
28
+ "./**/.pytest_cache",
29
+ "./**/__pycache__",
30
+ "./**/*.pyc",
31
+ "./**/*.pyo",
32
+ ]
33
+
34
+ # Define the default sessions run when `nox` is called on the CLI
35
+ nox.options.default_venv_backend = "virtualenv"
36
+ nox.options.sessions = ["lint", "test"]
37
+
38
+
39
+ @nox.session()
40
+ def dev(session: nox.Session) -> None:
41
+ """Setup a development environment by creating the venv and installs dependencies."""
42
+ # Use the active environement if it exists, otherwise create a new one
43
+ venv_path = os.environ.get("VIRTUAL_ENV", VENV_PATH)
44
+
45
+ if sys.platform == "win32":
46
+ venv_path = f"{venv_path}/Scripts"
47
+ activate_command = f"{venv_path}/activate"
48
+ else:
49
+ venv_path = f"{venv_path}/bin"
50
+ activate_command = f"source {venv_path}/activate"
51
+
52
+ if not os.path.exists(VENV_PATH):
53
+ session.run("python", "-m", "venv", VENV_PATH, "--upgrade-deps")
54
+
55
+ python = partial(session.run, f"{venv_path}/python", "-m")
56
+ contraint = ("--constraint", f"{REQUIREMENTS_PATH}/constraints.txt")
57
+
58
+ for requirement_file in get_requirement_files():
59
+ python("pip", "install", "-r", requirement_file, *contraint, external=True)
60
+
61
+ python("pip", "install", "--editable", ".", *contraint, external=True)
62
+
63
+ python("pip", "install", "pre-commit", external=True)
64
+ session.run(f"{venv_path}/pre-commit", "install", external=True)
65
+
66
+ if not os.environ.get("VIRTUAL_ENV"):
67
+ session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n")
68
+
69
+
70
+ @nox.session(name="test")
71
+ def run_tests_with_coverage(session: nox.Session) -> None:
72
+ """Run pytest with coverage, outputs console report and json."""
73
+ print_standard_logs(session)
74
+
75
+ contraint = ("--constraint", f"{REQUIREMENTS_PATH}/constraints.txt")
76
+
77
+ session.install(".[test]", *contraint)
78
+
79
+ coverage = partial(session.run, "python", "-m", "coverage")
80
+
81
+ coverage("erase")
82
+
83
+ if "partial-coverage" in session.posargs:
84
+ coverage("run", "--parallel-mode", "--module", "pytest", TESTS_PATH)
85
+ else:
86
+ coverage("run", "--module", "pytest", TESTS_PATH)
87
+ coverage("report", "--show-missing", f"--fail-under={COVERAGE_FAIL_UNDER}")
88
+ coverage("json")
89
+
90
+
91
+ @nox.session()
92
+ def coverage_combine(session: nox.Session) -> None:
93
+ """CI: Combine parallel-mode coverage files and produce reports."""
94
+ print_standard_logs(session)
95
+
96
+ contraint = ("--constraint", f"{REQUIREMENTS_PATH}/constraints.txt")
97
+
98
+ session.install("-r", f"{REQUIREMENTS_PATH}/requirements-test.txt", *contraint)
99
+
100
+ coverage = partial(session.run, "python", "-m", "coverage")
101
+ coverage("combine")
102
+ coverage("report", "--show-missing", f"--fail-under={COVERAGE_FAIL_UNDER}")
103
+ coverage("json")
104
+
105
+
106
+ @nox.session(name="lint")
107
+ def run_linters_and_formatters(session: nox.Session) -> None:
108
+ """Run code formatters, linters, and type checking against all files."""
109
+ print_standard_logs(session)
110
+
111
+ contraint = ("--constraint", f"{REQUIREMENTS_PATH}/constraints.txt")
112
+ session.install(".[dev]", *contraint)
113
+
114
+ python = partial(session.run, "python", "-m")
115
+
116
+ # Handle anything tool that applies corrections first.
117
+ python(
118
+ "isort",
119
+ "--verbose",
120
+ "--force-single-line-imports",
121
+ "--profile",
122
+ "black",
123
+ "--add-import",
124
+ "from __future__ import annotations",
125
+ LINT_PATH,
126
+ )
127
+ python("black", "--verbose", LINT_PATH)
128
+
129
+ # Linters: aka, things that yell but want you to fix things
130
+ python("flake8", "--show-source", "--verbose", LINT_PATH)
131
+ python("mypy", "--no-incremental", "--package", MODULE_NAME)
132
+
133
+
134
+ @nox.session()
135
+ def build(session: nox.Session) -> None:
136
+ """Build distribution files."""
137
+ print_standard_logs(session)
138
+
139
+ session.install("build")
140
+ session.run("python", "-m", "build")
141
+
142
+
143
+ @nox.session(name="update-deps")
144
+ def update_deps(session: nox.Session) -> None:
145
+ """Process requirement*.txt files, updating only additions/removals."""
146
+ print_standard_logs(session)
147
+
148
+ session.install("pip-tools")
149
+ session.run(
150
+ "pip-compile",
151
+ "--strip-extras",
152
+ "--no-annotate",
153
+ "--no-emit-index-url",
154
+ "--output-file",
155
+ f"{REQUIREMENTS_PATH}/constraints.txt",
156
+ *get_requirement_files(),
157
+ )
158
+
159
+
160
+ @nox.session(name="upgrade-deps")
161
+ def upgrade_deps(session: nox.Session) -> None:
162
+ """Process requirement*.txt files and upgrade all libraries as possible."""
163
+ print_standard_logs(session)
164
+
165
+ session.install("pip-tools")
166
+ session.run(
167
+ "pip-compile",
168
+ "--strip-extras",
169
+ "--no-annotate",
170
+ "--no-emit-index-url",
171
+ "--upgrade",
172
+ "--output-file",
173
+ f"{REQUIREMENTS_PATH}/constraints.txt",
174
+ *get_requirement_files(),
175
+ )
176
+
177
+
178
+ @nox.session(python=False)
179
+ def clean(_: nox.Session) -> None:
180
+ """Clean cache, .pyc, .pyo, and test/build artifact files from project."""
181
+ count = 0
182
+ for searchpath in CLEANABLE_TARGETS:
183
+ for filepath in pathlib.Path(".").glob(searchpath):
184
+ if filepath.is_dir():
185
+ shutil.rmtree(filepath)
186
+ else:
187
+ filepath.unlink()
188
+ count += 1
189
+
190
+ print(f"{count} files cleaned.")
191
+
192
+
193
+ def print_standard_logs(session: nox.Session) -> None:
194
+ """Reusable output for monitoring environment factors."""
195
+ version = session.run("python", "--version", silent=True)
196
+ session.log(f"Running from: {session.bin}")
197
+ session.log(f"Running with: {version}")
198
+
199
+
200
+ def get_requirement_files() -> list[pathlib.Path]:
201
+ """Get a list of requirement files matching "requirements*.txt"."""
202
+ glob = pathlib.Path(REQUIREMENTS_PATH).glob("requirements*.txt")
203
+ return [path for path in glob]