Skip to content
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

Create a new option to output the schema to a file #352

Merged
merged 4 commits into from
Dec 19, 2024
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/core-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ jobs:
pip install git+https://github.com/sodascience/metasyn-disclosure-control
pip install .
metasyn create-meta metasyn/demo/demo_titanic.csv --config examples/config_files/example_config.toml
- name: Test GMF file
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
metasyn schema -o current_schema.json
MD5_DATA=(`md5sum current_schema.json`)
[[ ${MD5_DATA[0]} == "c2a69330cec7a147ab775f5f0e037d8b" ]]



build-docs:
name: Build documentation
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ docs/source/api/generated

# uv stuff
uv.lock

# Schema stuff
create_schema.py
schemas/
14 changes: 12 additions & 2 deletions metasyn/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,14 @@ def schema() -> None:
action="store_true",
)

parser.add_argument(
"-o", "--output",
help="File to write the schema to.",
type=pathlib.Path,
)

# parse the args without the subcommand
args, _ = parser.parse_known_args()
args = parser.parse_args()

# deduplicated list of plugins for schema
plugins_avail = {entry.name for entry in entry_points(group="metasyn.distribution_provider")}
Expand All @@ -257,7 +263,11 @@ def schema() -> None:
)
parser.error(errmsg)
jsonschema = create_schema(list(plugins))
print(json.dumps(jsonschema, indent=2))
if args.output is None:
print(json.dumps(jsonschema, indent=4))
else:
with open(args.output, "w") as handle:
json.dump(jsonschema, handle, indent=4)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion metasyn/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

SCHEMA_BASE = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://sodascience.github.io/generative_metadata_format/core/1.0.0/generative_metadata_format", # noqa: E501
"$id": "http://sodascience.github.io/generative_metadata_format/core/1.1/generative_metadata_format", # noqa: E501
"type": "object",
"properties": {
"n_rows": {"type": "number"},
Expand Down
Loading