TypedUnit 0.0.7__tar.gz → 0.0.8__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 (43) hide show
  1. {typedunit-0.0.7 → typedunit-0.0.8}/.github/dependabot.yml +1 -1
  2. typedunit-0.0.8/.gitignore +33 -0
  3. typedunit-0.0.8/.pre-commit-config.yaml +17 -0
  4. {typedunit-0.0.7 → typedunit-0.0.8}/PKG-INFO +1 -1
  5. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/__init__.py +2 -1
  6. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/_version.py +3 -3
  7. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/units.py +90 -45
  8. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit.egg-info/PKG-INFO +1 -1
  9. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit.egg-info/SOURCES.txt +1 -1
  10. typedunit-0.0.7/.gitignore +0 -28
  11. typedunit-0.0.7/docs/source/gallery/index.rst +0 -71
  12. {typedunit-0.0.7 → typedunit-0.0.8}/.flake8 +0 -0
  13. {typedunit-0.0.7 → typedunit-0.0.8}/.github/workflows/deploy_PyPi.yml +0 -0
  14. {typedunit-0.0.7 → typedunit-0.0.8}/.github/workflows/deploy_anaconda.yml +0 -0
  15. {typedunit-0.0.7 → typedunit-0.0.8}/.github/workflows/deploy_coverage.yml +0 -0
  16. {typedunit-0.0.7 → typedunit-0.0.8}/.github/workflows/deploy_documentation.yml +0 -0
  17. {typedunit-0.0.7 → typedunit-0.0.8}/LICENSE +0 -0
  18. {typedunit-0.0.7 → typedunit-0.0.8}/README.rst +0 -0
  19. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/directories.py +0 -0
  20. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/helper.py +0 -0
  21. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit/utils.py +0 -0
  22. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit.egg-info/dependency_links.txt +0 -0
  23. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit.egg-info/requires.txt +0 -0
  24. {typedunit-0.0.7 → typedunit-0.0.8}/TypedUnit.egg-info/top_level.txt +0 -0
  25. {typedunit-0.0.7 → typedunit-0.0.8}/docs/Makefile +0 -0
  26. {typedunit-0.0.7 → typedunit-0.0.8}/docs/examples/README.rst +0 -0
  27. {typedunit-0.0.7 → typedunit-0.0.8}/docs/examples/example_0.py +0 -0
  28. {typedunit-0.0.7 → typedunit-0.0.8}/docs/examples/example_1.py +0 -0
  29. {typedunit-0.0.7 → typedunit-0.0.8}/docs/images/logo.png +0 -0
  30. {typedunit-0.0.7 → typedunit-0.0.8}/docs/make.bat +0 -0
  31. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/_static/default.css +0 -0
  32. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/_static/thumbnail.png +0 -0
  33. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/code.rst +0 -0
  34. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/conf.py +0 -0
  35. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/index.rst +0 -0
  36. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/references.rst +0 -0
  37. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/sg_execution_times.rst +0 -0
  38. {typedunit-0.0.7 → typedunit-0.0.8}/docs/source/theory.rst +0 -0
  39. {typedunit-0.0.7 → typedunit-0.0.8}/meta.yaml +0 -0
  40. {typedunit-0.0.7 → typedunit-0.0.8}/pyproject.toml +0 -0
  41. {typedunit-0.0.7 → typedunit-0.0.8}/setup.cfg +0 -0
  42. {typedunit-0.0.7 → typedunit-0.0.8}/tests/__init__.py +0 -0
  43. {typedunit-0.0.7 → typedunit-0.0.8}/tests/test_0.py +0 -0
@@ -6,6 +6,6 @@ updates:
6
6
  directory: "/"
7
7
  target-branch: "master"
8
8
  schedule:
9
- interval: "weekly"
9
+ interval: "monthly"
10
10
  day: "sunday"
11
11
  time: "09:00"
@@ -0,0 +1,33 @@
1
+
2
+ # Ignore all
3
+ /*
4
+
5
+ # Except ...
6
+ !.github
7
+ !.gitmodules
8
+ !extern
9
+ !TypedUnit
10
+ !development
11
+ !docs
12
+ !tests
13
+ !.flake8
14
+ !.gitignore
15
+ !.pre-commit-config.yaml
16
+ !LICENSE
17
+ !meta.yaml
18
+ !pyproject.toml
19
+ !README.rst
20
+ !notebook.ipynb
21
+ !CMakeLists.txt
22
+
23
+ # But ignore docs/build inside docs and code
24
+ docs/build/
25
+ docs/source/gallery/
26
+
27
+ # Compiled files in the project
28
+ *__pycache__*
29
+ *.DS_Store*
30
+ *.so*
31
+ *.a*
32
+
33
+ # Package specifics
@@ -0,0 +1,17 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: check-merge-conflict
6
+ - id: end-of-file-fixer
7
+ - id: mixed-line-ending
8
+ - id: check-yaml
9
+ - id: check-toml
10
+ - id: detect-private-key
11
+ - id: check-json
12
+ - id: check-case-conflict
13
+
14
+ - repo: https://github.com/psf/black
15
+ rev: 24.4.2
16
+ hooks:
17
+ - id: black
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TypedUnit
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: A package wrapping pint for handling typed units in Python.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -6,4 +6,5 @@ except ImportError:
6
6
 
7
7
 
8
8
  from .units import *
9
- from .helper import validate_units
9
+ from .helper import validate_units
10
+ from .units import ureg, Quantity
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.7'
32
- __version_tuple__ = version_tuple = (0, 0, 7)
31
+ __version__ = version = '0.0.8'
32
+ __version_tuple__ = version_tuple = (0, 0, 8)
33
33
 
34
- __commit_id__ = commit_id = 'gdd1c6b1a7'
34
+ __commit_id__ = commit_id = 'gad246e6a5'
@@ -13,11 +13,41 @@ ureg.define("event = [Int64]") # Define a custom unit 'events'
13
13
  ureg.define("sqrt_hertz = Hz**0.5")
14
14
  ureg.define("bit_bins = ![Int64]")
15
15
 
16
+ __all__ = [
17
+ "Energy",
18
+ "Time",
19
+ "Power",
20
+ "Voltage",
21
+ "Current",
22
+ "Resistance",
23
+ "Temperature",
24
+ "Length",
25
+ "Volume",
26
+ "FlowRate",
27
+ "Frequency",
28
+ "Angle",
29
+ "Mass",
30
+ "RefractiveIndex",
31
+ "Dimensionless",
32
+ "Responsitivity",
33
+ "Viscosity",
34
+ "Area",
35
+ "ElectricField",
36
+ "Velocity",
37
+ "Ohm",
38
+ "Concentration",
39
+ "Particle",
40
+ "ParticleFlux",
41
+ "AnyUnit",
42
+ ]
43
+
44
+
16
45
  class UnitMeta(type):
17
46
  """
18
47
  Metaclass that makes isinstance(x, SomeUnit) return True
19
48
  when x is a pint.Quantity with the right dimensionality.
20
49
  """
50
+
21
51
  def __instancecheck__(cls, obj):
22
52
  if not isinstance(obj, Quantity):
23
53
  return False
@@ -44,7 +74,9 @@ class UnitMeta(type):
44
74
  a = cls.__name__
45
75
  b = other.__name__
46
76
  name = f"{a}Times{b}"
47
- expected = f"({getattr(cls, '_expected_dim')})*({getattr(other, '_expected_dim')})"
77
+ expected = (
78
+ f"({getattr(cls, '_expected_dim')})*({getattr(other, '_expected_dim')})"
79
+ )
48
80
  return UnitMeta(name, (BaseUnit,), {"_expected_dim": expected})
49
81
 
50
82
  def __pow__(cls, power):
@@ -54,6 +86,7 @@ class UnitMeta(type):
54
86
  expected = f"({getattr(cls, '_expected_dim')})**{power}"
55
87
  return UnitMeta(name, (BaseUnit,), {"_expected_dim": expected})
56
88
 
89
+
57
90
  class BaseUnit(metaclass=UnitMeta):
58
91
  _expected_dim: str | None = None
59
92
 
@@ -61,151 +94,163 @@ class BaseUnit(metaclass=UnitMeta):
61
94
  def check(cls, value):
62
95
  if cls._expected_dim is None:
63
96
  return value
64
- assert isinstance(value, Quantity), f"Expected a pint Quantity instance, got {type(value)}"
65
- assert value.check(cls._expected_dim), f"Value units {value.dimensionality} do not match {cls.__name__} units"
97
+ assert isinstance(
98
+ value, Quantity
99
+ ), f"Expected a pint Quantity instance, got {type(value)}"
100
+ assert value.check(
101
+ cls._expected_dim
102
+ ), f"Value units {value.dimensionality} do not match {cls.__name__} units"
66
103
  return value
67
104
 
105
+
68
106
  class Energy(BaseUnit):
69
107
  """Quantity specifically for energy units."""
108
+
70
109
  _expected_dim = "joule"
71
110
 
111
+
72
112
  class Time(BaseUnit):
73
113
  """Quantity specifically for time units."""
114
+
74
115
  _expected_dim = "second"
75
116
 
117
+
76
118
  class Power(BaseUnit):
77
119
  """Quantity specifically for power units."""
120
+
78
121
  _expected_dim = "watt"
79
122
 
123
+
80
124
  class Voltage(BaseUnit):
81
125
  """Quantity specifically for voltage units."""
126
+
82
127
  _expected_dim = "volt"
83
128
 
129
+
84
130
  class Current(BaseUnit):
85
131
  """Quantity specifically for current units."""
132
+
86
133
  _expected_dim = "ampere"
87
134
 
135
+
88
136
  class Resistance(BaseUnit):
89
137
  """Quantity specifically for resistance units."""
138
+
90
139
  _expected_dim = "ohm"
91
140
 
141
+
92
142
  class Temperature(BaseUnit):
93
143
  """Quantity specifically for temperature units."""
144
+
94
145
  _expected_dim = "kelvin"
95
146
 
147
+
96
148
  class Length(BaseUnit):
97
149
  """Quantity specifically for length units."""
150
+
98
151
  _expected_dim = "meter"
99
152
 
153
+
100
154
  class Volume(BaseUnit):
101
155
  """Quantity specifically for volume units."""
156
+
102
157
  _expected_dim = "liter"
103
158
 
159
+
104
160
  class FlowRate(BaseUnit):
105
161
  """Quantity specifically for flow rate units."""
162
+
106
163
  _expected_dim = "liter / second"
107
164
 
165
+
108
166
  class Frequency(BaseUnit):
109
167
  """Quantity specifically for frequency units."""
168
+
110
169
  _expected_dim = "hertz"
111
170
 
171
+
112
172
  class Angle(BaseUnit):
113
173
  """Quantity specifically for angle units."""
174
+
114
175
  _expected_dim = "degree"
115
176
 
177
+
116
178
  class Mass(BaseUnit):
117
179
  """Quantity specifically for mass units."""
180
+
118
181
  _expected_dim = "kilogram"
119
182
 
183
+
120
184
  class RefractiveIndex(BaseUnit):
121
185
  """Quantity specifically for refractive index units."""
186
+
122
187
  _expected_dim = "refractive_index_units"
123
188
 
189
+
124
190
  class Dimensionless(BaseUnit):
125
191
  """Quantity specifically for dimensionless units."""
192
+
126
193
  _expected_dim = ""
127
194
 
195
+
128
196
  class Responsitivity(BaseUnit):
129
197
  """Quantity specifically for responsitivity units."""
198
+
130
199
  _expected_dim = "ampere / watt"
131
200
 
201
+
132
202
  class Viscosity(BaseUnit):
133
203
  """Quantity specifically for viscosity units."""
204
+
134
205
  _expected_dim = "pascal * second"
135
206
 
207
+
136
208
  class Area(BaseUnit):
137
209
  """Quantity specifically for viscosity units."""
210
+
138
211
  _expected_dim = "meter * meter"
139
212
 
213
+
140
214
  class ElectricField(BaseUnit):
141
215
  """Quantity specifically for electric field units."""
216
+
142
217
  _expected_dim = "volt / meter"
143
218
 
219
+
144
220
  class Velocity(BaseUnit):
145
221
  """Quantity specifically for velocity units."""
222
+
146
223
  _expected_dim = "meter / second"
147
224
 
225
+
148
226
  class Ohm(BaseUnit):
149
227
  """Quantity specifically for resistance units."""
228
+
150
229
  _expected_dim = "ohm"
151
230
 
231
+
152
232
  class Concentration(BaseUnit):
153
233
  """Quantity specifically for concentration units."""
234
+
154
235
  _expected_dim = "particle / liter"
155
236
 
237
+
156
238
  class Particle(BaseUnit):
157
239
  """Quantity specifically for particle units."""
240
+
158
241
  _expected_dim = "particle"
159
242
 
243
+
160
244
  class ParticleFlux(BaseUnit):
161
245
  """Quantity specifically for particle flux units."""
246
+
162
247
  _expected_dim = "particle / second"
163
248
 
164
- class Any(BaseUnit):
165
- """Quantity that can have any unit."""
166
- _expected_dim = None # Accept any dimensionality
167
249
 
168
250
  class AnyUnit(BaseUnit):
169
251
  """Quantity that can have any unit."""
170
- _expected_dim = None # Accept any dimensionality
171
-
172
- ureg.AU = ureg.dimensionless
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
- # from pydantic.dataclasses import dataclass
185
-
186
- # config_dict = dict(
187
- # arbitrary_types_allowed=True,
188
- # kw_only=True,
189
- # slots=True,
190
- # extra='forbid'
191
- # )
192
-
193
-
194
-
195
-
196
- # @dataclass(config=config_dict)
197
- # class Sphere():
198
- # name: str
199
- # refractive_index: RefractiveIndex
200
- # diameter: Length
201
- # particle_count: Particle
202
252
 
253
+ _expected_dim = None # Accept any dimensionality
203
254
 
204
- # test = Sphere(
205
- # name="Test Sphere",
206
- # refractive_index=1 * ureg.refractive_index_units,
207
- # diameter=1 * ureg.meter,
208
- # particle_count=1 * 5e9 * ureg.particle / ureg.milliliter
209
- # )
210
255
 
211
- # print(test)
256
+ ureg.AU = ureg.dimensionless
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TypedUnit
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: A package wrapping pint for handling typed units in Python.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -1,5 +1,6 @@
1
1
  .flake8
2
2
  .gitignore
3
+ .pre-commit-config.yaml
3
4
  LICENSE
4
5
  README.rst
5
6
  meta.yaml
@@ -34,6 +35,5 @@ docs/source/sg_execution_times.rst
34
35
  docs/source/theory.rst
35
36
  docs/source/_static/default.css
36
37
  docs/source/_static/thumbnail.png
37
- docs/source/gallery/index.rst
38
38
  tests/__init__.py
39
39
  tests/test_0.py
@@ -1,28 +0,0 @@
1
- # General patterns
2
- *.DS_store
3
- *.ipynb_checkpoints*
4
- *__pycache__*
5
- *.so
6
- *.a
7
- .coverage*
8
- *.pytest_cache
9
- htmlcov
10
- dist
11
- build
12
- *.egg*
13
- *.whl
14
- CMakeCache.txt
15
- CMakeFiles
16
- install_manifest.txt
17
- cmake_install.cmake
18
- wheelhouse
19
-
20
- # Docs-specific patterns
21
- docs/source/gallery/*
22
- !docs/source/gallery/index.rst
23
- PyOptik/data/**/test*
24
- PyOptik/data/**/example*
25
-
26
- # Override for documentation_build
27
- !documentation_build
28
- !documentation_build/**
@@ -1,71 +0,0 @@
1
- :orphan:
2
-
3
- .. _examples_gallery:
4
-
5
- Coding examples
6
- ===============
7
-
8
- Explore our gallery of examples demonstrating the usage of TypedUnits.
9
-
10
-
11
-
12
- .. raw:: html
13
-
14
- <div class="sphx-glr-thumbnails">
15
-
16
- .. thumbnail-parent-div-open
17
-
18
- .. raw:: html
19
-
20
- <div class="sphx-glr-thumbcontainer" tooltip="Workflow - 0">
21
-
22
- .. only:: html
23
-
24
- .. image:: /gallery/images/thumb/sphx_glr_example_0_thumb.png
25
- :alt:
26
-
27
- :ref:`sphx_glr_gallery_example_0.py`
28
-
29
- .. raw:: html
30
-
31
- <div class="sphx-glr-thumbnail-title">Workflow - 0</div>
32
- </div>
33
-
34
-
35
- .. raw:: html
36
-
37
- <div class="sphx-glr-thumbcontainer" tooltip="Workflow - 1">
38
-
39
- .. only:: html
40
-
41
- .. image:: /gallery/images/thumb/sphx_glr_example_1_thumb.png
42
- :alt:
43
-
44
- :ref:`sphx_glr_gallery_example_1.py`
45
-
46
- .. raw:: html
47
-
48
- <div class="sphx-glr-thumbnail-title">Workflow - 1</div>
49
- </div>
50
-
51
-
52
- .. thumbnail-parent-div-close
53
-
54
- .. raw:: html
55
-
56
- </div>
57
-
58
-
59
- .. toctree::
60
- :hidden:
61
-
62
- /gallery/example_0
63
- /gallery/example_1
64
-
65
-
66
-
67
- .. only:: html
68
-
69
- .. rst-class:: sphx-glr-signature
70
-
71
- `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes