Skip to content
Open
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
2 changes: 1 addition & 1 deletion gemd/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.0.3"
__version__ = "3.1.0"
2 changes: 0 additions & 2 deletions gemd/demo/cake.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,10 @@ def make_cake_templates():
tmpl["Procuring"] = ProcessTemplate(
name="Procuring",
description="Buyin' stuff",
allowed_names=[], # Takes no ingredients by definition
)
tmpl["Baking"] = ProcessTemplate(
name="Baking",
description="Using heat to promote chemical reactions in a material",
allowed_names=["batter"],
allowed_labels=["precursor"],
conditions=[(tmpl["Oven temperature"], RealBounds(0, 700, "degF"))],
parameters=[(tmpl["Oven temperature setting"], RealBounds(100, 550, "degF"))],
Expand Down
32 changes: 19 additions & 13 deletions gemd/entity/template/process_template.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""A process template."""

from warnings import warn

from deprecation import DeprecatedWarning, deprecated

from gemd.entity.setters import validate_list
from gemd.entity.template.base_template import BaseTemplate
from gemd.entity.template.has_condition_templates import HasConditionTemplates
from gemd.entity.template.has_parameter_templates import HasParameterTemplates

__all__ = ["ProcessTemplate"]

_ALLOWED_NAMES_DETAILS = "GEMD Python discards the value, and the Citrine Platform ignores it."


class ProcessTemplate(
BaseTemplate, HasConditionTemplates, HasParameterTemplates, typ="process_template"
Expand All @@ -32,11 +38,9 @@ class ProcessTemplate(
are hierarchical strings that store information about an entity. They can be used
for filtering and discoverability.
allowed_names: List[str], optional
Deprecated. This field does not limit ingredient names.
The Citrine Platform ignores this list when you save a template. When you fetch a
template, this list has the distinct ingredient names from process specs that use
the template. Names come from datasets you can read. GEMD Python keeps this field
to give users time to migrate code and JSON away from it.
Deprecated as of 3.1.0, and will be removed in 4.0.0.
GEMD Python discards the value and leaves it out of the JSON.
Passing any list, even an empty one, emits a DeprecationWarning.
allowed_labels: List[str], optional
The set of labels that a process' ingredients are allowed to use in their labels field.
conditions: List[~gemd.entity.template.condition_template.ConditionTemplate] or \
Expand Down Expand Up @@ -70,23 +74,25 @@ def __init__(
HasConditionTemplates.__init__(self, conditions)
HasParameterTemplates.__init__(self, parameters)

self._allowed_names = None
self.allowed_names = allowed_names
if allowed_names is not None:
warn(
DeprecatedWarning("allowed_names", "3.1.0", "4.0.0", _ALLOWED_NAMES_DETAILS),
stacklevel=2,
)

self._allowed_labels = None
self.allowed_labels = allowed_labels

@property
@deprecated(deprecated_in="3.1.0", removed_in="4.0.0", details=_ALLOWED_NAMES_DETAILS)
def allowed_names(self):
"""Get the allowed names."""
return self._allowed_names
"""Get an empty list."""
return []

@allowed_names.setter
@deprecated(deprecated_in="3.1.0", removed_in="4.0.0", details=_ALLOWED_NAMES_DETAILS)
def allowed_names(self, allowed_names):
if allowed_names is None:
self._allowed_names = validate_list([], str)
else:
self._allowed_names = validate_list(allowed_names, str)
pass

@property
def allowed_labels(self):
Expand Down
18 changes: 8 additions & 10 deletions tests/entity/template/test_process_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ def test_bounds_mismatch():
ProcessTemplate("a process template", conditions=[[cond_template, object_bounds]])


def test_allowed_names():
"""Test that allowed_names can be assigned.

Presently allowed_names is not used for any validation, but this test can be expanded
if it is used in the future.
"""
allowed_names = ["THF", "Carbon Disulfide", "Dimethyl Ether"]
proc_template = ProcessTemplate(name="test template", allowed_names=allowed_names)
for name in allowed_names:
assert name in proc_template.allowed_names
def test_allowed_names_removed():
"""Test that each use of allowed_names warns of its deprecation."""
with pytest.deprecated_call(match="allowed_names is deprecated"):
proc_template = ProcessTemplate(name="test template", allowed_names=[])
with pytest.deprecated_call(match="allowed_names is deprecated"):
proc_template.allowed_names = ["Water"]
with pytest.deprecated_call(match="allowed_names is deprecated"):
assert proc_template.allowed_names == []


def test_allowed_labels():
Expand Down
Loading