Skip to content

Commit

Permalink
migrate from 'schema' to 'data_model' attribute; issue FutureWarning. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
davemfish committed Nov 25, 2024
1 parent 896e452 commit bf12eea
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/geometamaker/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
import logging
import os
import warnings
from typing import List, Union

import fsspec
Expand Down Expand Up @@ -255,7 +256,6 @@ class Resource(BaseMetadata):

# A version string we can use to identify geometamaker compliant documents
metadata_version: str = ''
# TODO: don't want to include this in doc, but need it as an attribute
metadata_path: str = ''

# These are populated geometamaker.describe()
Expand Down Expand Up @@ -320,6 +320,16 @@ def load(cls, filepath):
# delete this property so that geometamaker can initialize it itself
# with the current version info.
del yaml_dict['metadata_version']

# migrate from 'schema' to 'data_model', if needed.
if 'schema' in yaml_dict:
warnings.warn(
"'schema' has been replaced with 'data_model' as an attribute "
"name. In the future, the presence of a 'schema' attribute "
"will raise a ValidationError",
category=FutureWarning)
yaml_dict['data_model'] = yaml_dict['schema']
del yaml_dict['schema']
return cls(**yaml_dict)

def set_title(self, title):
Expand Down Expand Up @@ -502,7 +512,8 @@ def write(self, workspace=None):
workspace, os.path.basename(self.metadata_path))

with open(target_path, 'w') as file:
file.write(utils.yaml_dump(self.model_dump()))
file.write(utils.yaml_dump(
self.model_dump(exclude=['metadata_path'])))

def to_string(self):
pass
Expand Down

0 comments on commit bf12eea

Please sign in to comment.