Skip to content

Commit b55293e

Browse files
Feature/sbachmei/improve python version handling (#5)
* update readme with pip install instructions * auto-extract python versions for test matrix * Auto-update README when supported python versions change * import ConfigNode and custom errors at package level * bugfix add value_name attr to ConfigurationError --------- Co-authored-by: github-actions <action@github.com>
1 parent 02d2086 commit b55293e

File tree

12 files changed

+122
-12
lines changed

12 files changed

+122
-12
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -----------------------------------------------------------------------------
22
# - invoked on push, pull_request, manual trigger, or schedule
3-
# - test under at least 3 versions of python
3+
# - test under all supported versions of python (see python_versions.json)
44
# -----------------------------------------------------------------------------
55
name: build
66
on:
@@ -11,11 +11,25 @@ on:
1111
- cron: "0 8 * * *"
1212

1313
jobs:
14+
get-python-versions:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
- name: Install jq
20+
run: sudo apt-get install jq
21+
- name: Get Python versions
22+
id: set-matrix
23+
run: |
24+
echo "MATRIX_RESULT=$(jq -c . python_versions.json)" >> $GITHUB_ENV
25+
outputs:
26+
matrix: ${{ env.MATRIX_RESULT }}
1427
build:
28+
needs: get-python-versions
1529
runs-on: ubuntu-latest
1630
strategy:
1731
matrix:
18-
python-version: ["3.9", "3.10", "3.11"]
32+
python-version: ${{ fromJSON(needs.get-python-versions.outputs.matrix) }}
1933
steps:
2034
- uses: actions/checkout@v3
2135
- name: Set up Python ${{ matrix.python-version }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -----------------------------------------------------------------------------
2+
# - invoked on push to any branch
3+
# -----------------------------------------------------------------------------
4+
name: update README
5+
6+
on: push
7+
8+
jobs:
9+
update-readme:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.11
18+
- name: Update README
19+
run: |
20+
pip install packaging
21+
python update_readme.py
22+
- name: Commit and push changes
23+
run: |
24+
git config --local user.email "action@github.com"
25+
git config --local user.name "github-actions"
26+
git diff --quiet && git diff --staged --quiet || (
27+
git add README.rst
28+
git commit -am "update README with supported Python versions"
29+
git pull --rebase origin ${{ github.ref_name }}
30+
git push origin ${{ github.ref_name }}
31+
)
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
**1.0.1 - 04/11/2024**
2+
3+
- Extract python version test matrix from python_versions.json
4+
- Automatically update README when supported python versions change
5+
- Bugfix missing ConfigurationError attribute
6+
17
**1.0.0 - 04/11/2024**
28

39
- Initial release

README.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ Layered Config Tree
44

55
Layered Config Tree is a configuration structure that supports cascading layers.
66

7-
**Layered Config Tree requires Python 3.8-3.11 to run**
7+
**Supported Python versions: 3.8, 3.9, 3.10, 3.11**
88

9-
You can build ``layered_config_tree`` from from source with
9+
You can install ``layered_config_tree`` from PyPI with pip:
10+
11+
``> pip install layered_config_tree``
12+
13+
or build it from from source:
1014

1115
``> git clone https://github.com/ihmeuw/layered_config_tree.git``
1216

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[build-system]
2+
requires = ["packaging", "setuptools"]
3+
14
[tool.black]
25
line_length = 94
36

python_versions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["3.8", "3.9", "3.10", "3.11"]

setup.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import json
12
import sys
23
from pathlib import Path
34

5+
from packaging.version import parse
46
from setuptools import find_packages, setup
57

6-
min_version, max_version = ((3, 8), "3.8"), ((3, 11), "3.11")
8+
with open("python_versions.json", "r") as f:
9+
supported_python_versions = json.load(f)
710

8-
if not (min_version[0] <= sys.version_info[:2] <= max_version[0]):
9-
# Python 3.5 does not support f-strings
11+
python_versions = [parse(v) for v in supported_python_versions]
12+
min_version = min(python_versions)
13+
max_version = max(python_versions)
14+
if not (
15+
min_version <= parse(".".join([str(v) for v in sys.version_info[:2]])) <= max_version
16+
):
1017
py_version = ".".join([str(v) for v in sys.version_info[:3]])
18+
# NOTE: Python 3.5 does not support f-strings
1119
error = (
1220
"\n----------------------------------------\n"
1321
"Error: Layered Config Tree runs under python {min_version}-{max_version}.\n"
1422
"You are running python {py_version}".format(
15-
min_version=min_version[1], max_version=max_version[1], py_version=py_version
23+
min_version=min_version.base_version,
24+
max_version=max_version.base_version,
25+
py_version=py_version,
1626
)
1727
)
1828
print(error, file=sys.stderr)

src/layered_config_tree/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
__uri__,
99
)
1010
from layered_config_tree._version import __version__
11-
from layered_config_tree.main import LayeredConfigTree
11+
from layered_config_tree.exceptions import (
12+
ConfigurationError,
13+
ConfigurationKeyError,
14+
DuplicatedConfigurationError,
15+
)
16+
from layered_config_tree.main import ConfigNode, LayeredConfigTree

src/layered_config_tree/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ConfigurationError(Exception):
66

77
def __init__(self, message: str, value_name: Optional[str]):
88
super().__init__(message)
9+
self.value_name = value_name
910

1011

1112
class ConfigurationKeyError(ConfigurationError, KeyError):

src/layered_config_tree/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import yaml
3434

35-
from layered_config_tree.exceptions import (
35+
from layered_config_tree import (
3636
ConfigurationError,
3737
ConfigurationKeyError,
3838
DuplicatedConfigurationError,

0 commit comments

Comments
 (0)