-
Notifications
You must be signed in to change notification settings - Fork 6
feat: enable schema extensions via data package architecture #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pierlou
merged 24 commits into
etalab:master
from
ttdm:feat/child_schemas_using_data_package
Apr 16, 2026
Merged
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
57320ff
first implem to get a quick review on the structure.
ttdm 645663e
feat: define proper name, title, description for each schema.
ttdm c2b1f38
chore: remore old json schema
ttdm 1f1fe1b
feat: move the scripts in sources, create github actions
ttdm f5b3f6f
chore: auto-generate schemas from source [skip ci]
github-actions[bot] 225423c
feat: simplify extensions with the working generation
ttdm 578f65a
chore: auto-generate schemas from source [skip ci]
github-actions[bot] f089353
chore: remove exemples
ttdm 1c226dd
fix: assert version path
ttdm ff93e48
test: testing a wrong value in a json field to test the Ci frictionl…
ttdm e1a0732
chore: auto-generate schemas from source [skip ci]
github-actions[bot] e0348d7
chore: reseting to a proper exemple value
ttdm f43f83f
chore: auto-generate schemas from source [skip ci]
github-actions[bot] 41d6553
feat: merger improvements, test improvement; small code quality impr…
ttdm d487442
chore: keep cleaning the code
ttdm 5034df1
chore: move the builder main entry point on top of its class; move co…
ttdm 347808e
feat: all small improvements from the review
ttdm cff5e51
feat: create a proper datapackage which link towards all table-schemas
ttdm 68fdbb8
feat: add path into schemas, clarify what to_table_schema does
ttdm 62bf8c6
refactor(schema_builder): make the repo_root injectable
David-Guillot bf72731
feat(schema_example_generator): move generated examples
David-Guillot 4256243
test: initial testing
David-Guillot 75b1d71
chore(ci): run tests before building schemas
David-Guillot 6ec805d
feat: centralize all constants in a file, generate the current schema…
ttdm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: Build and Validate Schemas | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - feat/** | ||
| paths: | ||
| - "schema/**/*.json" | ||
| - "src/**/*.py" | ||
| - "requirements.txt" | ||
| pull_request: | ||
| paths: | ||
| - "schema/**/*.json" | ||
| - "src/**/*.py" | ||
| - "requirements.txt" | ||
|
|
||
| jobs: | ||
| build-and-validate: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Cache pip | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.cache/pip | ||
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pip- | ||
| ${{ runner.os }}- | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install -r requirements.txt | ||
|
|
||
| - name: Build schemas from source | ||
| run: python3 src/build_schemas.py | ||
|
|
||
| - name: Check for changes | ||
| id: verify_diff | ||
| run: | | ||
| git diff --quiet build/ || echo "changed=true" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Commit and push if changes detected | ||
| if: steps.verify_diff.outputs.changed == 'true' && github.event_name == 'push' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add build/ | ||
| git commit -m "chore: auto-generate schemas from source [skip ci]" | ||
| git push | ||
|
|
||
| - name: Validate generated schemas | ||
| run: python3 src/validate_schemas.py |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.pyc | ||
| *.backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # Guide d'utilisation | ||
|
|
||
| ## Workflow automatisé | ||
|
|
||
| **GitHub Actions génère et valide automatiquement les schémas** lorsque sont détextées des modifications dans `schema/` lors d'un push. | ||
|
|
||
| Vous n'avez qu'à modifier les fichiers sources dans `schema/core/` et `schema/extensions/` et commit le tout dans une branche puis la push sur github. | ||
|
|
||
| ## Modifier un schéma | ||
|
|
||
| 1. Ouvrir le fichier JSON concerné (core ou extension), ex: `schema/extensions/{category}/{name}.json` | ||
| Catégory étant limité à "cible" ou "usage". | ||
| (Autoriser plus d'option, nécessiterait d'introduire plus d'éléments de configuration, notamment pour pouvoir automatiquement savoir quelles combinaisons générer entre les différents catégories et les différents éléments de chaque catégorie.) | ||
|
|
||
| 2. Ajouter un champ dans le tableau `fields` : | ||
|
|
||
| ```json | ||
| { | ||
| "name": "nom_du_champ", | ||
| "title": "Titre du champ", | ||
| "description": "Description", | ||
| "type": "string", | ||
| "example": "valeur d'exemple", | ||
| "constraints": { | ||
| "required": true, | ||
| "maxLength": 500 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 3. Commit et push - GitHub Actions régénère et valide automatiquement les schémas | ||
|
|
||
| ## Ajouter une extension (cible ou usage) | ||
|
|
||
| Le repo génère automatiquement toutes les combinaisons d'usages pour chaque cible. | ||
|
|
||
| Pour ajouter une nouvelle cible ou un nouvel usage : | ||
| 1. Créer un fichier JSON dans `schema/extensions/cible/` ou `schema/extensions/usage/` | ||
| 2. Suivre le format des fichiers existants | ||
| 3. Commit et push - les schémas combinés sont générés automatiquement | ||
|
|
||
| # Development Guide | ||
|
|
||
| ## Quick Setup | ||
|
|
||
| ```bash | ||
| # Environment | ||
| python3 -m venv venv | ||
| source venv/bin/activate | ||
| pip install -r requirements.txt | ||
|
|
||
| # Generate schemas and example files (optional - automated via GitHub Actions) | ||
| python3 src/build_schemas.py | ||
|
|
||
| # Validate (optional - automated via GitHub Actions) | ||
| python3 src/validate_schemas.py | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| The repo uses a modular datapackage structure: | ||
|
|
||
| - **Core schema** (`schema/core/schema-core.json`) - Base fields required for all schemas | ||
| - **Extensions** - Optional fields for specific use cases (usage & target audience) | ||
| - **Build script** - Generates schemas for all combinations of usage for each target | ||
|
|
||
| ``` | ||
| schema/ | ||
| ├── core/schema-core.json | ||
| └── extensions/ | ||
| ├── usage/ | ||
| │ ├── communication.json | ||
| │ ├── pilotage.json | ||
| │ └── activation.json | ||
| └── cible/ | ||
| ├── associations.json | ||
| ├── particuliers.json | ||
| ├── professionnels.json | ||
| └── secteur-public.json | ||
| ``` | ||
|
|
||
| ## Common Tasks | ||
|
|
||
| ### Add a Field | ||
|
|
||
| 1. Open the relevant JSON file (core or extension), ex: `schema/extensions/{category}/{name}.json` | ||
| 2. Add to the `fields` array: | ||
|
|
||
| ```json | ||
| { | ||
| "name": "field_name", | ||
| "title": "Field Title", | ||
| "description": "Description", | ||
| "type": "string", | ||
| "example": "example value" | ||
| } | ||
| ``` | ||
|
|
||
| 3. Commit and push - GitHub Actions will automatically regenerate and validate schemas | ||
| 4. (Optional) Test locally: `python3 src/build_schemas.py && python3 src/validate_schemas.py` | ||
|
|
||
| ### Create an Extension | ||
|
|
||
| The simplest way is to copy an existing extension for reference. | ||
|
|
||
| The written code automatically handles new targets or usages but needs to be edited if a new category of extensions is created. | ||
|
|
||
| Currently, there is no generic logic to handle a new type of extension. | ||
| In particular, the associations between extensions in this new category should be defined, and the allowed combinations between extension categories should be defined. | ||
|
|
||
| ### Resolve Field Conflicts | ||
|
|
||
| When fields with the same name have different types, you'll get warnings. Resolve by: | ||
|
|
||
| **Option 1: Rename** - Use different names in different extensions | ||
|
|
||
| ```json | ||
| // In usage/pilotage.json | ||
| {"name": "budget_total_alloue", "type": "number"} | ||
|
|
||
| // In cible/individuals.json | ||
| {"name": "budget_per_person", "type": "string"} | ||
| ``` | ||
|
|
||
| **Option 2: Harmonize** - Use the same type everywhere | ||
|
|
||
| ```json | ||
| { "name": "budget", "type": "number" } | ||
| ``` | ||
|
|
||
| **Future enhancements:** | ||
| Handle priority fields to allow overriding some fields. (Identified use case: make a field mandatory within an extension). | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # Validate a specific schema | ||
| frictionless validate build/schemas/dispositif-aide-pilotage.json | ||
|
|
||
| # Validate data against a schema | ||
| frictionless validate data.csv --schema build/schemas/dispositif-aide.json | ||
|
|
||
| # Validate all schemas | ||
| python3 scripts/validate_schemas.py | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Frictionless Data Specs](https://specs.frictionlessdata.io/) | ||
| - [Table Schema Spec](https://specs.frictionlessdata.io/table-schema/) | ||
| - [Data Package Spec](https://specs.frictionlessdata.io/data-package/) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.