commonlib-reader 1.1.1__tar.gz → 1.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.3
2
+ Name: commonlib-reader
3
+ Version: 1.1.3
4
+ Summary: Reader for Equinor commonlib api.
5
+ Author: Åsmund Våge Fannemel
6
+ Author-email: Åsmund Våge Fannemel <asmf@equinor.com>
7
+ License: MIT
8
+ Requires-Dist: pandas>=2.1.4
9
+ Requires-Dist: requests>=2.32.4
10
+ Requires-Dist: urllib3>=2.5.0
11
+ Requires-Dist: eq-api-connector>=1.0.0,<2.0.0
12
+ Requires-Python: >=3.10, <4.0.0
13
+ Project-URL: Repository, https://github.com/equinor/commonlib-reader.git
14
+ Description-Content-Type: text/markdown
15
+
16
+ # commonlib-reader
17
+ Connector package for Equinor [Commonlib](https://commonlib.equinor.com/) [api](https://commonlibapi.equinor.com/swagger/index.html).
18
+
19
+ Current features:
20
+ - Reading code tables
21
+ - Getting facility data using the [Facility](commonlib_reader/facility.py) class
22
+ - [IMS source ](commonlib_reader/ims.py) lookup tables for facilities
23
+ - Getting Tag category, Tag type, Tag format, and Tag format element data. See [tag.py](commonlib_reader/tag.py)
24
+ - Getting [units of measure](commonlib_reader/ims.py) definitions.
25
+
26
+
27
+ ## Use
28
+ Try it out by running the [demo](examples/demo.py).
29
+
30
+ ## Installing
31
+
32
+ Install package from pypi using `pip install commonlib_reader`
33
+
34
+
35
+ ## Developing / testing
36
+
37
+ uv is preferred for developers. Clone and install with required packages for testing and coverage:
38
+ `uv sync`
39
+
40
+ For testing with coverage run:
41
+ `uv run pytest --cov --cov-report=html`
@@ -1,4 +1,4 @@
1
- # commonlib-reader [![SNYK dependency check](https://github.com/equinor/commonlib-reader/actions/workflows/snyk.yml/badge.svg)](https://github.com/equinor/commonlib-reader/actions/workflows/snyk.yml)
1
+ # commonlib-reader
2
2
  Connector package for Equinor [Commonlib](https://commonlib.equinor.com/) [api](https://commonlibapi.equinor.com/swagger/index.html).
3
3
 
4
4
  Current features:
@@ -19,8 +19,8 @@ Install package from pypi using `pip install commonlib_reader`
19
19
 
20
20
  ## Developing / testing
21
21
 
22
- Poetry is preferred for developers. Clone and install with required packages for testing and coverage:
23
- `poetry install`
22
+ uv is preferred for developers. Clone and install with required packages for testing and coverage:
23
+ `uv sync`
24
24
 
25
- For testing with coverage run:
26
- `poetry run pytest --cov --cov-report=html`
25
+ For testing with coverage run:
26
+ `uv run pytest --cov --cov-report=html`
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.1.1"
3
+ version = "1.1.3"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  authors = [
6
6
  { name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }
@@ -16,13 +16,13 @@ dependencies = [
16
16
  "eq-api-connector (>=1.0.0,<2.0.0)"
17
17
  ]
18
18
 
19
- [tool.poetry.group.test.dependencies]
20
- pytest = "^7.4.4"
21
- pytest-cov = "^6.0.0"
22
-
23
- [tool.poetry.group.dev.dependencies]
24
- black = "^24.1.1"
19
+ [dependency-groups]
20
+ dev = [
21
+ "pytest>=7.4.4,<8.0.0",
22
+ "pytest-cov>=7.0.0,<8.0.0",
23
+ "black>=24.1.1,<27.0.0"
24
+ ]
25
25
 
26
26
  [build-system]
27
- requires = ["poetry-core"]
28
- build-backend = "poetry.core.masonry.api"
27
+ requires = ["uv_build>=0.11.16,<0.12"]
28
+ build-backend = "uv_build"
@@ -1,17 +1,18 @@
1
1
  from commonlib_reader.utils import (
2
2
  get_code,
3
3
  get_code_param,
4
- get_disciplines,
5
4
  get_library_names,
6
5
  )
7
6
 
8
7
 
8
+ from .discipline import Discipline
9
9
  from .tag import TagType, TagCategory, TagFormat
10
10
  from .ims import IMS
11
11
  from .facility import Facility
12
12
  from .unit import Unit
13
13
 
14
14
  __all__ = [
15
+ "Discipline",
15
16
  "Facility",
16
17
  "IMS",
17
18
  "TagType",
@@ -20,6 +21,5 @@ __all__ = [
20
21
  "Unit",
21
22
  "get_code",
22
23
  "get_code_param",
23
- "get_disciplines",
24
24
  "get_library_names",
25
25
  ]
@@ -1,6 +1,6 @@
1
1
  from eq_api_connector import APIConnector
2
2
 
3
- _connector = None
3
+ _connector: APIConnector | None = None
4
4
 
5
5
 
6
6
  def get_connector() -> APIConnector:
@@ -13,17 +13,23 @@ def get_connector() -> APIConnector:
13
13
  if _connector is None:
14
14
  clientID = "728cfddd-b8e9-4ed7-b9a3-8f2fd5b8e79a"
15
15
  scopes = ["37d598fc-da0f-46bd-949f-7107918d47a5/user_impersonation"]
16
- _connector = APIConnector(client_id=clientID, scope=scopes)
17
- _connector.set_url_prod("https://commonlibapi.equinor.com/")
16
+ connector = APIConnector(client_id=clientID, scope=scopes)
17
+ connector.set_url_prod("https://commonlibapi.equinor.com/")
18
+ _connector = connector
18
19
 
19
20
  return _connector
20
21
 
21
22
 
22
- def set_connector(connector: APIConnector):
23
+ def set_connector(connector: APIConnector) -> None:
23
24
  """Set the singleton instance of the APIConnector.
24
25
 
25
26
  Args:
26
27
  connector (APIConnector): An instance of the APIConnector class.
27
28
  """
28
29
  global _connector
30
+
31
+ if not isinstance(connector, APIConnector):
32
+ raise TypeError(
33
+ f"Connector must be an instance of APIConnector, got {type(connector).__name__}."
34
+ )
29
35
  _connector = connector
@@ -0,0 +1,64 @@
1
+ from typing import List
2
+
3
+ from commonlib_reader.utils import get_code
4
+
5
+
6
+ class Discipline:
7
+ def __init__(self, data: dict):
8
+ if not isinstance(data, dict):
9
+ raise ValueError("Input data shall be dictionary.")
10
+
11
+ self._data = data
12
+
13
+ def __eq__(self, other):
14
+ if isinstance(other, Discipline):
15
+ return self._data == other._data
16
+
17
+ return False
18
+
19
+ def __str__(self):
20
+ return f"Discipline: {self.name}-{self.description}"
21
+
22
+ @property
23
+ def name(self) -> str:
24
+ return self._data.get("name", "")
25
+
26
+ @property
27
+ def description(self) -> str:
28
+ return self._data.get("description", "")
29
+
30
+ @property
31
+ def identity(self) -> str:
32
+ return self._data.get("identity", "")
33
+
34
+ @property
35
+ def is_valid(self) -> bool:
36
+ return self._data.get("isValid", False)
37
+
38
+ @classmethod
39
+ def get_all(cls, scope: str, only_valid: bool = True) -> List["Discipline"]:
40
+ """Get all disciplines for
41
+
42
+ Raises:
43
+ ValueError: _description_
44
+
45
+ Returns:
46
+ List["Discipline"]: List of discipline objects
47
+ """
48
+ dis_data = get_code("Discipline", scope=scope)
49
+
50
+ if not isinstance(dis_data, list) or not all(
51
+ isinstance(x, dict) for x in dis_data
52
+ ):
53
+ raise ValueError("Invalid discipline data from api")
54
+
55
+ if len(dis_data) == 0:
56
+ raise ValueError(
57
+ f"No discipline data found for scope {scope}. Verify that scope is correct."
58
+ )
59
+
60
+ dis = [Discipline(x) for x in dis_data] # type: ignore
61
+ if only_valid:
62
+ dis = [x for x in dis if x.is_valid]
63
+
64
+ return sorted(dis, key=lambda d: d.identity)
@@ -227,12 +227,12 @@ class Facility:
227
227
  def get_sap_facilities(cls) -> List["Facility"]:
228
228
  fac = cls.get_all_facilities()
229
229
  return [f for f in fac if len(f.sap) > 0]
230
-
230
+
231
231
  @classmethod
232
232
  def get_ioc_facilities(cls) -> List["Facility"]:
233
233
  fac = cls.get_all_facilities()
234
234
  return [f for f in fac if len(f.ioc_plant) > 0]
235
-
235
+
236
236
  @classmethod
237
237
  def get_gov_facilities(cls) -> List["Facility"]:
238
238
  fac = cls.get_all_facilities()
@@ -140,7 +140,7 @@ class TagFormat:
140
140
  def __str__(self):
141
141
  return f"{self.description} - {self.tag_category}"
142
142
 
143
- def is_valid(self, tagNo: str):
143
+ def is_valid(self, tagNo: str) -> bool:
144
144
  """Check if input tag number matches this tag format.
145
145
  Args:
146
146
  tagNo (str): Tag number to check.
@@ -148,7 +148,7 @@ class TagFormat:
148
148
  bool: True if tag number matches this tag format, else False.
149
149
  """
150
150
 
151
- return re.fullmatch(self.regex, tagNo)
151
+ return bool(re.fullmatch(self.regex, tagNo))
152
152
 
153
153
  def get_id(self) -> int:
154
154
  """Get tagformat identity.
@@ -7,15 +7,15 @@ import requests
7
7
  from commonlib_reader.connector import get_connector
8
8
 
9
9
 
10
- def get_library_names():
10
+ def get_library_names() -> list[str]:
11
11
  library_names = get_connector().get_json(url="/api/Library/NameList")
12
- if isinstance(library_names, list):
13
- library_names.sort()
14
- return library_names
12
+ if isinstance(library_names, list) and all(
13
+ [isinstance(x, str) for x in library_names]
14
+ ):
15
+ library_names.sort() # type: ignore
16
+ return library_names # type: ignore
15
17
 
16
-
17
- def get_disciplines():
18
- return get_code("Discipline")
18
+ raise ValueError("Wrong data from API when getting library names.")
19
19
 
20
20
 
21
21
  def get_code(code: str, scope: Optional[str] = None, name: Optional[str] = None):
@@ -29,6 +29,15 @@ def get_code(code: str, scope: Optional[str] = None, name: Optional[str] = None)
29
29
 
30
30
 
31
31
  def get_code_param(code, params=None):
32
+ """_summary_
33
+
34
+ Args:
35
+ code (_type_): _description_
36
+ params (_type_, optional): _description_. Defaults to None.
37
+
38
+ Returns:
39
+ _type_: _description_
40
+ """
32
41
  if params is None:
33
42
  params = {}
34
43
 
@@ -1,49 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: commonlib-reader
3
- Version: 1.1.1
4
- Summary: Reader for Equinor commonlib api.
5
- License: MIT
6
- Author: Åsmund Våge Fannemel
7
- Author-email: asmf@equinor.com
8
- Requires-Python: >=3.10,<4.0.0
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Programming Language :: Python :: 3.14
16
- Requires-Dist: eq-api-connector (>=1.0.0,<2.0.0)
17
- Requires-Dist: pandas (>=2.1.4)
18
- Requires-Dist: requests (>=2.32.4)
19
- Requires-Dist: urllib3 (>=2.5.0)
20
- Project-URL: Repository, https://github.com/equinor/commonlib-reader.git
21
- Description-Content-Type: text/markdown
22
-
23
- # commonlib-reader [![SNYK dependency check](https://github.com/equinor/commonlib-reader/actions/workflows/snyk.yml/badge.svg)](https://github.com/equinor/commonlib-reader/actions/workflows/snyk.yml)
24
- Connector package for Equinor [Commonlib](https://commonlib.equinor.com/) [api](https://commonlibapi.equinor.com/swagger/index.html).
25
-
26
- Current features:
27
- - Reading code tables
28
- - Getting facility data using the [Facility](commonlib_reader/facility.py) class
29
- - [IMS source ](commonlib_reader/ims.py) lookup tables for facilities
30
- - Getting Tag category, Tag type, Tag format, and Tag format element data. See [tag.py](commonlib_reader/tag.py)
31
- - Getting [units of measure](commonlib_reader/ims.py) definitions.
32
-
33
-
34
- ## Use
35
- Try it out by running the [demo](examples/demo.py).
36
-
37
- ## Installing
38
-
39
- Install package from pypi using `pip install commonlib_reader`
40
-
41
-
42
- ## Developing / testing
43
-
44
- Poetry is preferred for developers. Clone and install with required packages for testing and coverage:
45
- `poetry install`
46
-
47
- For testing with coverage run:
48
- `poetry run pytest --cov --cov-report=html`
49
-