summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/FUNDING.yml1
-rw-r--r--.github/workflows/main.yml13
-rw-r--r--.gitignore2
-rw-r--r--.pre-commit-config.yaml41
-rw-r--r--README.md9
-rw-r--r--azure-pipelines.yml19
-rw-r--r--cfgv.py9
-rw-r--r--debian/changelog32
-rw-r--r--debian/control2
-rw-r--r--debian/copyright2
-rwxr-xr-xdebian/rules4
-rw-r--r--setup.cfg10
-rw-r--r--setup.py2
-rw-r--r--tests/cfgv_test.py42
-rw-r--r--tox.ini4
15 files changed, 127 insertions, 65 deletions
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index eb54a96..0000000
--- a/.github/FUNDING.yml
+++ /dev/null
@@ -1 +0,0 @@
-github: asottile
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..f235f84
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,13 @@
+name: main
+
+on:
+ push:
+ branches: [main, test-me-*]
+ tags: '*'
+ pull_request:
+
+jobs:
+ main:
+ uses: asottile/workflows/.github/workflows/tox.yml@v1.5.0
+ with:
+ env: '["py38", "py39", "py310", "py311"]'
diff --git a/.gitignore b/.gitignore
index 4b9703a..ca1d90e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
*.egg-info
*.pyc
-/.pytest_cache
/.coverage
/.tox
-/venv*
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 35b521a..0c09017 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,38 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.0.1
+ rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- - id: check-docstring-first
- id: check-yaml
- id: debug-statements
+ - id: double-quote-string-fixer
- id: name-tests-test
- id: requirements-txt-fixer
-- repo: https://github.com/PyCQA/flake8
- rev: 3.9.2
- hooks:
- - id: flake8
-- repo: https://github.com/pre-commit/mirrors-autopep8
- rev: v1.5.7
+- repo: https://github.com/asottile/setup-cfg-fmt
+ rev: v2.4.0
hooks:
- - id: autopep8
-- repo: https://github.com/asottile/reorder_python_imports
- rev: v2.6.0
+ - id: setup-cfg-fmt
+- repo: https://github.com/asottile/reorder-python-imports
+ rev: v3.10.0
hooks:
- id: reorder-python-imports
- args: [--py3-plus]
+ args: [--py38-plus, --add-import, 'from __future__ import annotations']
+- repo: https://github.com/asottile/add-trailing-comma
+ rev: v3.0.1
+ hooks:
+ - id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
- rev: v2.24.0
+ rev: v3.10.1
hooks:
- id: pyupgrade
- args: [--py36-plus]
-- repo: https://github.com/asottile/add-trailing-comma
- rev: v2.1.0
+ args: [--py38-plus]
+- repo: https://github.com/pre-commit/mirrors-autopep8
+ rev: v2.0.2
hooks:
- - id: add-trailing-comma
- args: [--py36-plus]
-- repo: https://github.com/asottile/setup-cfg-fmt
- rev: v1.17.0
+ - id: autopep8
+- repo: https://github.com/PyCQA/flake8
+ rev: 6.1.0
hooks:
- - id: setup-cfg-fmt
+ - id: flake8
diff --git a/README.md b/README.md
index 3d9745a..77273e3 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
-[![Build Status](https://dev.azure.com/asottile/asottile/_apis/build/status/asottile.cfgv?branchName=master)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=24&branchName=master)
-[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/24/master.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=24&branchName=master)
-[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/cfgv/master.svg)](https://results.pre-commit.ci/latest/github/asottile/cfgv/master)
+[![build status](https://github.com/asottile/cfgv/actions/workflows/main.yml/badge.svg)](https://github.com/asottile/cfgv/actions/workflows/main.yml)
+[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/asottile/cfgv/main.svg)](https://results.pre-commit.ci/latest/github/asottile/cfgv/main)
cfgv
====
@@ -9,7 +8,9 @@ Validate configuration and produce human readable error messages.
## Installation
-`pip install cfgv`
+```bash
+pip install cfgv
+```
## Sample error messages
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
deleted file mode 100644
index 61a5a11..0000000
--- a/azure-pipelines.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-trigger:
- branches:
- include: [master, test-me-*]
- tags:
- include: ['*']
-
-resources:
- repositories:
- - repository: asottile
- type: github
- endpoint: github
- name: asottile/azure-pipeline-templates
- ref: refs/tags/v2.1.0
-
-jobs:
-- template: job--python-tox.yml@asottile
- parameters:
- toxenvs: [pypy3, py36, py37, py38]
- os: linux
diff --git a/cfgv.py b/cfgv.py
index 701d944..27ddd98 100644
--- a/cfgv.py
+++ b/cfgv.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import collections
import contextlib
import os.path
@@ -390,12 +392,15 @@ def load_from_filename(
schema,
load_strategy,
exc_tp=ValidationError,
+ *,
+ display_filename=None,
):
+ display_filename = display_filename or filename
with reraise_as(exc_tp):
if not os.path.isfile(filename):
- raise ValidationError(f'{filename} is not a file')
+ raise ValidationError(f'{display_filename} is not a file')
- with validate_context(f'File {filename}'):
+ with validate_context(f'File {display_filename}'):
try:
with open(filename, encoding='utf-8') as f:
contents = f.read()
diff --git a/debian/changelog b/debian/changelog
index 92e2b87..72b9204 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,35 @@
+cfgv (3.4.0-1) sid; urgency=medium
+
+ * Uploading to sid.
+ * Merging upstream version 3.4.0.
+
+ -- Daniel Baumann <daniel.baumann@progress-linux.org> Mon, 14 Aug 2023 12:19:05 +0200
+
+cfgv (3.3.1-3) sid; urgency=medium
+
+ * Uploading to sid.
+ * Manually removing some files that pybuild doesn't clean up during
+ build (Closes: #1043856).
+
+ -- Daniel Baumann <daniel.baumann@progress-linux.org> Mon, 14 Aug 2023 09:31:20 +0200
+
+cfgv (3.3.1-2) sid; urgency=medium
+
+ * Uploading to sid.
+ * Updating packaging copyright for 2023.
+ * Updating to standards version 4.6.2.
+
+ -- Daniel Baumann <daniel.baumann@progress-linux.org> Wed, 25 Jan 2023 09:14:08 +0100
+
+cfgv (3.3.1-1) sid; urgency=medium
+
+ * Uploading to sid.
+ * Merging upstream version 3.3.1.
+ * Using codename instead of suites in previous changelog.
+ * Updating to standards version 4.6.0.
+
+ -- Daniel Baumann <daniel.baumann@progress-linux.org> Mon, 06 Sep 2021 06:21:56 +0200
+
cfgv (3.3.0-2) sid; urgency=medium
* Uploading to sid.
diff --git a/debian/control b/debian/control
index 5786346..6d94ce6 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,7 @@ Build-Depends:
python3-all,
python3-setuptools,
Rules-Requires-Root: no
-Standards-Version: 4.6.0
+Standards-Version: 4.7.0
Homepage: https://github.com/asottile/cfgv
Vcs-Browser: https://git.progress-linux.org/users/daniel.baumann/debian/packages/cfgv
Vcs-Git: https://git.progress-linux.org/users/daniel.baumann/debian/packages/cfgv
diff --git a/debian/copyright b/debian/copyright
index 208479c..52a68d0 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -8,7 +8,7 @@ Copyright: 2018-2020 Anthony Sottile <asottile@umich.edu>
License: MIT
Files: debian/*
-Copyright: 2020-2021 Daniel Baumann <daniel.baumann@progress-linux.org>
+Copyright: 2020-2024 Daniel Baumann <daniel.baumann@progress-linux.org>
License: MIT
License: MIT
diff --git a/debian/rules b/debian/rules
index 276f941..eff1207 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,3 +4,7 @@ export PYBUILD_NAME=cfgv
%:
dh ${@} --buildsystem=pybuild
+
+execute_after_dh_auto_clean:
+ # help pybuild
+ rm -rf *.egg-info
diff --git a/setup.cfg b/setup.cfg
index 7437e61..08b0734 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = cfgv
-version = 3.3.1
+version = 3.4.0
description = Validate configuration and produce human readable error messages.
long_description = file: README.md
long_description_content_type = text/markdown
@@ -8,21 +8,17 @@ url = https://github.com/asottile/cfgv
author = Anthony Sottile
author_email = asottile@umich.edu
license = MIT
-license_file = LICENSE
+license_files = LICENSE
classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
- Programming Language :: Python :: 3.6
- Programming Language :: Python :: 3.7
- Programming Language :: Python :: 3.8
- Programming Language :: Python :: 3.9
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
[options]
py_modules = cfgv
-python_requires = >=3.6.1
+python_requires = >=3.8
[bdist_wheel]
universal = True
diff --git a/setup.py b/setup.py
index 8bf1ba9..3d93aef 100644
--- a/setup.py
+++ b/setup.py
@@ -1,2 +1,4 @@
+from __future__ import annotations
+
from setuptools import setup
setup()
diff --git a/tests/cfgv_test.py b/tests/cfgv_test.py
index 15bf581..3819ade 100644
--- a/tests/cfgv_test.py
+++ b/tests/cfgv_test.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import json
from unittest import mock
@@ -34,11 +36,12 @@ from cfgv import WarnAdditionalKeys
def _assert_exception_trace(e, trace):
- inner = e
- for ctx in trace[:-1]:
- assert inner.ctx == ctx
- inner = inner.error_msg
- assert inner.error_msg == trace[-1]
+ parts = []
+ while e.ctx is not None:
+ parts.append(e.ctx)
+ e = e.error_msg
+ parts.append(e.error_msg)
+ assert tuple(parts) == trace
def test_ValidationError_simple_str():
@@ -580,6 +583,35 @@ def test_load_from_filename_applies_defaults(tmpdir):
assert ret == {'key': False}
+def test_load_from_filename_custom_display_no_file(tmp_path):
+ with pytest.raises(ValidationError) as excinfo:
+ load_from_filename(
+ tmp_path.joinpath('cfg.json'),
+ map_required,
+ json.loads,
+ display_filename='cfg.json',
+ )
+ _assert_exception_trace(excinfo.value.args[0], ('cfg.json is not a file',))
+
+
+def test_load_from_filename_custom_display_error(tmp_path):
+ f = tmp_path.joinpath('cfg.json')
+ f.write_text('{}')
+ with pytest.raises(ValidationError) as excinfo:
+ load_from_filename(
+ f,
+ map_required,
+ json.loads,
+ display_filename='cfg.json',
+ )
+ expected = (
+ 'File cfg.json',
+ 'At foo(key=MISSING)',
+ 'Missing required key: key',
+ )
+ _assert_exception_trace(excinfo.value.args[0], expected)
+
+
conditional_recurse = Map(
'Map', None,
diff --git a/tox.ini b/tox.ini
index 3420602..5370c94 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,12 @@
[tox]
-envlist = py36,py37,pypy3,pre-commit
+envlist = py,pre-commit
[testenv]
deps = -rrequirements-dev.txt
commands =
coverage erase
coverage run -m pytest {posargs:tests}
- coverage report --fail-under 100
+ coverage report
[testenv:pre-commit]
skip_install = true