Skip to content

Commit

Permalink
Merge pull request #398 from thegridelectric/dev
Browse files Browse the repository at this point in the history
Publish latest changes in a package.
  • Loading branch information
anschweitzer authored Dec 28, 2024
2 parents e225302 + 6188b9c commit 2425f7d
Show file tree
Hide file tree
Showing 246 changed files with 41,429 additions and 28,207 deletions.
1 change: 1 addition & 0 deletions CodeGenerationTools/GridworksCore/DataSchema.odxml

Large diffs are not rendered by default.

76 changes: 16 additions & 60 deletions CodeGenerationTools/GridworksCore/Enum/DeriveEnums.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

<xsl:text>from enum import auto
from typing import List
from typing import Optional

from gw.enums import GwStrEnum

Expand All @@ -57,26 +56,7 @@ class </xsl:text><xsl:value-of select="$enum-class-name"/>
<xsl:with-param name="indent-spaces" select="4"/>
</xsl:call-template>
</xsl:if>

<xsl:text>

Enum </xsl:text><xsl:value-of select="Name"/><xsl:text> version </xsl:text><xsl:value-of select="$enum-version"/>
<xsl:text> in the GridWorks Type registry.

Used by multiple Application Shared Languages (ASLs). For more information:
- [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/)
- [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#</xsl:text>
<xsl:value-of select="translate($enum-name,'.','')"/>
<xsl:text>)</xsl:text>

<xsl:if test="(normalize-space(Url)!='')">
<xsl:text>
- [More Info](</xsl:text>
<xsl:value-of select="normalize-space(Url)"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>

Values:</xsl:text>
<xsl:for-each select="$airtable//EnumSymbols/EnumSymbol[(Enum = $enum-id) and (Version &lt;= $enum-version)]">
<xsl:sort select="Idx" data-type="number"/>
Expand Down Expand Up @@ -104,7 +84,20 @@ class </xsl:text><xsl:value-of select="$enum-class-name"/>
</xsl:if>

</xsl:for-each>
<xsl:text>

For more information:
- [ASLs](https://gridworks-type-registry.readthedocs.io/en/latest/)
- [Global Authority](https://gridworks-type-registry.readthedocs.io/en/latest/enums.html#</xsl:text>
<xsl:value-of select="translate($enum-name,'.','')"/>
<xsl:text>)</xsl:text>

<xsl:if test="(normalize-space(Url)!='')">
<xsl:text>
- [More Info](</xsl:text>
<xsl:value-of select="normalize-space(Url)"/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>
"""

Expand All @@ -130,16 +123,6 @@ class </xsl:text><xsl:value-of select="$enum-class-name"/>
def default(cls) -> "</xsl:text>
<xsl:value-of select="$enum-class-name"/>
<xsl:text>":
"""
Returns default value (in this case </xsl:text>
<xsl:if test="$enum-type = 'Upper'">
<xsl:value-of select="translate(translate(DefaultEnumValue,'-',''),$lcletters, $ucletters)"/>
</xsl:if>
<xsl:if test="$enum-type ='UpperPython'">
<xsl:value-of select="DefaultEnumValue"/>
</xsl:if>
<xsl:text>)
"""
return cls.</xsl:text>
<xsl:if test="$enum-type = 'Upper'">
<xsl:value-of select="translate(translate(DefaultEnumValue,'-',''),$lcletters, $ucletters)"/>
Expand All @@ -151,49 +134,22 @@ class </xsl:text><xsl:value-of select="$enum-class-name"/>
<xsl:text>

@classmethod
def version(cls, value: Optional[str] = None) -> str:
if value is None:
return "</xsl:text><xsl:value-of select="$enum-version"/><xsl:text>"
if not isinstance(value, str):
raise TypeError("This method applies to strings, not enums")
if value not in value_to_version:
raise ValueError(f"Unknown enum value: {value}")
return value_to_version[value]
def values(cls) -> List[str]:
return [elt.value for elt in cls]

@classmethod
def enum_name(cls) -> str:
"""
The name in the GridWorks Type Registry (</xsl:text><xsl:value-of select="$enum-name"/><xsl:text>)
"""
return "</xsl:text>
<xsl:value-of select="$enum-name"/>
<xsl:text>"

@classmethod
def enum_version(cls) -> str:
"""
The version in the GridWorks Type Registry (</xsl:text><xsl:value-of select="$enum-version"/><xsl:text>)
"""
return "</xsl:text>
<xsl:value-of select="$enum-version"/>
<xsl:text>"
<xsl:text>"</xsl:text>


value_to_version = {</xsl:text>
<xsl:for-each select="$airtable//EnumSymbols/EnumSymbol[(Enum = $enum-id) and (Version &lt;= $enum-version)]">
<xsl:sort select="Idx" data-type="number"/>
<xsl:text>
"</xsl:text>
<xsl:if test="$enum-type = 'Upper'">
<xsl:value-of select="translate(translate(LocalValue,'-',''),$lcletters, $ucletters)"/>
</xsl:if>
<xsl:if test="$enum-type ='UpperPython'">
<xsl:value-of select="LocalValue"/>
</xsl:if>
<xsl:text>": "</xsl:text> <xsl:value-of select="Version"/><xsl:text>",</xsl:text>
</xsl:for-each>
<xsl:text>
}</xsl:text>

<!-- Add newline at EOF for git and pre-commit-->
<xsl:text>&#10;</xsl:text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes" />
<xsl:param name="root" />
<xsl:param name="codee-root" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes" />
<xsl:param name="root" />
<xsl:param name="codee-root" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,10 @@ def test_</xsl:text> <xsl:value-of select="translate(LocalName,'.','_')"/>
<xsl:text>
assert </xsl:text><xsl:value-of select="$local-class-name"/><xsl:text>.enum_version() == "</xsl:text>
<xsl:value-of select="$version"/>
<xsl:text>"
</xsl:text>


<xsl:for-each select="$airtable//EnumSymbols/EnumSymbol[(Enum = $enum-id) and (Version &lt;= $version)]">
<xsl:sort select="Idx" data-type="number"/>
<xsl:text>
assert </xsl:text><xsl:value-of select="$local-class-name"/><xsl:text>.version("</xsl:text>
<xsl:if test="$enum-type = 'Upper'">
<xsl:value-of select="translate(translate(LocalValue,'-',''),$lcletters, $ucletters)"/>
</xsl:if>
<xsl:if test="$enum-type ='UpperPython'">
<xsl:value-of select="LocalValue"/>
</xsl:if>
<xsl:text>") == "</xsl:text>
<xsl:value-of select="Version"/>
<xsl:text>"</xsl:text>
</xsl:for-each>
</xsl:if>


<!-- Add newline at EOF for git and pre-commit-->
<xsl:text>&#10;</xsl:text>

Expand Down
1,184 changes: 1,183 additions & 1 deletion CodeGenerationTools/GridworksCore/ODXML/DataSchema.odxml

Large diffs are not rendered by default.

Loading

0 comments on commit 2425f7d

Please sign in to comment.