Skip to content

Commit

Permalink
adding uri and their tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-gauthier-geosiris committed Jun 13, 2024
1 parent 9eefdde commit 36e3855
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 132 deletions.
16 changes: 8 additions & 8 deletions energyml-utils/docs/src/energyml/utils/manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
import re
from typing import List, Union, Any

REGEX_ENERGYML_MODULE_NAME = r&#34;energyml\.(?P&lt;pkg&gt;.*)\.v(?P&lt;version&gt;(?P&lt;versionNumber&gt;\d+(_\d+)*)(_dev(?P&lt;versionDev&gt;.*))?)\..*&#34;
REGEX_PROJECT_VERSION = r&#34;(?P&lt;n0&gt;[\d]+)(.(?P&lt;n1&gt;[\d]+)(.(?P&lt;n2&gt;[\d]+))?)?&#34;
RGX_ENERGYML_MODULE_NAME = r&#34;energyml\.(?P&lt;pkg&gt;.*)\.v(?P&lt;version&gt;(?P&lt;versionNumber&gt;\d+(_\d+)*)(_dev(?P&lt;versionDev&gt;.*))?)\..*&#34;
RGX_PROJECT_VERSION = r&#34;(?P&lt;n0&gt;[\d]+)(.(?P&lt;n1&gt;[\d]+)(.(?P&lt;n2&gt;[\d]+))?)?&#34;

ENERGYML_MODULES_NAMES = [&#34;eml&#34;, &#34;prodml&#34;, &#34;witsml&#34;, &#34;resqml&#34;]

Expand Down Expand Up @@ -196,7 +196,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>

def get_class_pkg(cls):
try:
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(cls.__module__)
return m.group(&#34;pkg&#34;)
except AttributeError as e:
Expand All @@ -210,7 +210,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
else, the original version is returned.
Example : reshapeVersion(&#34;v2.0.1&#34;, 2) ==&gt; &#34;2.0&#34; and reshapeVersion(&#34;version2.0.1.3.2.5&#34;, 4) ==&gt; &#34;version2.0.1.3.2.5&#34;
&#34;&#34;&#34;
p = re.compile(REGEX_PROJECT_VERSION)
p = re.compile(RGX_PROJECT_VERSION)
m = p.search(version)
if m is not None:
n0 = m.group(&#34;n0&#34;)
Expand All @@ -233,7 +233,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
def get_class_pkg_version(
cls, print_dev_version: bool = True, nb_max_version_digits: int = 2
):
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(
cls.__module__ if isinstance(cls, type) else type(cls).__module__
)
Expand Down Expand Up @@ -364,7 +364,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</summary>
<pre><code class="python">def get_class_pkg(cls):
try:
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(cls.__module__)
return m.group(&#34;pkg&#34;)
except AttributeError as e:
Expand All @@ -384,7 +384,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<pre><code class="python">def get_class_pkg_version(
cls, print_dev_version: bool = True, nb_max_version_digits: int = 2
):
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(
cls.__module__ if isinstance(cls, type) else type(cls).__module__
)
Expand Down Expand Up @@ -554,7 +554,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
else, the original version is returned.
Example : reshapeVersion(&#34;v2.0.1&#34;, 2) ==&gt; &#34;2.0&#34; and reshapeVersion(&#34;version2.0.1.3.2.5&#34;, 4) ==&gt; &#34;version2.0.1.3.2.5&#34;
&#34;&#34;&#34;
p = re.compile(REGEX_PROJECT_VERSION)
p = re.compile(RGX_PROJECT_VERSION)
m = p.search(version)
if m is not None:
n0 = m.group(&#34;n0&#34;)
Expand Down
56 changes: 28 additions & 28 deletions energyml-utils/docs/src/energyml/utils/xml.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,46 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>
dict of all energyml namespace packages
&#34;&#34;&#34; # pylint: disable=W0105

REGEX_UUID_NO_GRP = (
RGX_UUID_NO_GRP = (
r&#34;[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}&#34;
)
REGEX_UUID = r&#34;(?P&lt;uuid&gt;&#34; + REGEX_UUID_NO_GRP + &#34;)&#34;
REGEX_DOMAIN_VERSION = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNum&gt;([\d]+[\._])*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
REGEX_DOMAIN_VERSION_FLAT = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNumFlat&gt;([\d]+)*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
RGX_UUID = r&#34;(?P&lt;uuid&gt;&#34; + RGX_UUID_NO_GRP + &#34;)&#34;
RGX_DOMAIN_VERSION = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNum&gt;([\d]+[\._])*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
RGX_DOMAIN_VERSION_FLAT = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNumFlat&gt;([\d]+)*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;


# ContentType
REGEX_MIME_TYPE_MEDIA = r&#34;(?P&lt;media&gt;application|audio|font|example|image|message|model|multipart|text|video)&#34;
REGEX_CT_ENERGYML_DOMAIN = r&#34;(?P&lt;energymlDomain&gt;x-(?P&lt;domain&gt;[\w]+)\+xml)&#34;
REGEX_CT_XML_DOMAIN = r&#34;(?P&lt;xmlRawDomain&gt;(x\-)?(?P&lt;xmlDomain&gt;.+)\+xml)&#34;
REGEX_CT_TOKEN_VERSION = r&#34;version=&#34; + REGEX_DOMAIN_VERSION
REGEX_CT_TOKEN_TYPE = r&#34;type=(?P&lt;type&gt;[\w\_]+)&#34;

REGEX_CONTENT_TYPE = (
REGEX_MIME_TYPE_MEDIA + &#34;/&#34;
+ &#34;(?P&lt;rawDomain&gt;(&#34; + REGEX_CT_ENERGYML_DOMAIN + &#34;)|(&#34; + REGEX_CT_XML_DOMAIN + r&#34;)|([\w-]+\.?)+)&#34;
+ &#34;(;((&#34; + REGEX_CT_TOKEN_VERSION + &#34;)|(&#34; + REGEX_CT_TOKEN_TYPE + &#34;)))*&#34;
RGX_MIME_TYPE_MEDIA = r&#34;(?P&lt;media&gt;application|audio|font|example|image|message|model|multipart|text|video)&#34;
RGX_CT_ENERGYML_DOMAIN = r&#34;(?P&lt;energymlDomain&gt;x-(?P&lt;domain&gt;[\w]+)\+xml)&#34;
RGX_CT_XML_DOMAIN = r&#34;(?P&lt;xmlRawDomain&gt;(x\-)?(?P&lt;xmlDomain&gt;.+)\+xml)&#34;
RGX_CT_TOKEN_VERSION = r&#34;version=&#34; + RGX_DOMAIN_VERSION
RGX_CT_TOKEN_TYPE = r&#34;type=(?P&lt;type&gt;[\w\_]+)&#34;

RGX_CONTENT_TYPE = (
RGX_MIME_TYPE_MEDIA + &#34;/&#34;
+ &#34;(?P&lt;rawDomain&gt;(&#34; + RGX_CT_ENERGYML_DOMAIN + &#34;)|(&#34; + RGX_CT_XML_DOMAIN + r&#34;)|([\w-]+\.?)+)&#34;
+ &#34;(;((&#34; + RGX_CT_TOKEN_VERSION + &#34;)|(&#34; + RGX_CT_TOKEN_TYPE + &#34;)))*&#34;
)
REGEX_QUALIFIED_TYPE = (
r&#34;(?P&lt;domain&gt;[a-zA-Z]+)&#34; + REGEX_DOMAIN_VERSION_FLAT + r&#34;\.(?P&lt;type&gt;[\w_]+)&#34;
RGX_QUALIFIED_TYPE = (
r&#34;(?P&lt;domain&gt;[a-zA-Z]+)&#34; + RGX_DOMAIN_VERSION_FLAT + r&#34;\.(?P&lt;type&gt;[\w_]+)&#34;
)
# =========

REGEX_SCHEMA_VERSION = (
RGX_SCHEMA_VERSION = (
r&#34;(?P&lt;name&gt;[eE]ml|[cC]ommon|[rR]esqml|[wW]itsml|[pP]rodml)?\s*v?&#34;
+ REGEX_DOMAIN_VERSION
+ RGX_DOMAIN_VERSION
+ r&#34;\s*$&#34;
)

REGEX_ENERGYML_FILE_NAME_OLD = r&#34;(?P&lt;type&gt;[\w]+)_&#34; + REGEX_UUID_NO_GRP + r&#34;\.xml$&#34;
REGEX_ENERGYML_FILE_NAME_NEW = (
REGEX_UUID_NO_GRP + r&#34;\.(?P&lt;objectVersion&gt;\d+(\.\d+)*)\.xml$&#34;
RGX_ENERGYML_FILE_NAME_OLD = r&#34;(?P&lt;type&gt;[\w]+)_&#34; + RGX_UUID_NO_GRP + r&#34;\.xml$&#34;
RGX_ENERGYML_FILE_NAME_NEW = (
RGX_UUID_NO_GRP + r&#34;\.(?P&lt;objectVersion&gt;\d+(\.\d+)*)\.xml$&#34;
)
REGEX_ENERGYML_FILE_NAME = (
rf&#34;^(.*/)?({REGEX_ENERGYML_FILE_NAME_OLD})|({REGEX_ENERGYML_FILE_NAME_NEW})&#34;
RGX_ENERGYML_FILE_NAME = (
rf&#34;^(.*/)?({RGX_ENERGYML_FILE_NAME_OLD})|({RGX_ENERGYML_FILE_NAME_NEW})&#34;
)

REGEX_XML_HEADER = r&#34;^\s*\&lt;\?xml\s+((encoding\s*=\s*\&#34;(?P&lt;encoding&gt;[^\&#34;]+)\&#34;|version\s*=\s*\&#34;(?P&lt;version&gt;[^\&#34;]+)\&#34;|standalone\s*=\s*\&#34;(?P&lt;standalone&gt;[^\&#34;]+)\&#34;)\s+)+&#34;
RGX_XML_HEADER = r&#34;^\s*\&lt;\?xml\s+((encoding\s*=\s*\&#34;(?P&lt;encoding&gt;[^\&#34;]+)\&#34;|version\s*=\s*\&#34;(?P&lt;version&gt;[^\&#34;]+)\&#34;|standalone\s*=\s*\&#34;(?P&lt;standalone&gt;[^\&#34;]+)\&#34;)\s+)+&#34;


def get_pkg_from_namespace(namespace: str) -&gt; Optional[str]:
Expand Down Expand Up @@ -138,7 +138,7 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>

def get_xml_encoding(xml_content: str) -&gt; Optional[str]:
try:
m = re.search(REGEX_XML_HEADER, xml_content)
m = re.search(RGX_XML_HEADER, xml_content)
return m.group(&#34;encoding&#34;)
except AttributeError:
return &#34;utf-8&#34;
Expand Down Expand Up @@ -207,7 +207,7 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>


def parse_content_type(ct: str):
return re.search(REGEX_CONTENT_TYPE, ct)</code></pre>
return re.search(RGX_CONTENT_TYPE, ct)</code></pre>
</details>
</section>
<section>
Expand Down Expand Up @@ -402,7 +402,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</summary>
<pre><code class="python">def get_xml_encoding(xml_content: str) -&gt; Optional[str]:
try:
m = re.search(REGEX_XML_HEADER, xml_content)
m = re.search(RGX_XML_HEADER, xml_content)
return m.group(&#34;encoding&#34;)
except AttributeError:
return &#34;utf-8&#34;</code></pre>
Expand Down Expand Up @@ -432,7 +432,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def parse_content_type(ct: str):
return re.search(REGEX_CONTENT_TYPE, ct)</code></pre>
return re.search(RGX_CONTENT_TYPE, ct)</code></pre>
</details>
</dd>
<dt id="src.energyml.utils.xml.search_element_has_child_xpath"><code class="name flex">
Expand Down
2 changes: 1 addition & 1 deletion energyml-utils/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def file_test():


def tests_content_type():
print(REGEX_CONTENT_TYPE)
print(RGX_CONTENT_TYPE)

print(
parse_content_type(
Expand Down
4 changes: 2 additions & 2 deletions energyml-utils/example/main_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from src.energyml.utils.manager import get_sub_classes
from src.energyml.utils.serialization import read_energyml_xml_file, read_energyml_xml_str, read_energyml_xml_bytes
from src.energyml.utils.validation import validate_epc
from src.energyml.utils.xml import REGEX_CONTENT_TYPE
from src.energyml.utils.xml import RGX_CONTENT_TYPE


def test_array():
Expand Down Expand Up @@ -428,7 +428,7 @@ def read_unreferenced_h5_file():
#
# read_h5_grid2d()
# read_h5_grid2d_bis()
# print(REGEX_CONTENT_TYPE)
# print(RGX_CONTENT_TYPE)
#
# read_meshes()
#
Expand Down
121 changes: 121 additions & 0 deletions energyml-utils/src/energyml/utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

ENERGYML_NAMESPACES = {
"eml": "http://www.energistics.org/energyml/data/commonv2",
"prodml": "http://www.energistics.org/energyml/data/prodmlv2",
"witsml": "http://www.energistics.org/energyml/data/witsmlv2",
"resqml": "http://www.energistics.org/energyml/data/resqmlv2",
}
"""
dict of all energyml namespaces
""" # pylint: disable=W0105

ENERGYML_NAMESPACES_PACKAGE = {
"eml": ["http://www.energistics.org/energyml/data/commonv2"],
"prodml": ["http://www.energistics.org/energyml/data/prodmlv2"],
"witsml": ["http://www.energistics.org/energyml/data/witsmlv2"],
"resqml": ["http://www.energistics.org/energyml/data/resqmlv2"],
"opc": [
"http://schemas.openxmlformats.org/package/2006/content-types",
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
],
}
"""
dict of all energyml namespace packages
""" # pylint: disable=W0105

RGX_ENERGYML_MODULE_NAME = r"energyml\.(?P<pkg>.*)\.v(?P<version>(?P<versionNumber>\d+(_\d+)*)(_dev(?P<versionDev>.*))?)\..*"
RGX_PROJECT_VERSION = r"(?P<n0>[\d]+)(.(?P<n1>[\d]+)(.(?P<n2>[\d]+))?)?"

ENERGYML_MODULES_NAMES = ["eml", "prodml", "witsml", "resqml"]

RELATED_MODULES = [
["energyml.eml.v2_0.commonv2", "energyml.resqml.v2_0_1.resqmlv2"],
[
"energyml.eml.v2_1.commonv2",
"energyml.prodml.v2_0.prodmlv2",
"energyml.witsml.v2_0.witsmlv2",
],
["energyml.eml.v2_2.commonv2", "energyml.resqml.v2_2_dev3.resqmlv2"],
[
"energyml.eml.v2_3.commonv2",
"energyml.resqml.v2_2.resqmlv2",
"energyml.prodml.v2_2.prodmlv2",
"energyml.witsml.v2_1.witsmlv2",
],
]

RGX_UUID_NO_GRP = (
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
)
RGX_UUID = r"(?P<uuid>" + RGX_UUID_NO_GRP + ")"
RGX_DOMAIN_VERSION = r"(?P<domainVersion>(?P<versionNum>([\d]+[\._])*\d)\s*(?P<dev>dev\s*(?P<devNum>[\d]+))?)"
RGX_DOMAIN_VERSION_FLAT = r"(?P<domainVersion>(?P<versionNumFlat>([\d]+)*\d)\s*(?P<dev>dev\s*(?P<devNum>[\d]+))?)"


# ContentType
RGX_MIME_TYPE_MEDIA = r"(?P<media>application|audio|font|example|image|message|model|multipart|text|video)"
RGX_CT_ENERGYML_DOMAIN = r"(?P<energymlDomain>x-(?P<domain>[\w]+)\+xml)"
RGX_CT_XML_DOMAIN = r"(?P<xmlRawDomain>(x\-)?(?P<xmlDomain>.+)\+xml)"
RGX_CT_TOKEN_VERSION = r"version=" + RGX_DOMAIN_VERSION
RGX_CT_TOKEN_TYPE = r"type=(?P<type>[\w\_]+)"

RGX_CONTENT_TYPE = (
RGX_MIME_TYPE_MEDIA + "/"
+ "(?P<rawDomain>(" + RGX_CT_ENERGYML_DOMAIN + ")|(" + RGX_CT_XML_DOMAIN + r")|([\w-]+\.?)+)"
+ "(;((" + RGX_CT_TOKEN_VERSION + ")|(" + RGX_CT_TOKEN_TYPE + ")))*"
)
RGX_QUALIFIED_TYPE = (
r"(?P<domain>[a-zA-Z]+)" + RGX_DOMAIN_VERSION_FLAT + r"\.(?P<type>[\w_]+)"
)
# =========

RGX_SCHEMA_VERSION = (
r"(?P<name>[eE]ml|[cC]ommon|[rR]esqml|[wW]itsml|[pP]rodml|[oO]pc)?\s*v?"
+ RGX_DOMAIN_VERSION
+ r"\s*$"
)

RGX_ENERGYML_FILE_NAME_OLD = r"(?P<type>[\w]+)_" + RGX_UUID_NO_GRP + r"\.xml$"
RGX_ENERGYML_FILE_NAME_NEW = (
RGX_UUID_NO_GRP + r"\.(?P<objectVersion>\d+(\.\d+)*)\.xml$"
)
RGX_ENERGYML_FILE_NAME = (
rf"^(.*/)?({RGX_ENERGYML_FILE_NAME_OLD})|({RGX_ENERGYML_FILE_NAME_NEW})"
)

RGX_XML_HEADER = r"^\s*<\?xml(\s+(encoding\s*=\s*\"(?P<encoding>[^\"]+)\"|version\s*=\s*\"(?P<version>[^\"]+)\"|standalone\s*=\s*\"(?P<standalone>[^\"]+)\"))+"

# __ ______ ____
# / / / / __ \/ _/
# / / / / /_/ // /
# / /_/ / _, _// /
# \____/_/ |_/___/

URI_RGX_GRP_DOMAIN = "domain"
URI_RGX_GRP_DOMAIN_VERSION = "domainVersion"
URI_RGX_GRP_UUID = "uuid"
URI_RGX_GRP_DATASPACE = "dataspace"
URI_RGX_GRP_VERSION = "version"
URI_RGX_GRP_OBJECT_TYPE = "objectType"
URI_RGX_GRP_UUID2 = "uuid2"
URI_RGX_GRP_COLLECTION_DOMAIN = "collectionDomain"
URI_RGX_GRP_COLLECTION_DOMAIN_VERSION = "collectionDomainVersion"
URI_RGX_GRP_COLLECTION_TYPE = "collectionType"
URI_RGX_GRP_QUERY = "query"

# Patterns
_uri_rgx_pkg_name = "|".join(ENERGYML_NAMESPACES.keys()) # "[a-zA-Z]+\w+" //witsml|resqml|prodml|eml
URI_RGX = (
r"^eml:\/\/\/(?:dataspace\('(?P<" + URI_RGX_GRP_DATASPACE + r">[^']*?(?:''[^']*?)*)'\)\/?)?((?P<" + URI_RGX_GRP_DOMAIN
+ r">" + _uri_rgx_pkg_name + r")(?P<" + URI_RGX_GRP_DOMAIN_VERSION + r">[1-9]\d)\.(?P<" + URI_RGX_GRP_OBJECT_TYPE
+ r">\w+)(\((?:(?P<" + URI_RGX_GRP_UUID + r">(uuid=)?" + RGX_UUID_NO_GRP + r")|uuid=(?P<" + URI_RGX_GRP_UUID2
+ r">" + RGX_UUID_NO_GRP + r"),\s*version='(?P<" + URI_RGX_GRP_VERSION + r">[^']*?(?:''[^']*?)*)')\))?)?(\/(?P<"
+ URI_RGX_GRP_COLLECTION_DOMAIN + r">" + _uri_rgx_pkg_name + r")(?P<" + URI_RGX_GRP_COLLECTION_DOMAIN_VERSION
+ r">[1-9]\d)\.(?P<" + URI_RGX_GRP_COLLECTION_TYPE + r">\w+))?(?:\?(?P<" + URI_RGX_GRP_QUERY + r">[^#]+))?$"
)

# ================================
RELS_CONTENT_TYPE = "application/vnd.openxmlformats-package.core-properties+xml"
RELS_FOLDER_NAME = "_rels"

primitives = (bool, str, int, float, type(None))
3 changes: 1 addition & 2 deletions energyml-utils/src/energyml/utils/epc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
)
from .xml import is_energyml_content_type

RELS_CONTENT_TYPE = "application/vnd.openxmlformats-package.core-properties+xml"
RELS_FOLDER_NAME = "_rels"
from .constants import RELS_CONTENT_TYPE, RELS_FOLDER_NAME


class EpcExportVersion(Enum):
Expand Down
2 changes: 1 addition & 1 deletion energyml-utils/src/energyml/utils/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
get_related_energyml_modules_name, get_sub_classes, get_classes_matching_name, dict_energyml_modules
from .xml import parse_content_type, ENERGYML_NAMESPACES, parse_qualified_type

primitives = (bool, str, int, float, type(None))
from .constants import primitives


def is_enum(cls: Union[type, Any]):
Expand Down
27 changes: 4 additions & 23 deletions energyml-utils/src/energyml/utils/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,7 @@
import re
from typing import List, Union, Any

REGEX_ENERGYML_MODULE_NAME = r"energyml\.(?P<pkg>.*)\.v(?P<version>(?P<versionNumber>\d+(_\d+)*)(_dev(?P<versionDev>.*))?)\..*"
REGEX_PROJECT_VERSION = r"(?P<n0>[\d]+)(.(?P<n1>[\d]+)(.(?P<n2>[\d]+))?)?"

ENERGYML_MODULES_NAMES = ["eml", "prodml", "witsml", "resqml"]

RELATED_MODULES = [
["energyml.eml.v2_0.commonv2", "energyml.resqml.v2_0_1.resqmlv2"],
[
"energyml.eml.v2_1.commonv2",
"energyml.prodml.v2_0.prodmlv2",
"energyml.witsml.v2_0.witsmlv2",
],
["energyml.eml.v2_2.commonv2", "energyml.resqml.v2_2_dev3.resqmlv2"],
[
"energyml.eml.v2_3.commonv2",
"energyml.resqml.v2_2.resqmlv2",
"energyml.prodml.v2_2.prodmlv2",
"energyml.witsml.v2_1.witsmlv2",
],
]
from .constants import *


def get_related_energyml_modules_name(cls: Union[type, Any]) -> List[str]:
Expand Down Expand Up @@ -168,7 +149,7 @@ def get_all_classes(module_name: str, version: str) -> dict:

def get_class_pkg(cls):
try:
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(cls.__module__)
return m.group("pkg")
except AttributeError as e:
Expand All @@ -182,7 +163,7 @@ def reshape_version(version: str, nb_digit: int) -> str:
else, the original version is returned.
Example : reshapeVersion("v2.0.1", 2) ==> "2.0" and reshapeVersion("version2.0.1.3.2.5", 4) ==> "version2.0.1.3.2.5"
"""
p = re.compile(REGEX_PROJECT_VERSION)
p = re.compile(RGX_PROJECT_VERSION)
m = p.search(version)
if m is not None:
n0 = m.group("n0")
Expand All @@ -205,7 +186,7 @@ def reshape_version(version: str, nb_digit: int) -> str:
def get_class_pkg_version(
cls, print_dev_version: bool = True, nb_max_version_digits: int = 2
):
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
class_module = None
if isinstance(cls, type):
class_module = cls.__module__
Expand Down
Loading

0 comments on commit 36e3855

Please sign in to comment.