Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/config-types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Update Config Types

on:
push:
branches: [main]
paths:
- 'src/datamodel_code_generator/config.py'
pull_request:
branches: [main]
paths:
- 'src/datamodel_code_generator/config.py'
pull_request_target:
types: [labeled]
paths:
- 'src/datamodel_code_generator/config.py'

permissions:
contents: write

jobs:
update-config-types:
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
github.actor == 'koxudaxi' ||
github.actor == 'gaborbernat' ||
github.actor == 'ilovelinux' ||
(github.event_name == 'pull_request_target' && github.event.label.name == 'safe-to-fix' &&
(github.event.sender.login == 'koxudaxi' ||
github.event.sender.login == 'gaborbernat' ||
github.event.sender.login == 'ilovelinux'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- uses: actions/checkout@v4
if: github.event_name == 'push' || github.event_name == 'pull_request_target' || github.event.pull_request.head.repo.full_name == github.repository
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
token: ${{ secrets.PAT }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Setup environment
run: tox run -vv --notest --skip-missing-interpreters false -e config-types
env:
UV_PYTHON_PREFERENCE: "only-managed"
- name: Generate TypedDict from Config models
run: |
.tox/config-types/bin/datamodel-codegen --profile base-config-dict
.tox/config-types/bin/datamodel-codegen --profile generate-config-dict
.tox/config-types/bin/datamodel-codegen --profile parser-config-dict
.tox/config-types/bin/datamodel-codegen --profile parse-config-dict
- name: Format generated files
run: |
uv tool run ruff format src/datamodel_code_generator/_types/
- name: Commit and push if changed
if: github.event_name == 'push' || github.event_name == 'pull_request_target' || github.event.pull_request.head.repo.full_name == github.repository
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add src/datamodel_code_generator/_types/
git diff --staged --quiet || git commit -m "chore: update TypedDict from Config models

🤖 Generated by GitHub Actions"
git push
31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ lint.per-file-ignores."scripts/*.py" = [
"S", # subprocess security is fine for build scripts
"T201", # print is fine for CLI scripts
]
lint.per-file-ignores."src/datamodel_code_generator/config.py" = [
"TC", # Pydantic needs these imports at runtime, not just TYPE_CHECKING
]
lint.per-file-ignores."tests/**/*.py" = [
"FBT", # don't care about booleans as positional arguments in tests
"INP001", # no implicit namespace
Expand Down Expand Up @@ -257,3 +260,31 @@ reportPrivateImportUsage = false
[tool.pydantic-pycharm-plugin]
ignore-init-method-arguments = true
parsable-types.str = [ "int", "float" ]

[tool.datamodel-codegen.profiles.base-config-dict]
input-model = "src/datamodel_code_generator/config.py:BaseConfig"
output = "src/datamodel_code_generator/_types/base_config_dict.py"
output-model-type = "typing.TypedDict"
disable-timestamp = true
type-overrides = { "path" = "pathlib.Path" }

[tool.datamodel-codegen.profiles.generate-config-dict]
input-model = "src/datamodel_code_generator/config.py:GenerateConfig"
output = "src/datamodel_code_generator/_types/generate_config_dict.py"
output-model-type = "typing.TypedDict"
disable-timestamp = true
type-overrides = { "path" = "pathlib.Path" }

[tool.datamodel-codegen.profiles.parser-config-dict]
input-model = "src/datamodel_code_generator/config.py:ParserConfig"
output = "src/datamodel_code_generator/_types/parser_config_dict.py"
output-model-type = "typing.TypedDict"
disable-timestamp = true
type-overrides = { "path" = "pathlib.Path" }

[tool.datamodel-codegen.profiles.parse-config-dict]
input-model = "src/datamodel_code_generator/config.py:ParseConfig"
output = "src/datamodel_code_generator/_types/parse_config_dict.py"
output-model-type = "typing.TypedDict"
disable-timestamp = true
type-overrides = { "path" = "pathlib.Path" }
Loading
Loading