typico 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- typico-0.0.1/.copier-answers.yml +21 -0
- typico-0.0.1/.github/FUNDING.yml +3 -0
- typico-0.0.1/.github/copilot-instructions.md +19 -0
- typico-0.0.1/.github/dependabot.yml +9 -0
- typico-0.0.1/.github/workflows/build.yml +88 -0
- typico-0.0.1/.github/workflows/documentation.yml +57 -0
- typico-0.0.1/.gitignore +32 -0
- typico-0.0.1/.pre-commit-config.yaml +48 -0
- typico-0.0.1/LICENSE +22 -0
- typico-0.0.1/PKG-INFO +81 -0
- typico-0.0.1/README.md +32 -0
- typico-0.0.1/docs/.empty +0 -0
- typico-0.0.1/duties.py +60 -0
- typico-0.0.1/mkdocs.yml +92 -0
- typico-0.0.1/overrides/_dummy.txt +1 -0
- typico-0.0.1/pyproject.toml +245 -0
- typico-0.0.1/src/typico/__init__.py +4 -0
- typico-0.0.1/src/typico/py.typed +0 -0
- typico-0.0.1/src/typico/pyfield.py +198 -0
- typico-0.0.1/src/typico/utils.py +55 -0
- typico-0.0.1/tests/__init__.py +3 -0
- typico-0.0.1/tests/conftest.py +1 -0
- typico-0.0.1/tests/test_pyfield.py +133 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changes here will be overwritten by Copier
|
|
2
|
+
_commit: v1.8.4
|
|
3
|
+
_src_path: .\copier-phil65\
|
|
4
|
+
author_email: philipptemminghoff@googlemail.com
|
|
5
|
+
author_fullname: Philipp Temminghoff
|
|
6
|
+
author_username: phil65
|
|
7
|
+
copyright_date: '2025'
|
|
8
|
+
copyright_holder: Philipp Temminghoff
|
|
9
|
+
copyright_holder_email: philipptemminghoff@googlemail.com
|
|
10
|
+
libraries_use_pydantic: false
|
|
11
|
+
libraries_use_qt: false
|
|
12
|
+
project_description: Type helpers and abstractions
|
|
13
|
+
project_name: Typico
|
|
14
|
+
python_minimum_version: '3.12'
|
|
15
|
+
python_package_command_line_name: typico
|
|
16
|
+
python_package_distribution_name: typico
|
|
17
|
+
python_package_import_name: typico
|
|
18
|
+
repository_name: typico
|
|
19
|
+
repository_namespace: phil65
|
|
20
|
+
repository_provider: github.com
|
|
21
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## Code style
|
|
2
|
+
|
|
3
|
+
You can assume Python 3.12.
|
|
4
|
+
Use newest language features if possible
|
|
5
|
+
Consider using pattern matching, walrus operators and other new syntax features.
|
|
6
|
+
Adhere to pep8.
|
|
7
|
+
|
|
8
|
+
## Tests
|
|
9
|
+
|
|
10
|
+
Tests are written using PyTest. Dont put tests into a class.
|
|
11
|
+
|
|
12
|
+
## DocStrings
|
|
13
|
+
|
|
14
|
+
DocStrings are written in google-style.
|
|
15
|
+
Dont add the types to the "Args" section.
|
|
16
|
+
Only add a Return section if a value is returned and the meaning of the returned value
|
|
17
|
+
is not obvious.
|
|
18
|
+
You can use markdown admonitions with python-markdown syntax if neccessary (!!! info, !!! note, !!! warning).
|
|
19
|
+
You can use markdown tables and markdown lists if neccessary.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ${{ matrix.os }}
|
|
8
|
+
continue-on-error: ${{ matrix.python_version == '3.14' }}
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
python_version: ["3.12", "3.13", "3.14"]
|
|
12
|
+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
|
|
13
|
+
steps:
|
|
14
|
+
- name: Check out repository
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Python ${{ matrix.python_version }}
|
|
18
|
+
uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python_version }}
|
|
21
|
+
allow-prereleases: true
|
|
22
|
+
|
|
23
|
+
- name: Install uv
|
|
24
|
+
uses: astral-sh/setup-uv@v5
|
|
25
|
+
with:
|
|
26
|
+
enable-cache: true
|
|
27
|
+
cache-dependency-glob: pyproject.toml
|
|
28
|
+
cache-suffix: py${{ matrix.python_version }}
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies (uv sync)
|
|
31
|
+
run: uv sync --all-extras --no-group docs
|
|
32
|
+
|
|
33
|
+
- name: Check for code issues (ruff check)
|
|
34
|
+
uses: astral-sh/ruff-action@v3
|
|
35
|
+
|
|
36
|
+
- name: Check code format (ruff format)
|
|
37
|
+
uses: astral-sh/ruff-action@v3
|
|
38
|
+
with:
|
|
39
|
+
args: "format --check"
|
|
40
|
+
|
|
41
|
+
- name: Static type checking (MyPy)
|
|
42
|
+
run: uv run --no-group docs mypy src/typico/
|
|
43
|
+
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: uv run --no-group docs pytest --cov-report=xml --cov=src/typico/ --cov-report=term-missing
|
|
46
|
+
|
|
47
|
+
- name: Upload test results to Codecov
|
|
48
|
+
uses: codecov/codecov-action@v5
|
|
49
|
+
with:
|
|
50
|
+
fail_ci_if_error: false
|
|
51
|
+
verbose: true
|
|
52
|
+
|
|
53
|
+
release:
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
needs: test
|
|
56
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
57
|
+
permissions:
|
|
58
|
+
# this permission is mandatory for trusted publishing
|
|
59
|
+
id-token: write
|
|
60
|
+
contents: write
|
|
61
|
+
steps:
|
|
62
|
+
- name: Check out repository
|
|
63
|
+
uses: actions/checkout@v4
|
|
64
|
+
|
|
65
|
+
- name: Set up Python
|
|
66
|
+
uses: actions/setup-python@v5
|
|
67
|
+
with:
|
|
68
|
+
python-version: "3.12"
|
|
69
|
+
|
|
70
|
+
- name: Install uv
|
|
71
|
+
uses: astral-sh/setup-uv@v5
|
|
72
|
+
with:
|
|
73
|
+
enable-cache: true
|
|
74
|
+
cache-dependency-glob: pyproject.toml
|
|
75
|
+
cache-suffix: py${{ matrix.python_version }}
|
|
76
|
+
|
|
77
|
+
- name: Build package
|
|
78
|
+
run: uv build
|
|
79
|
+
|
|
80
|
+
- name: Publish package distributions to PyPI
|
|
81
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
82
|
+
|
|
83
|
+
- name: Release package on GitHub
|
|
84
|
+
uses: ncipollo/release-action@v1
|
|
85
|
+
with:
|
|
86
|
+
body: ${{ github.event.head_commit.message }}
|
|
87
|
+
artifacts: dist/*.whl,dist/*.tar.gz
|
|
88
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: Build documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
pages: write
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
# Allow one concurrent deployment
|
|
15
|
+
concurrency:
|
|
16
|
+
group: "pages"
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
# Default to bash
|
|
20
|
+
defaults:
|
|
21
|
+
run:
|
|
22
|
+
shell: bash
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
build:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
fetch-depth: 0
|
|
32
|
+
- name: Set up Python
|
|
33
|
+
uses: actions/setup-python@v5
|
|
34
|
+
with:
|
|
35
|
+
python-version: "3.12"
|
|
36
|
+
- name: Install uv
|
|
37
|
+
uses: astral-sh/setup-uv@v5
|
|
38
|
+
- name: Install dependencies
|
|
39
|
+
run: |
|
|
40
|
+
uv sync --all-extras
|
|
41
|
+
- name: Build
|
|
42
|
+
run: uv run mknodes build
|
|
43
|
+
- name: Upload artifact
|
|
44
|
+
uses: actions/upload-pages-artifact@v3
|
|
45
|
+
with:
|
|
46
|
+
path: ./site
|
|
47
|
+
|
|
48
|
+
deploy:
|
|
49
|
+
environment:
|
|
50
|
+
name: github-pages
|
|
51
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
|
+
needs: build
|
|
54
|
+
steps:
|
|
55
|
+
- name: Deploy to GitHub Pages
|
|
56
|
+
id: deployment
|
|
57
|
+
uses: actions/deploy-pages@v4
|
typico-0.0.1/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
# Distribution / packaging
|
|
5
|
+
*.sublime-workspace
|
|
6
|
+
# Unit test / coverage reports
|
|
7
|
+
.coverage
|
|
8
|
+
coverage.xml
|
|
9
|
+
.cache
|
|
10
|
+
.hatch
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
junit.xml
|
|
13
|
+
# Jupyter Notebook
|
|
14
|
+
.ipynb_checkpoints
|
|
15
|
+
# pyenv
|
|
16
|
+
.python-version
|
|
17
|
+
# dotenv
|
|
18
|
+
.env
|
|
19
|
+
# virtualenv
|
|
20
|
+
.venv
|
|
21
|
+
# mkdocs documentation
|
|
22
|
+
/site
|
|
23
|
+
# mypy
|
|
24
|
+
.mypy_cache/
|
|
25
|
+
# .vscode
|
|
26
|
+
.vscode/
|
|
27
|
+
# OS files
|
|
28
|
+
.DS_Store
|
|
29
|
+
# uv
|
|
30
|
+
uv.lock
|
|
31
|
+
# DiskCache cache file
|
|
32
|
+
./model_cache
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.12
|
|
3
|
+
default_stages: [pre-commit]
|
|
4
|
+
repos:
|
|
5
|
+
- repo: local
|
|
6
|
+
hooks:
|
|
7
|
+
- id: pytest-check
|
|
8
|
+
name: pytest-check
|
|
9
|
+
entry: uv run pytest
|
|
10
|
+
language: system
|
|
11
|
+
# stages: [push]
|
|
12
|
+
types: [python]
|
|
13
|
+
pass_filenames: false
|
|
14
|
+
always_run: true
|
|
15
|
+
|
|
16
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
17
|
+
# https://pre-commit.com/hooks.html
|
|
18
|
+
rev: v5.0.0
|
|
19
|
+
hooks:
|
|
20
|
+
- id: check-added-large-files
|
|
21
|
+
- id: check-case-conflict
|
|
22
|
+
- id: check-merge-conflict
|
|
23
|
+
- id: check-toml
|
|
24
|
+
- id: check-json
|
|
25
|
+
- id: check-xml
|
|
26
|
+
- id: check-yaml
|
|
27
|
+
args: [--allow-multiple-documents, --unsafe]
|
|
28
|
+
- id: debug-statements
|
|
29
|
+
- id: detect-private-key
|
|
30
|
+
|
|
31
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
32
|
+
rev: v1.15.0
|
|
33
|
+
hooks:
|
|
34
|
+
- id: mypy
|
|
35
|
+
additional_dependencies: [orjson]
|
|
36
|
+
|
|
37
|
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
38
|
+
rev: v0.11.2
|
|
39
|
+
hooks:
|
|
40
|
+
- id: ruff
|
|
41
|
+
- id: ruff-format
|
|
42
|
+
|
|
43
|
+
- repo: https://github.com/commitizen-tools/commitizen
|
|
44
|
+
rev: v4.4.1
|
|
45
|
+
hooks:
|
|
46
|
+
- id: commitizen
|
|
47
|
+
stages: [commit-msg]
|
|
48
|
+
additional_dependencies: [typing-extensions]
|
typico-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Philipp Temminghoff
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
typico-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typico
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Type helpers and abstractions
|
|
5
|
+
Project-URL: Documentation, https://phil65.github.io/typico/
|
|
6
|
+
Project-URL: Source, https://github.com/phil65/typico
|
|
7
|
+
Project-URL: Issues, https://github.com/phil65/typico/issues
|
|
8
|
+
Project-URL: Discussions, https://github.com/phil65/typico/discussions
|
|
9
|
+
Project-URL: Code coverage, https://app.codecov.io/gh/phil65/typico
|
|
10
|
+
Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2024, Philipp Temminghoff
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
+
Classifier: Topic :: Documentation
|
|
43
|
+
Classifier: Topic :: Software Development
|
|
44
|
+
Classifier: Topic :: Utilities
|
|
45
|
+
Classifier: Typing :: Typed
|
|
46
|
+
Requires-Python: >=3.12
|
|
47
|
+
Requires-Dist: typing-inspection>=0.4.0
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# Typico
|
|
51
|
+
|
|
52
|
+
[](https://pypi.org/project/typico/)
|
|
53
|
+
[](https://pypi.org/project/typico/)
|
|
54
|
+
[](https://pypi.org/project/typico/)
|
|
55
|
+
[](https://pypi.org/project/typico/)
|
|
56
|
+
[](https://pypi.org/project/typico/)
|
|
57
|
+
[](https://pypi.org/project/typico/)
|
|
58
|
+
[](https://pypi.org/project/typico/)
|
|
59
|
+
[](https://pypi.org/project/typico/)
|
|
60
|
+
[](https://pypi.org/project/typico/)
|
|
61
|
+
[](https://github.com/phil65/typico/releases)
|
|
62
|
+
[](https://github.com/phil65/typico/graphs/contributors)
|
|
63
|
+
[](https://github.com/phil65/typico/discussions)
|
|
64
|
+
[](https://github.com/phil65/typico/forks)
|
|
65
|
+
[](https://github.com/phil65/typico/issues)
|
|
66
|
+
[](https://github.com/phil65/typico/pulls)
|
|
67
|
+
[](https://github.com/phil65/typico/watchers)
|
|
68
|
+
[](https://github.com/phil65/typico/stars)
|
|
69
|
+
[](https://github.com/phil65/typico)
|
|
70
|
+
[](https://github.com/phil65/typico/commits)
|
|
71
|
+
[](https://github.com/phil65/typico/releases)
|
|
72
|
+
[](https://github.com/phil65/typico)
|
|
73
|
+
[](https://github.com/phil65/typico)
|
|
74
|
+
[](https://github.com/phil65/typico)
|
|
75
|
+
[](https://github.com/phil65/typico)
|
|
76
|
+
[](https://codecov.io/gh/phil65/typico/)
|
|
77
|
+
[](https://github.com/psf/black)
|
|
78
|
+
[](https://pyup.io/repos/github/phil65/typico/)
|
|
79
|
+
|
|
80
|
+
[Read the documentation!](https://phil65.github.io/typico/)
|
|
81
|
+
|
typico-0.0.1/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Typico
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/typico/)
|
|
4
|
+
[](https://pypi.org/project/typico/)
|
|
5
|
+
[](https://pypi.org/project/typico/)
|
|
6
|
+
[](https://pypi.org/project/typico/)
|
|
7
|
+
[](https://pypi.org/project/typico/)
|
|
8
|
+
[](https://pypi.org/project/typico/)
|
|
9
|
+
[](https://pypi.org/project/typico/)
|
|
10
|
+
[](https://pypi.org/project/typico/)
|
|
11
|
+
[](https://pypi.org/project/typico/)
|
|
12
|
+
[](https://github.com/phil65/typico/releases)
|
|
13
|
+
[](https://github.com/phil65/typico/graphs/contributors)
|
|
14
|
+
[](https://github.com/phil65/typico/discussions)
|
|
15
|
+
[](https://github.com/phil65/typico/forks)
|
|
16
|
+
[](https://github.com/phil65/typico/issues)
|
|
17
|
+
[](https://github.com/phil65/typico/pulls)
|
|
18
|
+
[](https://github.com/phil65/typico/watchers)
|
|
19
|
+
[](https://github.com/phil65/typico/stars)
|
|
20
|
+
[](https://github.com/phil65/typico)
|
|
21
|
+
[](https://github.com/phil65/typico/commits)
|
|
22
|
+
[](https://github.com/phil65/typico/releases)
|
|
23
|
+
[](https://github.com/phil65/typico)
|
|
24
|
+
[](https://github.com/phil65/typico)
|
|
25
|
+
[](https://github.com/phil65/typico)
|
|
26
|
+
[](https://github.com/phil65/typico)
|
|
27
|
+
[](https://codecov.io/gh/phil65/typico/)
|
|
28
|
+
[](https://github.com/psf/black)
|
|
29
|
+
[](https://pyup.io/repos/github/phil65/typico/)
|
|
30
|
+
|
|
31
|
+
[Read the documentation!](https://phil65.github.io/typico/)
|
|
32
|
+
|
typico-0.0.1/docs/.empty
ADDED
|
File without changes
|
typico-0.0.1/duties.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from duty import duty
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@duty(capture=False)
|
|
7
|
+
def build(ctx, *args: str):
|
|
8
|
+
"""Build a MkNodes page."""
|
|
9
|
+
args_str = " " + " ".join(args) if args else ""
|
|
10
|
+
ctx.run(f"uv run mknodes build{args_str}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@duty(capture=False)
|
|
14
|
+
def serve(ctx, *args: str):
|
|
15
|
+
"""Serve a MkNodes page."""
|
|
16
|
+
args_str = " " + " ".join(args) if args else ""
|
|
17
|
+
ctx.run(f"uv run mknodes serve{args_str}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@duty(capture=False)
|
|
21
|
+
def test(ctx, *args: str):
|
|
22
|
+
"""Serve a MkNodes page."""
|
|
23
|
+
args_str = " " + " ".join(args) if args else ""
|
|
24
|
+
ctx.run(f"uv run pytest{args_str}")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@duty(capture=False)
|
|
28
|
+
def clean(ctx):
|
|
29
|
+
"""Clean all files from the Git directory except checked-in files."""
|
|
30
|
+
ctx.run("git clean -dfX")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@duty(capture=False)
|
|
34
|
+
def update(ctx):
|
|
35
|
+
"""Update all environment packages using pip directly."""
|
|
36
|
+
ctx.run("uv lock --upgrade")
|
|
37
|
+
ctx.run("uv sync --all-extras")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@duty(capture=False)
|
|
41
|
+
def lint(ctx):
|
|
42
|
+
"""Lint the code and fix issues if possible."""
|
|
43
|
+
ctx.run("uv run ruff check --fix --unsafe-fixes .")
|
|
44
|
+
ctx.run("uv run ruff format .")
|
|
45
|
+
ctx.run("uv run mypy src/typico/")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@duty(capture=False)
|
|
49
|
+
def lint_check(ctx):
|
|
50
|
+
"""Lint the code."""
|
|
51
|
+
ctx.run("uv run ruff check .")
|
|
52
|
+
ctx.run("uv run ruff format --check .")
|
|
53
|
+
ctx.run("uv run mypy src/typico/")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@duty(capture=False)
|
|
57
|
+
def version(ctx, *args: str):
|
|
58
|
+
"""Bump package version."""
|
|
59
|
+
args_str = " " + " ".join(args) if args else ""
|
|
60
|
+
ctx.run(f"hatch version{args_str}")
|
typico-0.0.1/mkdocs.yml
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
site_name: "Typico"
|
|
2
|
+
site_description: "Type helpers and abstractions"
|
|
3
|
+
repo_url: "https://github.com/phil65/typico/"
|
|
4
|
+
site_url: https://phil65.github.io/typico/
|
|
5
|
+
site_author: "Philipp Temminghoff"
|
|
6
|
+
copyright: Copyright © 2025 Philipp Temminghoff
|
|
7
|
+
|
|
8
|
+
theme:
|
|
9
|
+
name: material
|
|
10
|
+
custom_dir: overrides
|
|
11
|
+
icon:
|
|
12
|
+
logo: material/graph-outline
|
|
13
|
+
palette:
|
|
14
|
+
# Palette toggle for automatic mode
|
|
15
|
+
- media: "(prefers-color-scheme)"
|
|
16
|
+
toggle:
|
|
17
|
+
icon: material/brightness-auto
|
|
18
|
+
name: Switch to light mode
|
|
19
|
+
|
|
20
|
+
# Palette toggle for light mode
|
|
21
|
+
- media: "(prefers-color-scheme: light)"
|
|
22
|
+
scheme: default
|
|
23
|
+
primary: red
|
|
24
|
+
toggle:
|
|
25
|
+
icon: material/brightness-7
|
|
26
|
+
name: Switch to dark mode
|
|
27
|
+
|
|
28
|
+
# Palette toggle for dark mode
|
|
29
|
+
- media: "(prefers-color-scheme: dark)"
|
|
30
|
+
scheme: slate
|
|
31
|
+
primary: red
|
|
32
|
+
toggle:
|
|
33
|
+
icon: material/brightness-4
|
|
34
|
+
name: Switch to system preference
|
|
35
|
+
features:
|
|
36
|
+
- announce.dismiss
|
|
37
|
+
- content.action.edit
|
|
38
|
+
- content.code.copy
|
|
39
|
+
- content.code.select
|
|
40
|
+
- content.code.annotate
|
|
41
|
+
- content.tooltips
|
|
42
|
+
# - content.tabs.link
|
|
43
|
+
- navigation.tracking # update URL based on current item in TOC
|
|
44
|
+
- navigation.path # shows breadcrumbs
|
|
45
|
+
- navigation.tabs # make top level tabs
|
|
46
|
+
- navigation.indexes # documents can be directly attached to sections (overview pages)
|
|
47
|
+
- navigation.footer # next/previous page buttons in footer
|
|
48
|
+
- navigation.top # adds back-to-top button
|
|
49
|
+
# - navigation.sections # top-level sections are rendered as groups
|
|
50
|
+
# - navigation.expand # expand all subsections in left sidebar by default
|
|
51
|
+
- toc.follow # makes toc follow scrolling
|
|
52
|
+
# - toc.integrate # integrates toc into left menu
|
|
53
|
+
- search.highlight
|
|
54
|
+
- search.suggest
|
|
55
|
+
# - search.share
|
|
56
|
+
|
|
57
|
+
plugins:
|
|
58
|
+
- search
|
|
59
|
+
- autorefs
|
|
60
|
+
- mknodes
|
|
61
|
+
- mkdocstrings:
|
|
62
|
+
default_handler: python
|
|
63
|
+
handlers:
|
|
64
|
+
python:
|
|
65
|
+
import:
|
|
66
|
+
- url: https://docs.python.org/3/objects.inv
|
|
67
|
+
domains: [std, py]
|
|
68
|
+
options:
|
|
69
|
+
# https://mkdocstrings.github.io/python/usage/
|
|
70
|
+
enable_inventory: !ENV [CI, false]
|
|
71
|
+
show_signature_annotations: true
|
|
72
|
+
show_symbol_type_toc: true
|
|
73
|
+
show_symbol_type_heading: true
|
|
74
|
+
show_root_toc_entry: false
|
|
75
|
+
# merge_init_into_class: true
|
|
76
|
+
ignore_init_summary: true
|
|
77
|
+
inherited_members: false
|
|
78
|
+
signature_crossrefs: true
|
|
79
|
+
separate_signature: true
|
|
80
|
+
line_length: 90
|
|
81
|
+
markdown_extensions:
|
|
82
|
+
- attr_list
|
|
83
|
+
- pymdownx.emoji
|
|
84
|
+
- toc:
|
|
85
|
+
permalink: true
|
|
86
|
+
|
|
87
|
+
extra:
|
|
88
|
+
social:
|
|
89
|
+
- icon: fontawesome/brands/github
|
|
90
|
+
link: https://github.com/phil65
|
|
91
|
+
- icon: fontawesome/brands/python
|
|
92
|
+
link: https://pypi.org/project/typico/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
File exists to make sure that folder exists for git
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
[tool.hatch.version]
|
|
2
|
+
source = "regex_commit"
|
|
3
|
+
commit_extra_args = ["-e"]
|
|
4
|
+
path = "src/typico/__init__.py"
|
|
5
|
+
|
|
6
|
+
[build-system]
|
|
7
|
+
requires = ["hatchling", "hatch-regex-commit"]
|
|
8
|
+
build-backend = "hatchling.build"
|
|
9
|
+
|
|
10
|
+
[project]
|
|
11
|
+
name = "typico"
|
|
12
|
+
description = "Type helpers and abstractions"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Philipp Temminghoff", email = "philipptemminghoff@googlemail.com" },
|
|
15
|
+
]
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
dynamic = ["version"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Documentation",
|
|
28
|
+
"Topic :: Software Development",
|
|
29
|
+
"Topic :: Utilities",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
|
|
32
|
+
]
|
|
33
|
+
keywords = []
|
|
34
|
+
requires-python = ">=3.12"
|
|
35
|
+
license = { file = "LICENSE" }
|
|
36
|
+
dependencies = [
|
|
37
|
+
# Only add below (Copier)
|
|
38
|
+
"typing-inspection>=0.4.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[tool.uv]
|
|
42
|
+
default-groups = ["dev", "lint", "docs"]
|
|
43
|
+
|
|
44
|
+
[dependency-groups]
|
|
45
|
+
dev = [
|
|
46
|
+
"pytest",
|
|
47
|
+
"pytest-cov",
|
|
48
|
+
"pyreadline3",
|
|
49
|
+
"devtools",
|
|
50
|
+
# Only add below (Copier)
|
|
51
|
+
]
|
|
52
|
+
benchmark = ["pyinstrument"]
|
|
53
|
+
lint = [
|
|
54
|
+
"ruff",
|
|
55
|
+
"mypy[faster-cache]; python_version < '3.14'",
|
|
56
|
+
"mypy; python_version >= '3.14'",
|
|
57
|
+
# Only add below (Copier)
|
|
58
|
+
]
|
|
59
|
+
docs = [
|
|
60
|
+
"mkdocs-mknodes",
|
|
61
|
+
"mkdocs-material",
|
|
62
|
+
# Only add below (Copier)
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[project.urls]
|
|
66
|
+
Documentation = "https://phil65.github.io/typico/"
|
|
67
|
+
Source = "https://github.com/phil65/typico"
|
|
68
|
+
Issues = "https://github.com/phil65/typico/issues"
|
|
69
|
+
Discussions = "https://github.com/phil65/typico/discussions"
|
|
70
|
+
"Code coverage" = "https://app.codecov.io/gh/phil65/typico"
|
|
71
|
+
|
|
72
|
+
[tool.pytest.ini_options]
|
|
73
|
+
testpaths = "tests/"
|
|
74
|
+
log_cli = true
|
|
75
|
+
log_format = "%(asctime)s %(levelname)s %(message)s"
|
|
76
|
+
log_date_format = "%Y-%m-%d %H:%M:%S"
|
|
77
|
+
|
|
78
|
+
[tool.coverage.report]
|
|
79
|
+
exclude_lines = [
|
|
80
|
+
"pragma: no cover",
|
|
81
|
+
"if TYPE_CHECKING:",
|
|
82
|
+
"@overload",
|
|
83
|
+
"except ImportError",
|
|
84
|
+
'if __name__ == "__main__":',
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[tool.mypy]
|
|
88
|
+
python_version = "3.12"
|
|
89
|
+
disable_error_code = ["misc", "import"]
|
|
90
|
+
pretty = true
|
|
91
|
+
check_untyped_defs = true
|
|
92
|
+
exclude = ['venv/', '.venv/', 'tests/']
|
|
93
|
+
plugins = []
|
|
94
|
+
|
|
95
|
+
[tool.ruff]
|
|
96
|
+
line-length = 90
|
|
97
|
+
extend-exclude = ['docs']
|
|
98
|
+
target-version = "py312"
|
|
99
|
+
|
|
100
|
+
[tool.ruff.lint]
|
|
101
|
+
select = [
|
|
102
|
+
"A", # Flake8-builtins
|
|
103
|
+
# "ANN", # Flake8-Annotations
|
|
104
|
+
# "ASYNC", # Flake8-Async
|
|
105
|
+
# "ARG", # # Flake8-Unused-Arguments
|
|
106
|
+
"B", # flake8-bugbear
|
|
107
|
+
"BLE", # Flake8-blind-except
|
|
108
|
+
"C",
|
|
109
|
+
"C4", # flake8-comprehensions
|
|
110
|
+
# "C90", # MCCabe
|
|
111
|
+
"COM", # Flake8-commas
|
|
112
|
+
# "CPY", # Copyright-related rules
|
|
113
|
+
"D", # PyDocStyle
|
|
114
|
+
# "DTZ", # Flake8- Datetimez
|
|
115
|
+
"E", # PyCodeStyle Error
|
|
116
|
+
"EM", # flake8-errmsg
|
|
117
|
+
# "ERA", # Eradicate
|
|
118
|
+
"EXE", # flake8-executable
|
|
119
|
+
"F", # PyFlakes
|
|
120
|
+
"FA", # flake8-future-annotations
|
|
121
|
+
# "FBT", # flake8-boolean-trap
|
|
122
|
+
# "FIX", # flake8-fixme
|
|
123
|
+
"FLY", # flynt
|
|
124
|
+
"G", # flake8-logging-format
|
|
125
|
+
"I", # ISort
|
|
126
|
+
"ICN", # Flake8-import-conventions
|
|
127
|
+
"INP", # flake8-no-pep420
|
|
128
|
+
"INT", # flake8-gettext
|
|
129
|
+
"ISC", # flake8-implicit-str-concat
|
|
130
|
+
"N", # pep8-naming
|
|
131
|
+
# "NPY", # numpy-specific rules
|
|
132
|
+
# "PD", # pandas-vet
|
|
133
|
+
"PERF", # perflint
|
|
134
|
+
# "PGH", # pygrep-hooks
|
|
135
|
+
"PIE", # flake8-pie
|
|
136
|
+
"PLE", # PyLint Error
|
|
137
|
+
"PLC", # PyLint convention
|
|
138
|
+
# "PLW", # PyLint Warning
|
|
139
|
+
"PLR", # PyLint refactor
|
|
140
|
+
"PT", # flake8-pytest-style
|
|
141
|
+
"PTH", # flake8-use-pathlib
|
|
142
|
+
"PYI", # flake8-pyi
|
|
143
|
+
"Q", # flake8-quotes
|
|
144
|
+
"RET", # flake8-return
|
|
145
|
+
"RSE", # flake8-raise
|
|
146
|
+
"RUF", # ruff-specific rules
|
|
147
|
+
# "S", # flake8-bandit
|
|
148
|
+
"SIM", # flake8-simplify
|
|
149
|
+
"SLF", # flake8-self
|
|
150
|
+
"SLOT", # flake8-slots
|
|
151
|
+
# "T",
|
|
152
|
+
# "TD", # flake8-todos
|
|
153
|
+
"T10", # flake8-debugger
|
|
154
|
+
# "T20", # flake8-print
|
|
155
|
+
"TC", # flake8-type-checking
|
|
156
|
+
"TID", # flake8-tidy-imports
|
|
157
|
+
"TRY", # tryceratops
|
|
158
|
+
"UP", # PyUpgrade
|
|
159
|
+
"W", # PyCodeStyle warning
|
|
160
|
+
"YTT", # flake8-2020
|
|
161
|
+
]
|
|
162
|
+
ignore = [
|
|
163
|
+
"C408", # Unnecessary {obj_type} call (rewrite as a literal)
|
|
164
|
+
"B905", # zip() without an explicit strict= parameter
|
|
165
|
+
"C901", # {name} is too complex ({complexity} > {max_complexity})
|
|
166
|
+
"COM812",
|
|
167
|
+
# "CPY001", # Missing copyright notice at top of file
|
|
168
|
+
"D100", # Missing docstring in public module
|
|
169
|
+
"D101", # Missing docstring in public class
|
|
170
|
+
"D102", # Missing docstring in public method
|
|
171
|
+
"D103", # Missing docstring in public function
|
|
172
|
+
"D104", # Missing docstring in public package
|
|
173
|
+
"D105", # Missing docstring in magic method
|
|
174
|
+
"D106", # Missing docstring in public nested class
|
|
175
|
+
"D107", # Missing docstring in __init__
|
|
176
|
+
"D203", # 1 blank line required before class docstring
|
|
177
|
+
"D204", # 1 blank line required after class docstring
|
|
178
|
+
"D213", # Multi-line docstring summary should start at the second line
|
|
179
|
+
"D215", # Section underline is over-indented ("{name}")
|
|
180
|
+
"D400", # First line should end with a period
|
|
181
|
+
"D401", # First line of docstring should be in imperative mood: "{first_line}"
|
|
182
|
+
"D404", # First word of the docstring should not be "This"
|
|
183
|
+
"D406", # Section name should end with a newline ("{name}")
|
|
184
|
+
"D407", # Missing dashed underline after section ("{name}")
|
|
185
|
+
"D408", # Section underline should be in the line following the section's name ("{name}")
|
|
186
|
+
"D409", # Section underline should match the length of its name ("{name}")
|
|
187
|
+
"D413", # Missing blank line after last section ("{name}")
|
|
188
|
+
"ISC001",
|
|
189
|
+
"PLR0912", # Too many branches
|
|
190
|
+
"PLR0913", # Too many arguments to function call
|
|
191
|
+
"PLR0915", # Too many statements
|
|
192
|
+
# "PLR2004", # Magic values instead of named consts
|
|
193
|
+
"SLF001", # Private member accessed
|
|
194
|
+
"TRY003", # Avoid specifying long messages outside the exception class
|
|
195
|
+
"TC006", # runtime-cast-value
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
[tool.ruff.lint.flake8-quotes]
|
|
199
|
+
docstring-quotes = "double"
|
|
200
|
+
|
|
201
|
+
[tool.ruff.format]
|
|
202
|
+
# Enable preview style formatting.
|
|
203
|
+
preview = true
|
|
204
|
+
|
|
205
|
+
[tool.ruff.lint.isort]
|
|
206
|
+
lines-after-imports = 2
|
|
207
|
+
# lines-between-types = 1
|
|
208
|
+
# atomic = true
|
|
209
|
+
force-sort-within-sections = true
|
|
210
|
+
combine-as-imports = true
|
|
211
|
+
|
|
212
|
+
[tool.ruff.lint.per-file-ignores]
|
|
213
|
+
"__init__.py" = ["E402", "I001"]
|
|
214
|
+
"scripts/*" = ["INP001"]
|
|
215
|
+
|
|
216
|
+
[tool.pyright]
|
|
217
|
+
venvPath = "."
|
|
218
|
+
venv = ".venv"
|
|
219
|
+
pythonVersion = "3.12"
|
|
220
|
+
pythonPlatform = "All"
|
|
221
|
+
typeCheckingMode = "basic"
|
|
222
|
+
deprecateTypingAliases = true
|
|
223
|
+
reportMissingTypeStubs = false
|
|
224
|
+
reportUnusedCallResult = false
|
|
225
|
+
reportUnknownVariableType = false
|
|
226
|
+
reportAny = false
|
|
227
|
+
reportImplicitOverride = false
|
|
228
|
+
reportUnusedFunction = false
|
|
229
|
+
reportImplicitStringConcatenation = false
|
|
230
|
+
reportIgnoreCommentWithoutRule = false
|
|
231
|
+
reportUnannotatedClassAttribute = false
|
|
232
|
+
reportSelfClsParameterName = false
|
|
233
|
+
reportPrivateImportUsage = false
|
|
234
|
+
|
|
235
|
+
[tool.mknodes]
|
|
236
|
+
allowed-commit-types = [
|
|
237
|
+
"fix",
|
|
238
|
+
"feat",
|
|
239
|
+
"refactor",
|
|
240
|
+
"docs",
|
|
241
|
+
"test",
|
|
242
|
+
"build",
|
|
243
|
+
"chore",
|
|
244
|
+
]
|
|
245
|
+
docstring-style = "google"
|
|
File without changes
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import TYPE_CHECKING, Annotated, Any, TypeVar, get_args, get_origin
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
from pydantic.fields import FieldInfo
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
T = TypeVar("T", bound="BaseModel")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class ValidationConstraints:
|
|
17
|
+
"""Encapsulation of field validation constraints."""
|
|
18
|
+
|
|
19
|
+
min_value: float | None = None
|
|
20
|
+
"""Minimum allowed value for numeric fields."""
|
|
21
|
+
|
|
22
|
+
max_value: float | None = None
|
|
23
|
+
"""Maximum allowed value for numeric fields."""
|
|
24
|
+
|
|
25
|
+
exclusive_min: bool = False
|
|
26
|
+
"""If True, the minimum value is exclusive (value must be greater than min_value)."""
|
|
27
|
+
|
|
28
|
+
exclusive_max: bool = False
|
|
29
|
+
"""If True, the maximum value is exclusive (value must be less than max_value)."""
|
|
30
|
+
|
|
31
|
+
multiple_of: float | None = None
|
|
32
|
+
"""If set, the value must be a multiple of this number."""
|
|
33
|
+
|
|
34
|
+
min_length: int | None = None
|
|
35
|
+
"""Minimum length for strings or collections."""
|
|
36
|
+
|
|
37
|
+
max_length: int | None = None
|
|
38
|
+
"""Maximum length for strings or collections."""
|
|
39
|
+
|
|
40
|
+
pattern: str | None = None
|
|
41
|
+
"""Regular expression pattern that strings must match."""
|
|
42
|
+
|
|
43
|
+
min_items: int | None = None
|
|
44
|
+
"""Minimum number of items for array/list types."""
|
|
45
|
+
|
|
46
|
+
max_items: int | None = None
|
|
47
|
+
"""Maximum number of items for array/list types."""
|
|
48
|
+
|
|
49
|
+
allowed_values: list[Any] | None = None
|
|
50
|
+
"""List of allowed values (for enums, literals, or constrained types)."""
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def from_pydantic_field(cls, field_info: FieldInfo) -> ValidationConstraints:
|
|
54
|
+
"""Extract constraints directly from Pydantic field info."""
|
|
55
|
+
constraints: dict[str, Any] = {}
|
|
56
|
+
|
|
57
|
+
from annotated_types import Ge, Gt, Le, Lt, MaxLen, MinLen, MultipleOf
|
|
58
|
+
|
|
59
|
+
for meta in field_info.metadata:
|
|
60
|
+
match meta:
|
|
61
|
+
case Gt():
|
|
62
|
+
constraints["min_value"] = meta.gt
|
|
63
|
+
constraints["exclusive_min"] = True
|
|
64
|
+
case Ge():
|
|
65
|
+
constraints["min_value"] = meta.ge
|
|
66
|
+
case Lt():
|
|
67
|
+
constraints["max_value"] = meta.lt
|
|
68
|
+
constraints["exclusive_max"] = True
|
|
69
|
+
case Le():
|
|
70
|
+
constraints["max_value"] = meta.le
|
|
71
|
+
case MultipleOf():
|
|
72
|
+
constraints["multiple_of"] = meta.multiple_of
|
|
73
|
+
case MinLen():
|
|
74
|
+
constraints["min_length"] = meta.min_length
|
|
75
|
+
case MaxLen():
|
|
76
|
+
constraints["max_length"] = meta.max_length
|
|
77
|
+
# Easy to extend with more cases as needed
|
|
78
|
+
|
|
79
|
+
return cls(**constraints)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass
|
|
83
|
+
class PyField[T]:
|
|
84
|
+
"""Generic representation of a field focused on type semantics."""
|
|
85
|
+
|
|
86
|
+
name: str
|
|
87
|
+
"""The name of the field in the model."""
|
|
88
|
+
|
|
89
|
+
raw_type: Any
|
|
90
|
+
"""The Python type annotation of the field."""
|
|
91
|
+
|
|
92
|
+
parent_model: type[T] | None = None
|
|
93
|
+
"""The parent model class containing this field."""
|
|
94
|
+
|
|
95
|
+
field_type: str | None = None
|
|
96
|
+
"""The field type, based on Annoated convention."""
|
|
97
|
+
|
|
98
|
+
title: str | None = None
|
|
99
|
+
"""Display title for the field."""
|
|
100
|
+
|
|
101
|
+
description: str | None = None
|
|
102
|
+
"""Detailed description of the field."""
|
|
103
|
+
|
|
104
|
+
placeholder: str | None = None
|
|
105
|
+
"""Placeholder text to show when the field is empty."""
|
|
106
|
+
|
|
107
|
+
examples: list[Any] | None = None
|
|
108
|
+
"""Example values for the field."""
|
|
109
|
+
|
|
110
|
+
hidden: bool = False
|
|
111
|
+
"""Whether the field should be hidden from serialization or presentation."""
|
|
112
|
+
|
|
113
|
+
readonly: bool = False
|
|
114
|
+
"""Whether the field is immutable after initialization."""
|
|
115
|
+
|
|
116
|
+
deprecated: bool = False
|
|
117
|
+
"""Whether the field is marked as deprecated."""
|
|
118
|
+
|
|
119
|
+
is_required: bool = True
|
|
120
|
+
"""Whether the field is required for validation."""
|
|
121
|
+
|
|
122
|
+
default_value: Any = None
|
|
123
|
+
"""The default value for the field."""
|
|
124
|
+
|
|
125
|
+
has_default: bool = False
|
|
126
|
+
"""Whether the field has a default value defined."""
|
|
127
|
+
|
|
128
|
+
constraints: ValidationConstraints = field(default_factory=ValidationConstraints)
|
|
129
|
+
"""Validation constraints for the field."""
|
|
130
|
+
|
|
131
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
132
|
+
"""Additional metadata associated with the field."""
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def from_pydantic(
|
|
136
|
+
cls,
|
|
137
|
+
name: str,
|
|
138
|
+
field_info: FieldInfo,
|
|
139
|
+
parent_model: type[BaseModel] | None = None,
|
|
140
|
+
) -> PyField:
|
|
141
|
+
"""Create a PyField from Pydantic field information."""
|
|
142
|
+
raw_type = field_info.annotation
|
|
143
|
+
field_type = None
|
|
144
|
+
if get_origin(raw_type) == Annotated: # Direct comparison with the actual type
|
|
145
|
+
args = get_args(raw_type)
|
|
146
|
+
raw_type = args[0] # Actual type is first argument
|
|
147
|
+
|
|
148
|
+
# Extract field_type from any dict arguments
|
|
149
|
+
for arg in args[1:]:
|
|
150
|
+
if isinstance(arg, dict) and "field_type" in arg:
|
|
151
|
+
field_type = arg["field_type"]
|
|
152
|
+
break
|
|
153
|
+
|
|
154
|
+
# Check json_schema_extra as an alternative source for field_type
|
|
155
|
+
if (
|
|
156
|
+
field_type is None
|
|
157
|
+
and field_info.json_schema_extra
|
|
158
|
+
and (
|
|
159
|
+
isinstance(field_info.json_schema_extra, dict)
|
|
160
|
+
and "field_type" in field_info.json_schema_extra
|
|
161
|
+
)
|
|
162
|
+
):
|
|
163
|
+
field_type = field_info.json_schema_extra["field_type"]
|
|
164
|
+
|
|
165
|
+
# Get required status (we still need model_json_schema for this)
|
|
166
|
+
is_required = True # Default to True
|
|
167
|
+
if parent_model:
|
|
168
|
+
schema = parent_model.model_json_schema()
|
|
169
|
+
is_required = name in schema.get("required", [])
|
|
170
|
+
|
|
171
|
+
from pydantic.fields import PydanticUndefined
|
|
172
|
+
|
|
173
|
+
has_default = field_info.default is not PydanticUndefined
|
|
174
|
+
default_value = field_info.default if has_default else None
|
|
175
|
+
constraints = ValidationConstraints.from_pydantic_field(field_info)
|
|
176
|
+
examples = field_info.examples
|
|
177
|
+
|
|
178
|
+
# Use first example as placeholder if available
|
|
179
|
+
placeholder = str(examples[0]) if examples and examples[0] is not None else None
|
|
180
|
+
|
|
181
|
+
return cls(
|
|
182
|
+
name=name,
|
|
183
|
+
raw_type=raw_type,
|
|
184
|
+
parent_model=parent_model,
|
|
185
|
+
field_type=field_type,
|
|
186
|
+
title=field_info.title or name.replace("_", " ").capitalize(),
|
|
187
|
+
description=field_info.description,
|
|
188
|
+
placeholder=placeholder,
|
|
189
|
+
examples=examples,
|
|
190
|
+
hidden=field_info.exclude is True,
|
|
191
|
+
readonly=field_info.frozen is True,
|
|
192
|
+
deprecated=field_info.deprecated is not None,
|
|
193
|
+
is_required=is_required,
|
|
194
|
+
default_value=default_value,
|
|
195
|
+
has_default=has_default,
|
|
196
|
+
constraints=constraints,
|
|
197
|
+
metadata={},
|
|
198
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_json_schema_extra(field_info: pydantic.fields.FieldInfo) -> dict[str, Any]:
|
|
9
|
+
"""Extract JSON schema extra information from a field.
|
|
10
|
+
|
|
11
|
+
Handles both when json_schema_extra is a dict and when it's a callable.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
field_info: The Pydantic field info object
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
A dictionary of schema extra information
|
|
18
|
+
"""
|
|
19
|
+
if not field_info.json_schema_extra:
|
|
20
|
+
return {}
|
|
21
|
+
|
|
22
|
+
if isinstance(field_info.json_schema_extra, dict):
|
|
23
|
+
return field_info.json_schema_extra
|
|
24
|
+
|
|
25
|
+
# Handle callable json_schema_extra
|
|
26
|
+
if callable(field_info.json_schema_extra):
|
|
27
|
+
schema_dict: dict[str, Any] = {}
|
|
28
|
+
field_info.json_schema_extra(schema_dict)
|
|
29
|
+
return schema_dict
|
|
30
|
+
return {}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_default_value[T](field_info: pydantic.fields.FieldInfo, fallback: T) -> T:
|
|
34
|
+
"""Get default value for an integer field.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
field_info: Pydantic field info
|
|
38
|
+
fallback: Default value to use if no default is defined
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Default value for the field
|
|
42
|
+
"""
|
|
43
|
+
# Check for default value
|
|
44
|
+
if (
|
|
45
|
+
field_info.default is not None
|
|
46
|
+
and field_info.default is not pydantic.fields.PydanticUndefined
|
|
47
|
+
):
|
|
48
|
+
return field_info.default
|
|
49
|
+
|
|
50
|
+
# Check for default factory
|
|
51
|
+
if field_info.default_factory is not None:
|
|
52
|
+
if field_info.default_factory_takes_validated_data:
|
|
53
|
+
return field_info.default_factory({}) # type: ignore
|
|
54
|
+
return field_info.default_factory() # type: ignore
|
|
55
|
+
return fallback
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Tests for the PyField class."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Annotated, Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from typico.pyfield import PyField
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Address(BaseModel):
|
|
14
|
+
"""Test nested model."""
|
|
15
|
+
|
|
16
|
+
street: str
|
|
17
|
+
city: str
|
|
18
|
+
zip_code: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TestModel(BaseModel):
|
|
22
|
+
"""Test model with various field types."""
|
|
23
|
+
|
|
24
|
+
id: int = Field(description="Unique identifier")
|
|
25
|
+
name: str = Field(title="Full Name")
|
|
26
|
+
email: Annotated[str, {"field_type": "email"}]
|
|
27
|
+
age: int = Field(ge=0, le=120)
|
|
28
|
+
is_active: bool = True
|
|
29
|
+
tags: list[str] = []
|
|
30
|
+
address: Address | None = None
|
|
31
|
+
notes: str = Field(min_length=5, max_length=1000, default="")
|
|
32
|
+
model_id: Annotated[str, {"field_type": "llm_model_identifier"}] = Field(
|
|
33
|
+
default="gpt-3.5-turbo",
|
|
34
|
+
description="The LLM model to use",
|
|
35
|
+
examples=["gpt-3.5-turbo", "gpt-4"],
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_basic_field_extraction():
|
|
40
|
+
"""Test extraction of basic field information."""
|
|
41
|
+
# Create PyField from the 'name' field
|
|
42
|
+
field_info = TestModel.model_fields["name"]
|
|
43
|
+
field = PyField.from_pydantic("name", field_info, TestModel)
|
|
44
|
+
|
|
45
|
+
assert field.name == "name"
|
|
46
|
+
assert field.title == "Full Name" # Uses title from Field
|
|
47
|
+
assert field.raw_type is str
|
|
48
|
+
assert field.parent_model is TestModel
|
|
49
|
+
assert field.field_type is None # No field_type specified
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_annotated_field_type():
|
|
53
|
+
"""Test extraction of field_type from Annotated fields."""
|
|
54
|
+
# Create PyField from the 'email' field which has Annotated field_type
|
|
55
|
+
field_info = TestModel.model_fields["email"]
|
|
56
|
+
field = PyField.from_pydantic("email", field_info, TestModel)
|
|
57
|
+
|
|
58
|
+
assert field.name == "email"
|
|
59
|
+
assert field.field_type == "email"
|
|
60
|
+
assert field.raw_type is str # Should extract the actual type from Annotated
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_domain_specific_field_type():
|
|
64
|
+
"""Test extraction of domain-specific field types."""
|
|
65
|
+
# Test the model_id field with custom field_type
|
|
66
|
+
field_info = TestModel.model_fields["model_id"]
|
|
67
|
+
field = PyField.from_pydantic("model_id", field_info, TestModel)
|
|
68
|
+
|
|
69
|
+
assert field.field_type == "llm_model_identifier"
|
|
70
|
+
assert field.default_value == "gpt-3.5-turbo"
|
|
71
|
+
assert field.description == "The LLM model to use"
|
|
72
|
+
assert field.examples is not None
|
|
73
|
+
assert field.examples[0] == "gpt-3.5-turbo"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_constraints_extraction():
|
|
77
|
+
"""Test extraction of validation constraints."""
|
|
78
|
+
# Test the 'age' field with constraints
|
|
79
|
+
field_info = TestModel.model_fields["age"]
|
|
80
|
+
field = PyField.from_pydantic("age", field_info, TestModel)
|
|
81
|
+
|
|
82
|
+
assert field.constraints.min_value == 0
|
|
83
|
+
assert field.constraints.max_value == 120 # noqa: PLR2004
|
|
84
|
+
assert field.constraints.exclusive_min is False
|
|
85
|
+
assert field.constraints.exclusive_max is False
|
|
86
|
+
|
|
87
|
+
# Test the 'notes' field with length constraints
|
|
88
|
+
field_info = TestModel.model_fields["notes"]
|
|
89
|
+
field = PyField.from_pydantic("notes", field_info, TestModel)
|
|
90
|
+
|
|
91
|
+
assert field.constraints.min_length == 5 # noqa: PLR2004
|
|
92
|
+
assert field.constraints.max_length == 1000 # noqa: PLR2004
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_required_and_default():
|
|
96
|
+
"""Test required status and default value extraction."""
|
|
97
|
+
# 'id' is required and has no default
|
|
98
|
+
field_info = TestModel.model_fields["id"]
|
|
99
|
+
field = PyField.from_pydantic("id", field_info, TestModel)
|
|
100
|
+
|
|
101
|
+
assert field.is_required is True
|
|
102
|
+
assert field.has_default is False
|
|
103
|
+
|
|
104
|
+
# 'is_active' has a default value
|
|
105
|
+
field_info = TestModel.model_fields["is_active"]
|
|
106
|
+
field = PyField.from_pydantic("is_active", field_info, TestModel)
|
|
107
|
+
|
|
108
|
+
assert field.has_default is True
|
|
109
|
+
assert field.default_value is True
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_nested_model_field():
|
|
113
|
+
"""Test handling of nested model fields."""
|
|
114
|
+
field_info = TestModel.model_fields["address"]
|
|
115
|
+
field = PyField.from_pydantic("address", field_info, TestModel)
|
|
116
|
+
|
|
117
|
+
assert field.raw_type == Optional[Address] # noqa: UP007
|
|
118
|
+
assert field.is_required is False # Should be optional
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_examples_and_placeholder():
|
|
122
|
+
"""Test extraction of examples and placeholder."""
|
|
123
|
+
field_info = TestModel.model_fields["model_id"]
|
|
124
|
+
field = PyField.from_pydantic("model_id", field_info, TestModel)
|
|
125
|
+
|
|
126
|
+
assert field.examples is not None
|
|
127
|
+
assert len(field.examples) == 2 # noqa: PLR2004
|
|
128
|
+
assert field.examples[0] == "gpt-3.5-turbo"
|
|
129
|
+
assert field.placeholder == "gpt-3.5-turbo" # First example becomes placeholder
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == "__main__":
|
|
133
|
+
pytest.main([__file__])
|