Skip to content

Commit

Permalink
remove empty data file with a dynamically-generate data_module
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Dec 7, 2024
1 parent 3aeba5b commit 2f50e81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion bigraph_schema/data.py

This file was deleted.

15 changes: 11 additions & 4 deletions bigraph_schema/type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"""

import sys
import types
import copy
import numbers
import numpy as np
Expand All @@ -81,9 +83,14 @@
deep_merge, hierarchy_depth,
establish_path)

import bigraph_schema.data as data
import bigraph_schema.data

# Create a new module dynamically for the dataclasses
module_name = 'bigraph_schema.data'
if module_name not in sys.modules:
data_module = types.ModuleType(module_name)
sys.modules[module_name] = data_module
else:
data_module = sys.modules[module_name]

overridable_schema_keys = set([
'_type',
Expand Down Expand Up @@ -1760,7 +1767,7 @@ def default(subschema=subschema):
'__module__': 'bigraph_schema.data'})

setattr(
bigraph_schema.data,
data_module,
dataclass_name,
dataclass)

Expand Down Expand Up @@ -1837,7 +1844,7 @@ def dataclass_tree(schema, path, core):
'Optional': Optional,
'str': str
})
setattr(data, dataclass_name, dataclass)
setattr(data_module, dataclass_name, dataclass)

return dataclass

Expand Down
9 changes: 4 additions & 5 deletions bigraph_schema/type_system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from dataclasses import asdict

from bigraph_schema.type_functions import (
divide_longest, base_type_library, accumulate, to_string, deserialize_integer, apply_schema, diff
divide_longest, base_type_library, accumulate, to_string, deserialize_integer, apply_schema, diff, data_module
)
from bigraph_schema import TypeSystem
from bigraph_schema.units import units
from bigraph_schema.registry import establish_path, remove_omitted, NONE_SYMBOL
import bigraph_schema.data as data


@pytest.fixture
Expand Down Expand Up @@ -1965,9 +1964,9 @@ def test_dataclass(core):
'b': 888.88},
'x': 111.11111}}

nested_new = data.nested(
data.nested_a(
data.nested_a_a(
nested_new = data_module.nested(
data_module.nested_a(
data_module.nested_a_a(
a=222.22,
b=3.3333),
5555.55))
Expand Down

0 comments on commit 2f50e81

Please sign in to comment.