Skip to content

Commit 12ae1f5

Browse files
committed
feat: ValidationFailure is now ValidationError
- ref https://peps.python.org/pep-0008/#exception-names - import sorted using ruff - adds project URLs
1 parent 95ec1fa commit 12ae1f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+187
-175
lines changed

build_pkg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Remove Refs."""
22

33
# standard
4-
from subprocess import run
5-
64
# from shutil import rmtree
75
from pathlib import Path
6+
from subprocess import run # nosec
87

98
# local
109
from docs.gen_docs import generate_documentation
@@ -13,5 +12,8 @@
1312
project_dir = Path(__file__).parent
1413
generate_documentation(project_dir, only_rst_man=True)
1514
print()
16-
process = run(("poetry", "build"), capture_output=True)
15+
process = run(("poetry", "build"), capture_output=True) # nosec
1716
print(process.stderr.decode() + process.stdout.decode())
17+
18+
19+
# TODO: Address all '# nosec'

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66

77
# standard
8-
from importlib.metadata import metadata
98
from datetime import datetime
9+
from importlib.metadata import metadata
1010

1111
# -- Project information ----------------------------------------------------------
1212
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

docs/gen_docs.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# -*- coding: utf-8 -*-
33

44
# standard
5-
from shutil import rmtree, move, copy
6-
from ast import parse, ImportFrom
7-
from typing import List, Dict
5+
from ast import ImportFrom, parse
86
from os.path import getsize
9-
from subprocess import run
107
from pathlib import Path
8+
from shutil import copy, move, rmtree
9+
from subprocess import run # nosec
10+
from typing import Dict, List
1111

1212
__all__ = ("generate_documentation",)
1313

@@ -53,7 +53,7 @@ def _generate_reference(source: Path, destination: Path, ext: str):
5353
def _update_mkdocs_config(source: Path, destination: Path, nav_items: Dict[str, List[str]]):
5454
"""Temporary update to mkdocs config."""
5555
# external
56-
from yaml import safe_load, safe_dump
56+
from yaml import safe_dump, safe_load
5757

5858
copy(source, destination)
5959
with open(source, "rt") as mkf:
@@ -69,7 +69,7 @@ def _gen_md_docs(source: Path, refs_path: Path):
6969
# backup mkdocs config
7070
_update_mkdocs_config(source / "mkdocs.yaml", source / "mkdocs.bak.yaml", nav_items)
7171
# build mkdocs as subprocess
72-
mkdocs_build = run(("mkdocs", "build"), capture_output=True)
72+
mkdocs_build = run(("mkdocs", "build"), capture_output=True) # nosec
7373
print(mkdocs_build.stderr.decode() + mkdocs_build.stdout.decode())
7474
# restore mkdocs config
7575
move(str(source / "mkdocs.bak.yaml"), source / "mkdocs.yaml")
@@ -96,12 +96,12 @@ def _gen_rst_docs(source: Path, refs_path: Path, only_web: bool = False, only_ma
9696
rc = 0
9797
if not only_man:
9898
# build sphinx web pages as subprocess
99-
web_build = run(("sphinx-build", "docs", "docs/_build/web"), capture_output=True)
99+
web_build = run(("sphinx-build", "docs", "docs/_build/web"), capture_output=True) # nosec
100100
print(web_build.stderr.decode() + web_build.stdout.decode())
101101
rc = web_build.returncode
102102
if not only_web:
103103
# build sphinx man pages as subprocess
104-
man_build = run(
104+
man_build = run( # nosec
105105
("sphinx-build", "-b", "man", "docs", "docs/_build/man"), capture_output=True
106106
)
107107
print(man_build.stderr.decode() + man_build.stdout.decode())
@@ -155,3 +155,5 @@ def generate_documentation(
155155
# # for debugging
156156
)
157157
quit(rc)
158+
159+
# TODO: Address all '# nosec'

pyproject.toml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ name = "validators"
77
version = "0.21.1"
88
description = "Python Data Validation for Humans™"
99
authors = [{ name = "Konsta Vesterinen", email = "konsta@fastmonkeys.com" }]
10-
requires-python = ">=3.8"
11-
readme = "README.md"
1210
license = { text = "MIT" }
11+
readme = "README.md"
1312
keywords = ["validation", "validator", "python-validator"]
1413
classifiers = [
1514
"Development Status :: 4 - Beta",
@@ -26,12 +25,18 @@ classifiers = [
2625
"Programming Language :: Python :: Implementation :: CPython",
2726
"Topic :: Software Development :: Libraries :: Python Modules",
2827
]
28+
requires-python = ">=3.8"
29+
dependencies = []
2930

30-
####################
31-
# Dependencies #
32-
####################
31+
[project.urls]
32+
Homepage = "https://python-validators.github.io/validators"
33+
Documentation = "https://python-validators.github.io/validators"
34+
Repository = "https://github.com/python-validators/validators"
35+
Changelog = "https://github.com/python-validators/validators/blob/master/CHANGES.md"
3336

34-
dependencies = []
37+
###########################
38+
# Optional Dependencies #
39+
###########################
3540

3641
[project.optional-dependencies]
3742
docs-offline = ["myst-parser>=2.0.0", "pypandoc-binary>=1.11", "sphinx>=7.1.1"]
@@ -75,12 +80,15 @@ line-length = 100
7580
target-version = ["py38", "py39", "py310", "py311"]
7681

7782
[tool.pyright]
78-
include = ["src", "tests"]
83+
extraPaths = ["src"]
7984
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", ".venv/", "site/"]
8085
pythonVersion = "3.8"
8186
pythonPlatform = "All"
8287
typeCheckingMode = "strict"
8388

89+
[tool.pytest.ini_options]
90+
pythonpath = ["src"]
91+
8492
[tool.ruff]
8593
select = ["E", "F", "I", "N", "D"]
8694
line-length = 100
@@ -107,25 +115,33 @@ env_list = lint, type, format, sast, py{38,39,310,311}
107115
108116
[testenv:lint]
109117
description = ruff linter
110-
deps = ruff
118+
deps =
119+
ruff
111120
commands = ruff check .
112121
113122
[testenv:type]
114123
description = pyright type checker
115-
deps = pyright
124+
deps =
125+
pyright
126+
pyaml
127+
pypandoc-binary
128+
pytest
116129
commands = pyright .
117130
118131
[testenv:format]
119132
description = code formatter
120-
deps = black
133+
deps =
134+
black
121135
commands = black .
122136
123137
[testenv:sast]
124-
deps = bandit[toml]
138+
deps =
139+
bandit[toml]
125140
commands = bandit -c pyproject.toml -r .
126141
127142
[testenv]
128143
description = unit tests
129-
deps = pytest
144+
deps =
145+
pytest
130146
commands = pytest .
131147
"""

src/validators/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .mac_address import mac_address
2424
from .slug import slug
2525
from .url import url
26-
from .utils import validator, ValidationFailure
26+
from .utils import validator, ValidationError
2727
from .uuid import uuid
2828

2929
# from .crypto_addresses import eth_address
@@ -57,7 +57,7 @@
5757
"unionpay",
5858
"url",
5959
"uuid",
60-
"ValidationFailure",
60+
"ValidationError",
6161
"validator",
6262
"visa",
6363
# i18n

src/validators/between.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def between(
3434
>>> between(13.2, min_val=13, max_val=14)
3535
# Output: True
3636
>>> between(500, max_val=400)
37-
# Output: ValidationFailure(func=between, args=...)
37+
# Output: ValidationError(func=between, args=...)
3838
>>> between(
3939
... datetime(2000, 11, 11),
4040
... min_val=datetime(1999, 11, 11)
@@ -54,7 +54,7 @@ def between(
5454
Returns:
5555
(Literal[True]):
5656
If `value` is in between the given conditions.
57-
(ValidationFailure):
57+
(ValidationError):
5858
If `value` is not in between the given conditions.
5959
6060
Raises:

src/validators/btc_address.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def btc_address(value: str, /):
3636
>>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69')
3737
# Output: True
3838
>>> btc_address('1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2')
39-
# Output: ValidationFailure(func=btc_address, args=...)
39+
# Output: ValidationError(func=btc_address, args=...)
4040
4141
Args:
4242
value:
@@ -45,7 +45,7 @@ def btc_address(value: str, /):
4545
Returns:
4646
(Literal[True]):
4747
If `value` is a valid bitcoin address.
48-
(ValidationFailure):
48+
(ValidationError):
4949
If `value` is an invalid bitcoin address.
5050
5151
> *New in version 0.18.0*.

src/validators/card.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def card_number(value: str, /):
2020
>>> card_number('4242424242424242')
2121
# Output: True
2222
>>> card_number('4242424242424241')
23-
# Output: ValidationFailure(func=card_number, args={'value': '4242424242424241'})
23+
# Output: ValidationError(func=card_number, args={'value': '4242424242424241'})
2424
2525
Args:
2626
value:
@@ -29,7 +29,7 @@ def card_number(value: str, /):
2929
Returns:
3030
(Literal[True]):
3131
If `value` is a valid generic card number.
32-
(ValidationFailure):
32+
(ValidationError):
3333
If `value` is an invalid generic card number.
3434
3535
> *New in version 0.15.0*.
@@ -53,7 +53,7 @@ def visa(value: str, /):
5353
>>> visa('4242424242424242')
5454
# Output: True
5555
>>> visa('2223003122003222')
56-
# Output: ValidationFailure(func=visa, args={'value': '2223003122003222'})
56+
# Output: ValidationError(func=visa, args={'value': '2223003122003222'})
5757
5858
Args:
5959
value:
@@ -62,7 +62,7 @@ def visa(value: str, /):
6262
Returns:
6363
(Literal[True]):
6464
If `value` is a valid Visa card number.
65-
(ValidationFailure):
65+
(ValidationError):
6666
If `value` is an invalid Visa card number.
6767
6868
> *New in version 0.15.0*.
@@ -79,7 +79,7 @@ def mastercard(value: str, /):
7979
>>> mastercard('5555555555554444')
8080
# Output: True
8181
>>> mastercard('4242424242424242')
82-
# Output: ValidationFailure(func=mastercard, args={'value': '4242424242424242'})
82+
# Output: ValidationError(func=mastercard, args={'value': '4242424242424242'})
8383
8484
Args:
8585
value:
@@ -88,7 +88,7 @@ def mastercard(value: str, /):
8888
Returns:
8989
(Literal[True]):
9090
If `value` is a valid Mastercard card number.
91-
(ValidationFailure):
91+
(ValidationError):
9292
If `value` is an invalid Mastercard card number.
9393
9494
> *New in version 0.15.0*.
@@ -105,7 +105,7 @@ def amex(value: str, /):
105105
>>> amex('378282246310005')
106106
# Output: True
107107
>>> amex('4242424242424242')
108-
# Output: ValidationFailure(func=amex, args={'value': '4242424242424242'})
108+
# Output: ValidationError(func=amex, args={'value': '4242424242424242'})
109109
110110
Args:
111111
value:
@@ -114,7 +114,7 @@ def amex(value: str, /):
114114
Returns:
115115
(Literal[True]):
116116
If `value` is a valid American Express card number.
117-
(ValidationFailure):
117+
(ValidationError):
118118
If `value` is an invalid American Express card number.
119119
120120
> *New in version 0.15.0*.
@@ -131,7 +131,7 @@ def unionpay(value: str, /):
131131
>>> unionpay('6200000000000005')
132132
# Output: True
133133
>>> unionpay('4242424242424242')
134-
# Output: ValidationFailure(func=unionpay, args={'value': '4242424242424242'})
134+
# Output: ValidationError(func=unionpay, args={'value': '4242424242424242'})
135135
136136
Args:
137137
value:
@@ -140,7 +140,7 @@ def unionpay(value: str, /):
140140
Returns:
141141
(Literal[True]):
142142
If `value` is a valid UnionPay card number.
143-
(ValidationFailure):
143+
(ValidationError):
144144
If `value` is an invalid UnionPay card number.
145145
146146
> *New in version 0.15.0*.
@@ -157,7 +157,7 @@ def diners(value: str, /):
157157
>>> diners('3056930009020004')
158158
# Output: True
159159
>>> diners('4242424242424242')
160-
# Output: ValidationFailure(func=diners, args={'value': '4242424242424242'})
160+
# Output: ValidationError(func=diners, args={'value': '4242424242424242'})
161161
162162
Args:
163163
value:
@@ -166,7 +166,7 @@ def diners(value: str, /):
166166
Returns:
167167
(Literal[True]):
168168
If `value` is a valid Diners Club card number.
169-
(ValidationFailure):
169+
(ValidationError):
170170
If `value` is an invalid Diners Club card number.
171171
172172
> *New in version 0.15.0*.
@@ -183,7 +183,7 @@ def jcb(value: str, /):
183183
>>> jcb('3566002020360505')
184184
# Output: True
185185
>>> jcb('4242424242424242')
186-
# Output: ValidationFailure(func=jcb, args={'value': '4242424242424242'})
186+
# Output: ValidationError(func=jcb, args={'value': '4242424242424242'})
187187
188188
Args:
189189
value:
@@ -192,7 +192,7 @@ def jcb(value: str, /):
192192
Returns:
193193
(Literal[True]):
194194
If `value` is a valid JCB card number.
195-
(ValidationFailure):
195+
(ValidationError):
196196
If `value` is an invalid JCB card number.
197197
198198
> *New in version 0.15.0*.
@@ -209,7 +209,7 @@ def discover(value: str, /):
209209
>>> discover('6011111111111117')
210210
# Output: True
211211
>>> discover('4242424242424242')
212-
# Output: ValidationFailure(func=discover, args={'value': '4242424242424242'})
212+
# Output: ValidationError(func=discover, args={'value': '4242424242424242'})
213213
214214
Args:
215215
value:
@@ -218,7 +218,7 @@ def discover(value: str, /):
218218
Returns:
219219
(Literal[True]):
220220
If `value` is a valid Discover card number.
221-
(ValidationFailure):
221+
(ValidationError):
222222
If `value` is an invalid Discover card number.
223223
224224
> *New in version 0.15.0*.

src/validators/domain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def domain(value: str, /, *, rfc_1034: bool = False, rfc_2782: bool = False):
1616
>>> domain('example.com')
1717
# Output: True
1818
>>> domain('example.com/')
19-
# Output: ValidationFailure(func=domain, ...)
19+
# Output: ValidationError(func=domain, ...)
2020
>>> # Supports IDN domains as well::
2121
>>> domain('xn----gtbspbbmkef.xn--p1ai')
2222
# Output: True
@@ -35,7 +35,7 @@ def domain(value: str, /, *, rfc_1034: bool = False, rfc_2782: bool = False):
3535
Returns:
3636
(Literal[True]):
3737
If `value` is a valid domain name.
38-
(ValidationFailure):
38+
(ValidationError):
3939
If `value` is an invalid domain name.
4040
4141
Note:

0 commit comments

Comments
 (0)