python-materialsdb 0.0.1__tar.gz → 0.1.0__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.
Files changed (28) hide show
  1. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/PKG-INFO +23 -8
  2. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/README.md +15 -3
  3. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/pyproject.toml +5 -1
  4. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/setup.cfg +2 -1
  5. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/cache.py +42 -17
  6. python_materialsdb-0.1.0/src/materialsdb/ifc/material_psets.json +582 -0
  7. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/ifc/project_library.py +13 -64
  8. python_materialsdb-0.1.0/src/materialsdb/query.py +24 -0
  9. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/serialiser.py +25 -2
  10. python_materialsdb-0.1.0/src/materialsdb/store.py +290 -0
  11. python_materialsdb-0.1.0/src/materialsdb/summary.py +75 -0
  12. python_materialsdb-0.1.0/src/materialsdb/utils.py +95 -0
  13. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/python_materialsdb.egg-info/PKG-INFO +23 -8
  14. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/python_materialsdb.egg-info/SOURCES.txt +10 -1
  15. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/python_materialsdb.egg-info/requires.txt +3 -0
  16. python_materialsdb-0.1.0/tests/test_project_library.py +14 -0
  17. python_materialsdb-0.1.0/tests/test_query.py +34 -0
  18. python_materialsdb-0.1.0/tests/test_serialiser.py +65 -0
  19. python_materialsdb-0.1.0/tests/test_store.py +109 -0
  20. python_materialsdb-0.1.0/tests/test_summary.py +41 -0
  21. python-materialsdb-0.0.1/src/materialsdb/utils.py +0 -20
  22. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/LICENSE.md +0 -0
  23. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/__init__.py +0 -0
  24. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/classes.py +0 -0
  25. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/config.py +0 -0
  26. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/materialsdb/ifc/__init__.py +0 -0
  27. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/python_materialsdb.egg-info/dependency_links.txt +0 -0
  28. {python-materialsdb-0.0.1 → python_materialsdb-0.1.0}/src/python_materialsdb.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: python-materialsdb
3
- Version: 0.0.1
3
+ Version: 0.1.0
4
4
  Summary: A library to work with materialsdb.org open standard for building materials.
5
5
  Home-page: https://github.com/CyrilWaechter/python-materialsdb
6
6
  Author: Cyril Waechter
@@ -9,15 +9,19 @@ License: GPLv3+
9
9
  Project-URL: Bug Tracker, https://github.com/CyrilWaechter/python-materialsdb/issues
10
10
  Project-URL: Community, https://community.osarch.org/
11
11
  Keywords: materials,BIM,ifcopenshell,IFC
12
- Platform: UNKNOWN
13
12
  Classifier: Programming Language :: Python :: 3
14
13
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
16
  Classifier: Topic :: Scientific/Engineering
18
17
  Description-Content-Type: text/markdown
19
- Provides-Extra: ifc
20
18
  License-File: LICENSE.md
19
+ Requires-Dist: lxml
20
+ Provides-Extra: ifc
21
+ Requires-Dist: ifcopenshell; extra == "ifc"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest-benchmark; extra == "dev"
24
+ Dynamic: license-file
21
25
 
22
26
  python-materialsdb is an unofficial python library for [materialsdb.org][1] an open format and database for building materials.
23
27
 
@@ -46,9 +50,21 @@ Note: in materialsdb standard languages are [ISO 639-1](https://en.wikipedia.org
46
50
 
47
51
  # Usage examples :
48
52
  Check out some [examples](examples):
49
- * [Convert lastest materials data to ifc](examples/generate_ifc_project_libraries.py)
53
+ * [Convert latest materials data to ifc](examples/generate_ifc_project_libraries.py)
50
54
  * [Create your own materialsdb.org compliant XML](examples/create_layers.py)
51
55
 
56
+ # Querying materials :
57
+ The library keeps an sqlite index of the cached materials data for fast
58
+ filtering and single-material access:
59
+
60
+ ```python
61
+ from materialsdb import query
62
+
63
+ query.refresh() # incremental update from cached xml
64
+ rows = query.search("isolant", sort="lambda") # filtered, sorted summaries
65
+ material = query.get_material(rows[0].id) # full material dataclass
66
+ ```
67
+
52
68
  # How to install
53
69
  ## Using pip
54
70
  ```bash
@@ -56,8 +72,8 @@ pip install python-materialsdb
56
72
  ```
57
73
 
58
74
  # Dependencies
59
- * [lxml][2] (BSD) : xml parser
60
- * [ifcopenshell][3] (LGPL) : ifc read/write
75
+ * [lxml][2] (BSD) : xml parser (tested with version 6.1.1)
76
+ * [ifcopenshell][3] (LGPL) : ifc read/write (tested with version 0.8.5)
61
77
 
62
78
  # Third parties :
63
79
  * [materialsdb.org][1] (GPL) : materials schema
@@ -65,4 +81,3 @@ pip install python-materialsdb
65
81
  [1]: http://www.materialsdb.org
66
82
  [2]: https://lxml.de
67
83
  [3]: ifcopenshell.org
68
-
@@ -25,9 +25,21 @@ Note: in materialsdb standard languages are [ISO 639-1](https://en.wikipedia.org
25
25
 
26
26
  # Usage examples :
27
27
  Check out some [examples](examples):
28
- * [Convert lastest materials data to ifc](examples/generate_ifc_project_libraries.py)
28
+ * [Convert latest materials data to ifc](examples/generate_ifc_project_libraries.py)
29
29
  * [Create your own materialsdb.org compliant XML](examples/create_layers.py)
30
30
 
31
+ # Querying materials :
32
+ The library keeps an sqlite index of the cached materials data for fast
33
+ filtering and single-material access:
34
+
35
+ ```python
36
+ from materialsdb import query
37
+
38
+ query.refresh() # incremental update from cached xml
39
+ rows = query.search("isolant", sort="lambda") # filtered, sorted summaries
40
+ material = query.get_material(rows[0].id) # full material dataclass
41
+ ```
42
+
31
43
  # How to install
32
44
  ## Using pip
33
45
  ```bash
@@ -35,8 +47,8 @@ pip install python-materialsdb
35
47
  ```
36
48
 
37
49
  # Dependencies
38
- * [lxml][2] (BSD) : xml parser
39
- * [ifcopenshell][3] (LGPL) : ifc read/write
50
+ * [lxml][2] (BSD) : xml parser (tested with version 6.1.1)
51
+ * [ifcopenshell][3] (LGPL) : ifc read/write (tested with version 0.8.5)
40
52
 
41
53
  # Third parties :
42
54
  * [materialsdb.org][1] (GPL) : materials schema
@@ -7,4 +7,8 @@ build-backend = "setuptools.build_meta"
7
7
  [tool.pytest.ini_options]
8
8
  testpaths = [
9
9
  "tests",
10
- ]
10
+ ]
11
+ markers = [
12
+ "benchmark: performance benchmarks (deselected by default)",
13
+ ]
14
+ addopts = "-m 'not benchmark'"
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = python-materialsdb
3
- version = 0.0.1
3
+ version = 0.1.0
4
4
  author = Cyril Waechter
5
5
  author_email = cyrwae@hotmail.com
6
6
  description = A library to work with materialsdb.org open standard for building materials.
@@ -35,6 +35,7 @@ where = src
35
35
 
36
36
  [options.extras_require]
37
37
  ifc = ifcopenshell
38
+ dev = pytest-benchmark
38
39
 
39
40
  [egg_info]
40
41
  tag_build =
@@ -1,10 +1,14 @@
1
1
  import os
2
2
  import pathlib
3
3
  import urllib.request
4
+ from collections import namedtuple
4
5
  from typing import Optional
5
6
  from lxml import etree
6
7
 
7
- MATERIALSDBINDEXURL = "http://www.materialsdb.org/download/ProducerIndex.xml"
8
+ MATERIALSDBINDEXURLLIST = [
9
+ "http://www.materialsdb.org/download/ProducerIndex.xml",
10
+ "http://www.materialsdb.org/download/generic/GenericIndex.xml",
11
+ ]
8
12
 
9
13
 
10
14
  def get_cache_folder():
@@ -19,12 +23,12 @@ def get_cache_folder():
19
23
  return cache_dir
20
24
 
21
25
 
22
- def get_cached_index_path() -> pathlib.Path:
23
- return get_cache_folder() / "ProducerIndex.xml"
26
+ def get_cached_index_path(index) -> pathlib.Path:
27
+ return get_cache_folder() / pathlib.Path(index).name
24
28
 
25
29
 
26
- def parse_cached_index() -> etree._ElementTree:
27
- path = get_cached_index_path()
30
+ def parse_cached_index(index) -> etree._ElementTree:
31
+ path = get_cached_index_path(index)
28
32
  if path.exists():
29
33
  return etree.parse(str(path))
30
34
  root = etree.Element("root")
@@ -53,27 +57,48 @@ def get_producers_dir() -> pathlib.Path:
53
57
  return producer_path
54
58
 
55
59
 
56
- def update_producers_data():
57
- cached_index = parse_cached_index()
60
+ Report = namedtuple("Report", ["existing", "updated", "deleted"])
61
+
62
+
63
+ def update_producers_data(url_list=MATERIALSDBINDEXURLLIST):
64
+ existing = []
65
+ updated = []
66
+ deleted = []
67
+ for index in url_list:
68
+ report = update_producers_from_index(index)
69
+ existing.extend(report.existing)
70
+ updated.extend(report.updated)
71
+ deleted.extend(report.deleted)
72
+ return Report(existing, updated, deleted)
73
+
74
+
75
+ def update_producers_from_index(index):
76
+ cached_index = parse_cached_index(index)
58
77
  cached_root = cached_index.getroot()
59
- new_index = etree.parse(MATERIALSDBINDEXURL)
78
+ with urllib.request.urlopen(index) as response:
79
+ new_index = etree.parse(response)
60
80
  new_root = new_index.getroot()
61
81
  producers_dir = get_producers_dir()
62
82
  has_index_update = False
83
+ existing = []
84
+ updated = []
85
+ deleted = []
63
86
  for company in new_root:
64
- cached_company = get_by_id(cached_root, company.get("id"))
65
- if (
66
- not require_update(cached_company, company)
67
- and (producers_dir / pathlib.Path(company.get("href")).name).exists()
68
- ):
87
+ cached_producer = get_by_id(cached_root, company.get("id"))
88
+ producer_path = producers_dir / pathlib.Path(company.get("href")).name
89
+ if not require_update(cached_producer, company) and producer_path.exists():
90
+ existing.append(producer_path)
69
91
  continue
70
- if cached_company:
71
- (producers_dir / pathlib.Path(cached_company.get("href")).name).unlink(True)
92
+ if cached_producer:
93
+ cached_path = producers_dir / pathlib.Path(cached_producer.get("href")).name
94
+ deleted.append(cached_path)
95
+ cached_path.unlink(True)
72
96
  has_index_update = True
73
- producer_path = producers_dir / pathlib.Path(company.get("href")).name
74
97
  urllib.request.urlretrieve(company.get("href"), producer_path)
98
+ updated.append(producer_path)
75
99
  if has_index_update:
76
- new_index.write(str(get_cached_index_path()))
100
+ new_index.write(str(get_cached_index_path(index)))
101
+ return Report(existing, updated, deleted)
77
102
 
78
103
 
79
104
  def producers():