compas-pb 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 (30) hide show
  1. compas_pb-0.1.0/LICENSE +21 -0
  2. compas_pb-0.1.0/PKG-INFO +139 -0
  3. compas_pb-0.1.0/README.md +77 -0
  4. compas_pb-0.1.0/pyproject.toml +149 -0
  5. compas_pb-0.1.0/requirements-dev.txt +11 -0
  6. compas_pb-0.1.0/requirements.txt +2 -0
  7. compas_pb-0.1.0/setup.cfg +4 -0
  8. compas_pb-0.1.0/src/compas_pb/__init__.py +43 -0
  9. compas_pb-0.1.0/src/compas_pb/api.py +155 -0
  10. compas_pb-0.1.0/src/compas_pb/conversions.py +151 -0
  11. compas_pb-0.1.0/src/compas_pb/core.py +364 -0
  12. compas_pb-0.1.0/src/compas_pb/generated/circle_pb2.py +37 -0
  13. compas_pb-0.1.0/src/compas_pb/generated/element_pb2.py +37 -0
  14. compas_pb-0.1.0/src/compas_pb/generated/frame_pb2.py +38 -0
  15. compas_pb-0.1.0/src/compas_pb/generated/line_pb2.py +37 -0
  16. compas_pb-0.1.0/src/compas_pb/generated/mesh_pb2.py +39 -0
  17. compas_pb-0.1.0/src/compas_pb/generated/message_pb2.py +51 -0
  18. compas_pb-0.1.0/src/compas_pb/generated/point_pb2.py +36 -0
  19. compas_pb-0.1.0/src/compas_pb/generated/vector_pb2.py +36 -0
  20. compas_pb-0.1.0/src/compas_pb/registry.py +57 -0
  21. compas_pb-0.1.0/src/compas_pb.egg-info/PKG-INFO +139 -0
  22. compas_pb-0.1.0/src/compas_pb.egg-info/SOURCES.txt +28 -0
  23. compas_pb-0.1.0/src/compas_pb.egg-info/dependency_links.txt +1 -0
  24. compas_pb-0.1.0/src/compas_pb.egg-info/not-zip-safe +1 -0
  25. compas_pb-0.1.0/src/compas_pb.egg-info/requires.txt +15 -0
  26. compas_pb-0.1.0/src/compas_pb.egg-info/top_level.txt +1 -0
  27. compas_pb-0.1.0/tests/test_mesh.py +32 -0
  28. compas_pb-0.1.0/tests/test_pb_load_dump.py +349 -0
  29. compas_pb-0.1.0/tests/test_plugin.py +47 -0
  30. compas_pb-0.1.0/tests/test_types.py +79 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Gramazio Kohler Research
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: compas_pb
3
+ Version: 0.1.0
4
+ Summary: Protobuf extension for COMPAS Data
5
+ Author-email: Wei-Ting Chen <chenwei@arch.ethz.ch>, Chen Kasirer <kasirer@arch.ethz.ch>
6
+ License: MIT License
7
+
8
+ Gramazio Kohler Research
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://gramaziokohler.github.io/compas_pb
29
+ Project-URL: Documentation, https://gramaziokohler.github.io/compas_pb
30
+ Project-URL: Repository, https://github.com/gramaziokohler/compas_pb
31
+ Project-URL: Changelog, https://github.com/gramaziokohler/compas_pb/blob/main/CHANGELOG.md
32
+ Project-URL: Issues, https://github.com/gramaziokohler/compas_pb/issues
33
+ Project-URL: Forum, https://forum.compas-framework.org/
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Topic :: Scientific/Engineering
36
+ Classifier: Operating System :: Unix
37
+ Classifier: Operating System :: POSIX
38
+ Classifier: Operating System :: Microsoft :: Windows
39
+ Classifier: Programming Language :: Python
40
+ Classifier: Programming Language :: Python :: 3
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Requires-Python: >=3.9
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: compas>=2
48
+ Requires-Dist: protobuf>=6.31.1
49
+ Provides-Extra: dev
50
+ Requires-Dist: attrs>=17.4; extra == "dev"
51
+ Requires-Dist: black>=22.12.0; extra == "dev"
52
+ Requires-Dist: bump-my-version; extra == "dev"
53
+ Requires-Dist: compas_invocations2; extra == "dev"
54
+ Requires-Dist: invoke>=0.14; extra == "dev"
55
+ Requires-Dist: ruff; extra == "dev"
56
+ Requires-Dist: sphinx_compas2_theme; extra == "dev"
57
+ Requires-Dist: twine; extra == "dev"
58
+ Requires-Dist: wheel; extra == "dev"
59
+ Requires-Dist: pytest-mock; extra == "dev"
60
+ Requires-Dist: build; extra == "dev"
61
+ Dynamic: license-file
62
+
63
+ # compas_pb
64
+
65
+ A COMPAS extension which lets you serialize and deserialize COMPAS `Data` types using protobuf.
66
+
67
+ ## Installation
68
+
69
+ Stable releases can be installed from PyPI.
70
+
71
+ ```bash
72
+ pip install compas_pb
73
+ ```
74
+
75
+ ## Basic Usage
76
+
77
+ ### Serialize to file
78
+
79
+ ```python
80
+ from compas.geometry import Vector
81
+ from compas_pb import pb_dump
82
+ from compas_pb import pb_load
83
+
84
+ PATH = "vector.data"
85
+
86
+ vector = Vector(1.0, 2.0, 3.0)
87
+
88
+ pb_dump(vector, PATH)
89
+
90
+ loaded_vector = pb_load(PATH)
91
+
92
+ ```
93
+
94
+ ### (De)serialize to bytes
95
+
96
+ ```python
97
+ from compas.geometry import Vector
98
+ from compas_pb import pb_dump_bts
99
+ from compas_pb import pb_load_bts
100
+
101
+ vector = Vector(1.0, 2.0, 3.0)
102
+
103
+ bytes_vector = pb_dump_bts(vector)
104
+
105
+ loaded_vector = pb_load_bts(bytes_vector)
106
+
107
+ ```
108
+
109
+ ### Serialization of arbitrarily nested data structures
110
+
111
+ ```python
112
+ from compas.geometry import Vector
113
+ from compas.geometry import Polyline
114
+ from compas_pb import pb_dump_bts
115
+ from compas_pb import pb_load_bts
116
+
117
+ data = {
118
+ "direction": Vector(1.0, 2.0, 3.0),
119
+ "outlines":
120
+ [
121
+ Polyline([0, 0, 0], [1, 1, 1], [2, 2, 2]),
122
+ Polyline([3, 3, 3], [4, 4, 4], [5, 5, 5])
123
+ ],
124
+ }
125
+
126
+ pb_data = pb_dump_bts(data)
127
+
128
+ loaded_data = pb_load_bts(pb_data)
129
+
130
+ ```
131
+
132
+ ## Documentation
133
+
134
+ For further "getting started" instructions, a tutorial, examples, and an API reference,
135
+ please check out the online documentation here: [compas_pb docs](https://gramaziokohler.github.io/compas_pb)
136
+
137
+ ## Issue Tracker
138
+
139
+ If you find a bug or if you have a problem with running the code, please file an issue on the [Issue Tracker](https://github.com/gramaziokohler/compas_pb/issues).
@@ -0,0 +1,77 @@
1
+ # compas_pb
2
+
3
+ A COMPAS extension which lets you serialize and deserialize COMPAS `Data` types using protobuf.
4
+
5
+ ## Installation
6
+
7
+ Stable releases can be installed from PyPI.
8
+
9
+ ```bash
10
+ pip install compas_pb
11
+ ```
12
+
13
+ ## Basic Usage
14
+
15
+ ### Serialize to file
16
+
17
+ ```python
18
+ from compas.geometry import Vector
19
+ from compas_pb import pb_dump
20
+ from compas_pb import pb_load
21
+
22
+ PATH = "vector.data"
23
+
24
+ vector = Vector(1.0, 2.0, 3.0)
25
+
26
+ pb_dump(vector, PATH)
27
+
28
+ loaded_vector = pb_load(PATH)
29
+
30
+ ```
31
+
32
+ ### (De)serialize to bytes
33
+
34
+ ```python
35
+ from compas.geometry import Vector
36
+ from compas_pb import pb_dump_bts
37
+ from compas_pb import pb_load_bts
38
+
39
+ vector = Vector(1.0, 2.0, 3.0)
40
+
41
+ bytes_vector = pb_dump_bts(vector)
42
+
43
+ loaded_vector = pb_load_bts(bytes_vector)
44
+
45
+ ```
46
+
47
+ ### Serialization of arbitrarily nested data structures
48
+
49
+ ```python
50
+ from compas.geometry import Vector
51
+ from compas.geometry import Polyline
52
+ from compas_pb import pb_dump_bts
53
+ from compas_pb import pb_load_bts
54
+
55
+ data = {
56
+ "direction": Vector(1.0, 2.0, 3.0),
57
+ "outlines":
58
+ [
59
+ Polyline([0, 0, 0], [1, 1, 1], [2, 2, 2]),
60
+ Polyline([3, 3, 3], [4, 4, 4], [5, 5, 5])
61
+ ],
62
+ }
63
+
64
+ pb_data = pb_dump_bts(data)
65
+
66
+ loaded_data = pb_load_bts(pb_data)
67
+
68
+ ```
69
+
70
+ ## Documentation
71
+
72
+ For further "getting started" instructions, a tutorial, examples, and an API reference,
73
+ please check out the online documentation here: [compas_pb docs](https://gramaziokohler.github.io/compas_pb)
74
+
75
+ ## Issue Tracker
76
+
77
+ If you find a bug or if you have a problem with running the code, please file an issue on the [Issue Tracker](https://github.com/gramaziokohler/compas_pb/issues).
@@ -0,0 +1,149 @@
1
+ [build-system]
2
+ requires = ["setuptools>=66.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ # ============================================================================
6
+ # project info
7
+ # ============================================================================
8
+
9
+ [project]
10
+ name = "compas_pb"
11
+ description = "Protobuf extension for COMPAS Data"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Wei-Ting Chen", email = "chenwei@arch.ethz.ch" },
15
+ { name = "Chen Kasirer", email = "kasirer@arch.ethz.ch" }
16
+ ]
17
+ license = { file = "LICENSE" }
18
+ readme = "README.md"
19
+ requires-python = ">=3.9"
20
+ dynamic = ['dependencies', 'optional-dependencies', 'version']
21
+ classifiers = [
22
+ "Development Status :: 4 - Beta",
23
+ "Topic :: Scientific/Engineering",
24
+ "Operating System :: Unix",
25
+ "Operating System :: POSIX",
26
+ "Operating System :: Microsoft :: Windows",
27
+ "Programming Language :: Python",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://gramaziokohler.github.io/compas_pb"
36
+ Documentation = "https://gramaziokohler.github.io/compas_pb"
37
+ Repository = "https://github.com/gramaziokohler/compas_pb"
38
+ Changelog = "https://github.com/gramaziokohler/compas_pb/blob/main/CHANGELOG.md"
39
+ Issues = "https://github.com/gramaziokohler/compas_pb/issues"
40
+ Forum = "https://forum.compas-framework.org/"
41
+
42
+ # ============================================================================
43
+ # setuptools config
44
+ # ============================================================================
45
+
46
+ [tool.setuptools]
47
+ package-dir = { "" = "src" }
48
+ include-package-data = true
49
+ zip-safe = false
50
+
51
+ [tool.setuptools.dynamic]
52
+ version = { attr = "compas_pb.__version__" }
53
+ dependencies = { file = "requirements.txt" }
54
+ optional-dependencies = { dev = { file = "requirements-dev.txt" } }
55
+
56
+ [tool.setuptools.packages.find]
57
+ where = ["src"]
58
+
59
+ # ============================================================================
60
+ # replace pytest.ini
61
+ # ============================================================================
62
+
63
+ [tool.pytest.ini_options]
64
+ minversion = "6.0"
65
+ testpaths = ["tests", "src/compas_pb"]
66
+ python_files = ["test_*.py", "*_test.py", "test.py"]
67
+ addopts = [
68
+ "-ra",
69
+ "--strict-markers",
70
+ "--doctest-glob=*.rst",
71
+ "--tb=short",
72
+ "--import-mode=importlib",
73
+ ]
74
+ doctest_optionflags = [
75
+ "NORMALIZE_WHITESPACE",
76
+ "IGNORE_EXCEPTION_DETAIL",
77
+ "ALLOW_UNICODE",
78
+ "ALLOW_BYTES",
79
+ "NUMBER",
80
+ ]
81
+
82
+ # ============================================================================
83
+ # replace bumpversion.cfg
84
+ # ============================================================================
85
+
86
+ [tool.bumpversion]
87
+ current_version = "0.1.0"
88
+ message = "Bump version to {new_version}"
89
+ commit = true
90
+ tag = true
91
+
92
+ [[tool.bumpversion.files]]
93
+ filename = "src/compas_pb/__init__.py"
94
+ search = "{current_version}"
95
+ replace = "{new_version}"
96
+
97
+ [[tool.bumpversion.files]]
98
+ filename = "CHANGELOG.md"
99
+ search = "Unreleased"
100
+ replace = "[{new_version}] {now:%Y-%m-%d}"
101
+
102
+ # ============================================================================
103
+ # linting and formatting
104
+ # ============================================================================
105
+
106
+ [tool.black]
107
+ extend-exclude = '(/[a-zA-Z\./]*[\s]?)' # exclude everything, black should be removed..
108
+
109
+ [tool.ruff]
110
+ line-length = 179
111
+ indent-width = 4
112
+ target-version = "py39"
113
+ exclude = ["src/compas_pb/generated/"]
114
+
115
+ [tool.ruff.lint]
116
+ select = ["E", "F", "I"]
117
+
118
+ [tool.ruff.lint.per-file-ignores]
119
+ "__init__.py" = ["I001"]
120
+ "tests/*" = ["I001"]
121
+ "tasks.py" = ["I001"]
122
+
123
+ [tool.isort]
124
+ line_length = 179
125
+ multi_line_output = 3
126
+ include_trailing_comma = true
127
+ force_grid_wrap = 0
128
+ use_parentheses = true
129
+ force_single_line = false
130
+ ensure_newline_before_comments = true
131
+ known_first_party = "compas_pb"
132
+ default_section = "THIRDPARTY"
133
+
134
+ forced_separate = "test_compas_pb"
135
+
136
+ [tool.ruff.lint.isort]
137
+ force-single-line = true
138
+ known-first-party = ["compas_pb"]
139
+
140
+ [tool.ruff.lint.pydocstyle]
141
+ convention = "numpy"
142
+
143
+ [tool.ruff.lint.pycodestyle]
144
+ max-doc-length = 179
145
+
146
+ [tool.ruff.format]
147
+ docstring-code-format = true
148
+ docstring-code-line-length = "dynamic"
149
+
@@ -0,0 +1,11 @@
1
+ attrs >=17.4
2
+ black >=22.12.0
3
+ bump-my-version
4
+ compas_invocations2
5
+ invoke >=0.14
6
+ ruff
7
+ sphinx_compas2_theme
8
+ twine
9
+ wheel
10
+ pytest-mock
11
+ build
@@ -0,0 +1,2 @@
1
+ compas >= 2
2
+ protobuf >=6.31.1
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,43 @@
1
+ from __future__ import print_function
2
+
3
+ import os
4
+
5
+ # please don't remove me! I trigger the registration of all the core serializers
6
+ import compas_pb.conversions # noqa: F401 #
7
+
8
+ from .api import pb_load
9
+ from .api import pb_dump
10
+ from .api import pb_dump_bts
11
+ from .api import pb_load_bts
12
+ from .api import pb_dump_json
13
+ from .api import pb_load_json
14
+
15
+
16
+ __author__ = ["Wei-Ting Chen", "Chen Kasirer"]
17
+ __copyright__ = "Gramazio Kohler Research"
18
+ __license__ = "MIT License"
19
+ __email__ = "kasirer@arch.ethz.ch"
20
+ __version__ = "0.1.0"
21
+
22
+
23
+ HERE = os.path.dirname(__file__)
24
+
25
+ HOME = os.path.abspath(os.path.join(HERE, "../../"))
26
+ DATA = os.path.abspath(os.path.join(HOME, "data"))
27
+ DOCS = os.path.abspath(os.path.join(HOME, "docs"))
28
+ TEMP = os.path.abspath(os.path.join(HOME, "temp"))
29
+ IDL = os.path.abspath(os.path.join(HOME, "IDL"))
30
+
31
+ __all__ = [
32
+ "HOME",
33
+ "DATA",
34
+ "DOCS",
35
+ "TEMP",
36
+ "IDL",
37
+ "pb_load",
38
+ "pb_dump",
39
+ "pb_dump_bts",
40
+ "pb_load_bts",
41
+ "pb_dump_json",
42
+ "pb_load_json",
43
+ ]
@@ -0,0 +1,155 @@
1
+ from typing import Dict
2
+ from typing import List
3
+
4
+ from compas.data import Data
5
+
6
+ from compas_pb.core import deserialize_message
7
+ from compas_pb.core import deserialize_message_from_json
8
+ from compas_pb.core import serialize_message_bts
9
+ from compas_pb.core import serialize_message_to_json
10
+
11
+
12
+ def pb_dump(data: Data | Dict[str, Data] | List[Data], filepath: str) -> None:
13
+ """Write a collection of COMPAS object to a binary file.
14
+
15
+ Parameters
16
+ ----------
17
+ data : Data | Dict | List
18
+ Any protobuffer serializable object.
19
+ This includes any (combination of) COMPAS object(s).
20
+ filepath : path string or file-like object
21
+ A writeable file-like object or the path to a file.
22
+
23
+ Returns:
24
+ -------
25
+ None
26
+
27
+ Example:
28
+ --------
29
+ pass
30
+
31
+ """
32
+ message_bts = serialize_message_bts(data)
33
+
34
+ with open(filepath, "wb") as f:
35
+ f.write(message_bts)
36
+
37
+
38
+ def pb_load(filepath: str) -> Data | Dict | List:
39
+ """Read a collection of COMPAS object from a binary file.
40
+
41
+ Parameters
42
+ ----------
43
+ filepath : path string or file-like object
44
+
45
+ A readable file-like object or the path to a file.
46
+
47
+ Returns:
48
+ -------
49
+ Data | Dict | List
50
+
51
+ The (COMPAS) object(s) contained in the file.
52
+
53
+ """
54
+
55
+ with open(filepath, "rb") as f:
56
+ message_bts = f.read()
57
+ message = deserialize_message(message_bts)
58
+ return message
59
+
60
+
61
+ def pb_dump_json(data: Data | Dict | List) -> str:
62
+ """Write a collection of COMPAS object to a JSON string.
63
+
64
+
65
+ Parameters
66
+ ----------
67
+ data : Data | Dict | List
68
+
69
+ Any protobuffer serializable object. This includes any (combination of) COMPAS object(s).
70
+
71
+
72
+ Returns:
73
+ -------
74
+ string
75
+
76
+ The JSON string representation of the data.
77
+
78
+ Example:
79
+ --------
80
+ pass
81
+
82
+ """
83
+ json_str = serialize_message_to_json(data)
84
+ return json_str
85
+
86
+
87
+ def pb_load_json(data: str) -> Data | Dict | List:
88
+ """Read a collection of COMPAS object from a JSON string.
89
+
90
+
91
+ Parameters
92
+ ----------
93
+ data : str
94
+
95
+ A JSON string representation of the data.
96
+
97
+
98
+ Returns:
99
+ -------
100
+ Data | Dict | List
101
+
102
+
103
+ The (COMPAS) object(s) contained in the JSON string.
104
+
105
+ Example:
106
+ --------
107
+ pass
108
+
109
+ """
110
+ message = deserialize_message_from_json(data)
111
+ return message
112
+
113
+
114
+ def pb_dump_bts(data: Data | Dict | list) -> bytes:
115
+ """Write a collection of COMPAS object to a btye string.
116
+
117
+
118
+ Parameters
119
+ ----------
120
+ data : Data | Dict | List
121
+
122
+ Any protobuffer serializable object.
123
+ This includes any (combination of) COMPAS object(s).
124
+
125
+ Returns:
126
+ -------
127
+ None
128
+
129
+ Example:
130
+ --------
131
+ pass
132
+
133
+ """
134
+ message_bts = serialize_message_bts(data)
135
+
136
+ return message_bts
137
+
138
+
139
+ def pb_load_bts(data: bytes) -> Data | Dict | List:
140
+ """Read a collection of COMPAS object from a binary file.
141
+
142
+ Parameters
143
+ ----------
144
+ filepath : path string or file-like object
145
+ A readable file-like object or the path to a file.
146
+
147
+
148
+ Returns:
149
+ -------
150
+ Data | Dict | List
151
+ The (COMPAS) object(s) contained in the file.
152
+
153
+ """
154
+ message_bts = deserialize_message(data)
155
+ return message_bts