Skip to content

Commit 2b9bdea

Browse files
committed
CI & compatibility
1 parent 8158ca6 commit 2b9bdea

7 files changed

Lines changed: 117 additions & 33 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
on:
2+
push:
3+
pull_request:
4+
schedule: [{cron: '3 2 * * 6'}] # M H d m w (Sat 2:03)
5+
jobs:
6+
test:
7+
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
8+
strategy:
9+
matrix:
10+
python: [3.8, 3.9, '3.10', 3.11, 3.12, 3.13, 3.14]
11+
os: [ubuntu]
12+
include: [{os: macos, python: 3.13}, {os: windows, python: 3.13}]
13+
runs-on: ${{ matrix.os }}-latest
14+
timeout-minutes: 5
15+
defaults: {run: {shell: bash}}
16+
steps:
17+
- uses: actions/checkout@v6
18+
with: {fetch-depth: 0}
19+
- uses: actions/setup-python@v6
20+
with:
21+
python-version: ${{ matrix.python }}
22+
- run: pip install -e .[dev]
23+
- run: pytest --cov=envwrap --cov-report=xml
24+
- uses: coverallsapp/github-action@v2
25+
with:
26+
flag-name: ${{ matrix.python }}-${{ matrix.os }}
27+
parallel: true
28+
- uses: codecov/codecov-action@v6
29+
with:
30+
token: ${{ secrets.CODECOV_TOKEN }}
31+
flags: ${{ matrix.python }}, ${{ matrix.os }}
32+
- name: codacy
33+
run: |
34+
bash <(curl -fsL https://coverage.codacy.com/get.sh) report -l Python -r coverage.xml --partial || :
35+
env:
36+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
37+
finish:
38+
continue-on-error: ${{ github.event_name != 'push' }}
39+
needs: test
40+
runs-on: ubuntu-slim
41+
steps:
42+
- uses: coverallsapp/github-action@v2
43+
with: {parallel-finished: true}
44+
- name: codacy
45+
run: |
46+
bash <(curl -fsL https://coverage.codacy.com/get.sh) final || :
47+
env:
48+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
49+
deploy:
50+
needs: test
51+
runs-on: ubuntu-latest
52+
environment: pypi
53+
permissions: {contents: write, id-token: write, packages: write}
54+
steps:
55+
- uses: actions/checkout@v6
56+
with:
57+
fetch-depth: 0
58+
token: ${{ secrets.GH_TOKEN || github.token }}
59+
- uses: actions/setup-python@v6
60+
with: {python-version: '3.x'}
61+
- id: dist
62+
uses: casperdcl/deploy-pypi@v3
63+
with:
64+
upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
65+
build: true
66+
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
67+
name: Release
68+
run: |
69+
changelog=$(git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD)
70+
tag="${GITHUB_REF#refs/tags/}"
71+
gh release create --title "tqdm $tag stable" --draft --notes "$changelog" "$tag" dist/${{ steps.dist.outputs.whl }} dist/${{ steps.dist.outputs.whl_asc }}
72+
env:
73+
GH_TOKEN: ${{ secrets.GH_TOKEN }}

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ repos:
5353
rev: v3.21.2
5454
hooks:
5555
- id: pyupgrade
56-
args: [--py37-plus]
56+
args: [--py38-plus]
5757
- repo: https://github.com/PyCQA/isort
5858
rev: 9.0.0a3
5959
hooks:

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# envwrap
22

3+
[![CI](https://github.com/tqdm/envwrap/actions/workflows/test.yml/badge.svg)](https://github.com/tqdm/envwrap/actions/workflows/test.yml)
4+
[![coveralls](https://img.shields.io/coveralls/github/tqdm/envwrap/main?logo=coveralls)](https://coveralls.io/github/tqdm/envwrap)
5+
[![codecov](https://codecov.io/gh/tqdm/envwrap/graph/badge.svg?token=PEWICBIPVW)](https://codecov.io/gh/tqdm/envwrap)
6+
[![codacy](https://app.codacy.com/project/badge/Grade/6ca7a441560444489fd5c5b1548ab0de)](https://app.codacy.com/gh/tqdm/envwrap/dashboard)
7+
38
Override parameter defaults via environment variables & config files.
49

510
```py

‎envwrap/__init__.py‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import logging
22
import os
3-
from functools import cache, partial, partialmethod
3+
from functools import partial, partialmethod
4+
5+
try:
6+
from functools import cache # py>=3.9
7+
except ImportError:
8+
from functools import lru_cache
9+
cache = lru_cache(maxsize=None)
410
from inspect import signature
511
from pathlib import Path, PurePath
612
from warnings import warn
@@ -10,27 +16,27 @@
1016
log = logging.getLogger(__name__)
1117

1218

13-
def read_config(fpath: PurePath) -> dict[str]:
19+
def read_config(fpath: PurePath) -> dict:
1420
log.debug("Reading: %s", fpath)
15-
match fpath.suffix.lower():
16-
case ".toml":
17-
try:
18-
from tomllib import loads # py>=3.11
19-
except ModuleNotFoundError:
20-
from toml import loads
21-
case ".yaml" | ".yml":
22-
from yaml import safe_load as loads
23-
case ".json":
24-
from json import loads
25-
case ".ini" | ".cfg":
26-
from configparser import ConfigParser
27-
28-
def loads(s):
29-
parser = ConfigParser()
30-
parser.read_string(s)
31-
return {sec: dict(parser.items(sec)) for sec in parser.sections()}
32-
case _:
33-
raise TypeError(f"Unsupported config filetype: {fpath}")
21+
ext = fpath.suffix.lower()[1:]
22+
if ext == "toml":
23+
try:
24+
from tomllib import loads # py>=3.11
25+
except ModuleNotFoundError:
26+
from toml import loads
27+
elif ext in ("yaml", "yml"):
28+
from yaml import safe_load as loads
29+
elif ext == "json":
30+
from json import loads
31+
elif ext in ("ini", "cfg"):
32+
from configparser import ConfigParser
33+
34+
def loads(s):
35+
parser = ConfigParser()
36+
parser.read_string(s)
37+
return {sec: dict(parser.items(sec)) for sec in parser.sections()}
38+
else:
39+
raise TypeError(f"Unsupported config filetype: {fpath}")
3440

3541
return loads(fpath.read_text())
3642

@@ -73,7 +79,7 @@ def load_overrides(name: str, app: str, func: str):
7379
return overrides
7480

7581

76-
def envwrap(name: str, app: str = "", types: dict | None = None, is_method=False):
82+
def envwrap(name: str, app: str = "", types: dict = None, is_method=False):
7783
"""
7884
Override parameter defaults via environment variables & config files.
7985
Precedence (descending):

‎envwrap/cli.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ def main(argv=None):
1313
args = parser.parse_args(argv)
1414
logging.basicConfig(
1515
level={0: logging.INFO, 1: logging.DEBUG}.get(args.verbose, logging.NOTSET))
16-
match len(args.args):
17-
case 2:
18-
app = ""
19-
case 3:
20-
app = args.args[1]
21-
case _:
22-
raise ValueError("Usage: envwrap <config_name> [<app_name>] <func_name>")
16+
if len(args.args) == 2:
17+
app = ""
18+
elif len(args.args) == 3:
19+
app = args.args[1]
20+
else:
21+
raise ValueError("Usage: envwrap <config_name> [<app_name>] <func_name>")
2322
name = args.args[0]
2423
func = args.args[-1]
2524
print(f">>> @envwrap.envwrap('{name}', '{app}')", f">>> def {func}(...):", "... ...",

‎pyproject.toml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
requires = ["setuptools>=42", "setuptools-scm[toml]>=3.4"]
33
build-backend = "setuptools.build_meta"
44

5+
[tool.setuptools_scm]
6+
57
[tool.setuptools.packages.find]
68
exclude = ["tests"]
79

@@ -15,9 +17,9 @@ dynamic = ["version"]
1517
maintainers = [{name = "tqdm developers", email = "devs@tqdm.ml"}]
1618
description = "Override parameter defaults via environment variables & config files"
1719
readme = "README.md"
18-
requires-python = ">=3.7"
20+
requires-python = ">=3.8"
1921
keywords = ["config", "environment", "env", "defaults", "partial", "appdir", "appdirs", "platformdirs"]
20-
license = "MPL-2.0"
22+
license = {text = "MPL-2.0"}
2123
# Trove classifiers (https://pypi.org/pypi?%3Aaction=list_classifiers)
2224
classifiers = [
2325
"Development Status :: 5 - Production/Stable",

‎tests/test_envwrap.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ def test_conf(tmp_path):
4545
finally:
4646
os.chdir(pwd)
4747
cfg.unlink()
48-
tmp_path.rmdir()

0 commit comments

Comments
 (0)