-
Notifications
You must be signed in to change notification settings - Fork 15
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
FIX: Invert default schema URLs #971
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,11 @@ dev = [ | |
"pyarrow-stubs", | ||
"pydocstyle", | ||
"PyQt5-sip<12.16.0; python_version == '3.8'", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-mock", | ||
"pytest-runner", | ||
"pytest", | ||
"pytest-xdist", | ||
Comment on lines
-63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort + not sure why this dependency was never added to parallelize tests |
||
"rstcheck", | ||
"ruff", | ||
"types-PyYAML", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,9 +138,9 @@ def url(cls) -> str: | |
DEV_URL = f"{FmuSchemas.DEV_URL}/{cls.PATH}" | ||
PROD_URL = f"{FmuSchemas.PROD_URL}/{cls.PATH}" | ||
|
||
if os.environ.get("SCHEMA_RELEASE", False): | ||
return PROD_URL | ||
return DEV_URL | ||
if os.environ.get("DEV_SCHEMA", False): | ||
return DEV_URL | ||
return PROD_URL | ||
Comment on lines
+141
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We won't be able to produce metadata with the |
||
|
||
@classmethod | ||
def default_generator(cls) -> type[GenerateJsonSchema]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import logging | ||
import os | ||
import shutil | ||
import sys | ||
from copy import deepcopy | ||
from pathlib import Path | ||
|
||
|
@@ -14,6 +15,12 @@ | |
import xtgeo | ||
import yaml | ||
|
||
# This must be set before anything in dataio is imported if not using pytest-xdist. | ||
if "--prod" in sys.argv: | ||
os.environ["DEV_SCHEMA"] = "" | ||
else: | ||
os.environ["DEV_SCHEMA"] = "1" | ||
|
||
import fmu.dataio as dio | ||
from fmu.config import utilities as ut | ||
from fmu.dataio._models.fmu_results import FmuResults, fields, global_configuration | ||
|
@@ -45,6 +52,21 @@ | |
ERT_RUNPATH = f"_ERT_{FmuEnv.RUNPATH.name}" | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--prod", action="store_true", help="Use schemas/metadata with production URLs." | ||
) | ||
Comment on lines
+55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes pytest aware of our custom |
||
|
||
|
||
def pytest_configure(config) -> None: | ||
"""If '--prod' is given to pytest, use schemas/metadata with prod urls (i.e. not dev | ||
urls).""" | ||
if config.getoption("--prod"): | ||
os.environ["DEV_SCHEMA"] = "" | ||
else: | ||
os.environ["DEV_SCHEMA"] = "1" | ||
|
||
|
||
def _current_function_name(): | ||
"""Helper to retrieve current function name, e.g. for logging""" | ||
return inspect.currentframe().f_back.f_code.co_name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,10 @@ import subprocess | |
import sys | ||
from copy import deepcopy | ||
from pathlib import Path | ||
from typing import Any, Dict, List, TypeVar | ||
from typing import TYPE_CHECKING, Any, Dict, List, TypeVar | ||
|
||
from fmu.dataio._models import schemas | ||
from fmu.dataio._models._schema_base import SchemaBase | ||
if TYPE_CHECKING: | ||
from fmu.dataio._models._schema_base import SchemaBase | ||
|
||
GREEN = "\033[32m" | ||
RED = "\033[31m" | ||
|
@@ -47,6 +47,12 @@ def _get_parser() -> argparse.ArgumentParser: | |
action="store_true", | ||
help="Show a diff between the current schema and the new one in output.", | ||
) | ||
parser.add_argument( | ||
"-p", | ||
"--prod", | ||
action="store_true", | ||
help="Produce schemas with production URLs", | ||
) | ||
parser.add_argument( | ||
"-t", | ||
"--test", | ||
|
@@ -183,13 +189,21 @@ def write_schema( | |
_show_py_diff(existing_schema, new_schema) | ||
return False | ||
|
||
if is_release: | ||
if ( | ||
is_release | ||
and not force_overwrite | ||
and existing_schema["$id"] != new_schema["$id"] | ||
): | ||
print( | ||
INFO, | ||
f"{BOLD}{schema.FILENAME}{NC} version {BOLD}{schema.VERSION}{NC}: " | ||
f"modifying '$id' url to 'prod':\n {schema.url()}", | ||
FAIL, | ||
f"🚨 {BOLD}{schema.FILENAME}{NC} version " | ||
f"{BOLD}{schema.VERSION}{NC}: mismatch in '$id'. you probably need " | ||
"to run `./tools/update-schema --prod --force`", | ||
) | ||
elif new_schema == existing_schema: | ||
if show_diff: | ||
_show_py_diff(existing_schema, new_schema) | ||
return False | ||
if new_schema == existing_schema: | ||
print( | ||
PASS, | ||
f"{BOLD}{schema.FILENAME}{NC} version " | ||
|
@@ -219,11 +233,13 @@ def main() -> None: | |
if args.force: | ||
print(INFO, "forcing overwrite of all schemas") | ||
|
||
is_release = bool(os.environ.get("SCHEMA_RELEASE", False)) | ||
os.environ["DEV_SCHEMA"] = "" if args.prod else "1" | ||
# Ensures URLs will differ based on above | ||
import fmu.dataio._models as models | ||
Comment on lines
+237
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lazy import to ensure the models receive the |
||
|
||
failed_a_write = False | ||
for schema in schemas: | ||
did_write = write_schema(schema, args.force, is_release, args.test, args.diff) | ||
for schema in models.schemas: | ||
did_write = write_schema(schema, args.force, args.prod, args.test, args.diff) | ||
if not did_write: | ||
failed_a_write = True | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both pytest and update-schemas take a
--prod
flag now. Both ensure theDEV_SCHEMAS
environment variable is unset. This causes the default case to happen: schemas and metadata are produced with the production url.