Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
name: "python tests and coverage"
# Uses:
# https://github.com/actions/setup-python
# https://github.com/actions/checkout
# https://github.com/actions/download-artifact
# https://github.com/actions/upload-artifact
# https://github.com/actions/setup-python : 0b93645e9fea7318ecaed2b359559ac225c90a2b
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/download-artifact : fa0a91b85d4f404e444e00e005971372dc801d16
# https://github.com/actions/upload-artifact : 6f51ac03b9356f520e9adb1b1b7802705f340c2b

on:
pull_request:
branches:
- "*"
- "main"
push:
branches:
- "main"

jobs:
settings:
runs-on: "ubuntu-latest"
name: "Define workflow settings"
outputs:
default-python-version: "3.12"
steps:
- name: "Define settings"
run: ""

run-tests-and-coverage:
name: "Run nox for tests and coverage"
name: "Run pytest with coverage."
needs: ["settings"]
runs-on: "${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
os:
- "macos-latest"
- "windows-latest"
- "ubuntu-latest"
python-version:
Expand All @@ -34,75 +43,77 @@ jobs:

steps:
- name: "Repo checkout"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"

- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
with:
python-version: "${{ matrix.python-version }}"
allow-prereleases: true

- name: "Install nox"
run: |
python -m pip install --upgrade pip nox
python -m pip install --upgrade nox

- name: "Run tests and coverage via nox"
run: |
nox --session tests_with_coverage-${{ matrix.python-version }}
nox --session test -- partial-coverage

- name: "Save coverage artifact"
uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3"
uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
with:
name: "coverage-artifact-${{ matrix.os}}-${{ matrix.python-version}}"
path: ".coverage.*"
retention-days: 1
include-hidden-files: true

coverage-compile:
name: "coverage compile"
needs: "run-tests-and-coverage"
name: "Compile coverage reports."
needs: ["settings", "run-tests-and-coverage"]
runs-on: "ubuntu-latest"
steps:
- name: "Repo checkout"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"

- name: "Set up Python"
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
with:
python-version: "3.12"
python-version: "${{ needs.settings.outputs.default-python-version }}"

- name: "Install nox"
run: |
python -m pip install --upgrade pip nox
python -m pip install --upgrade nox

- name: "Download coverage artifacts"
uses: "actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427"
uses: "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16"
with:
pattern: "coverage-artifact-*"
merge-multiple: true

- name: "Compile coverage data, print report"
run: |
nox --session coverage_combine_and_report
nox --session coverage_combine
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY

mypy-check:
name: "mypy strict enforcement"
linting:
name: "Check linting and formatting requirements"
needs: ["settings"]
runs-on: "ubuntu-latest"
steps:
- name: "Repo checkout"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"

- name: "Set up Python"
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
with:
python-version: "3.12"
python-version: "${{ needs.settings.outputs.default-python-version }}"

- name: "Install nox"
run: |
python -m pip install --upgrade pip nox
python -m pip install --upgrade nox

- name: "Enforce strict type annotations with mypy"
- name: "Run formatters and linters"
run: |
nox --session mypy_check
nox --session lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
temp_*
.env
venv/
.venv/
*egg-info/
.tox/
.coverage
Expand Down
18 changes: 0 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: debug-statements
- id: mixed-line-ending

# Adds a standard feel to import segments
- repo: https://github.com/pycqa/isort
Expand All @@ -32,19 +30,3 @@ repos:
rev: 25.1.0
hooks:
- id: black

# Flake8 for linting, line-length adjusted to match Black default
- repo: https://github.com/PyCQA/flake8
rev: 7.1.2
hooks:
- id: flake8
additional_dependencies:
- flake8-builtins
- flake8-pep585
- pep8-naming

# Type enforcement for Python
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
108 changes: 21 additions & 87 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ All pull requests must:

Follow the patterns seen in the code. Walk where others have walked.

The majority of code style nits will be met when passing `pre-commit` checks
prior to submitting a pull request.
Be sure to run the expected formatters and linters prior to opening the PR.

### Tests

Expand All @@ -35,7 +34,6 @@ prior to submitting a pull request.
- No test should be dependent on another
- No test should be dependent on secrets/tokens


---

# Local developer installation
Expand All @@ -52,122 +50,64 @@ git clone https://github.com/Preocts/commented-configparser
cd commented-configparser
```

### Virtual Environment

Use a ([`venv`](https://docs.python.org/3/library/venv.html)), or equivalent,
when working with python projects. Leveraging a `venv` will ensure the installed
dependency files will not impact other python projects or any system
dependencies.

**Windows users**: Depending on your python install you will use `py` in place
of `python` to create the `venv`.

**Linux/Mac users**: Replace `python`, if needed, with the appropriate call to
the desired version while creating the `venv`. (e.g. `python3` or `python3.12`)

**All users**: Once inside an active `venv` all systems should allow the use of
`python` for command line instructions. This will ensure you are using the
`venv`'s python and not the system level python.

### Create the `venv`:

```console
python -m venv venv
```

Activate the `venv`:
### [Install nox](https://nox.thea.codes/en/stable/index.html)

```console
# Linux/Mac
. venv/bin/activate

# Windows
venv\Scripts\activate
```

The command prompt should now have a `(venv)` prefix on it. `python` will now
call the version of the interpreter used to create the `venv`

To deactivate (exit) the `venv`:
It is recommended to use a tool such as `pipx` or `uvx` to install nox. nox is
needed to run the provided sessions for developer setup, linting, tests, and
dependency management. It is optional, but these instructions will not cover
manually steps outside of nox.

```console
deactivate
```

---
## Nox Sessions

## Developer Installation Steps
### Developer Install

### Install editable library and development requirements
This builds the `/.venv`, installs the editable
package, and installs all dependency files.

```console
python -m pip install --editable .[dev,test]
```bash
nox -s dev
```

### Install pre-commit [(see below for details)](#pre-commit)
### Run tests with coverage

```console
pre-commit install
nox -s test
```

### Install with nox

If you have `nox` installed with `pipx` or in the current venv you can use the
following session. This is an alternative to the two steps above.
### Run formatters and linters

```console
nox -s install
```

---

## Pre-commit and nox tools

### Run pre-commit on all files

```console
pre-commit run --all-files
```

### Run tests with coverage (quick)

```console
nox -e coverage
```

### Run tests (slow)

```console
nox
nox -s lint
```

### Build dist

```console
nox -e build
nox -s build
```

---

## Updating dependencies

New dependencys can be added to the `requirements-*.in` file. It is recommended
New dependencys can be added to the `requirements-*.txt` file. It is recommended
to only use pins when specific versions or upgrades beyond a certain version are
to be avoided. Otherwise, allow `pip-compile` to manage the pins in the
generated `requirements-*.txt` files.
generated `constraints.txt` file.

Once updated following the steps below, the package can be installed if needed.

### Update the generated files with changes

```console
nox -e update
nox -s update-deps
```

### Upgrade all generated dependencies

```console
nox -e upgrade
nox -s upgrade-deps
```

---
Expand All @@ -178,9 +118,3 @@ nox -e upgrade

This repo is setup with a `.pre-commit-config.yaml` with the expectation that
any code submitted for review already passes all selected pre-commit checks.

---

## Error: File "setup.py" not found

Update `pip` to at least version 22.3.1
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

# commented-configparser

- [Contributing Guide and Developer Setup Guide](./CONTRIBUTING.md)
- [License: MIT](./LICENSE)

---

A custom ConfigParser class that preserves comments and option casing when writing loaded config out.

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.
Expand Down
Loading