unitx 0.0.1__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.
- unitx-0.0.1/LICENSE +19 -0
- unitx-0.0.1/PKG-INFO +45 -0
- unitx-0.0.1/README.md +2 -0
- unitx-0.0.1/pyproject.toml +37 -0
- unitx-0.0.1/setup.cfg +4 -0
- unitx-0.0.1/src/unitx/__init__.py +28 -0
- unitx-0.0.1/src/unitx/area.py +40 -0
- unitx-0.0.1/src/unitx/distance.py +39 -0
- unitx-0.0.1/src/unitx/exceptions.py +19 -0
- unitx-0.0.1/src/unitx/mass.py +39 -0
- unitx-0.0.1/src/unitx/temperature.py +54 -0
- unitx-0.0.1/src/unitx/validate.py +24 -0
- unitx-0.0.1/src/unitx/volume.py +42 -0
- unitx-0.0.1/src/unitx.egg-info/PKG-INFO +45 -0
- unitx-0.0.1/src/unitx.egg-info/SOURCES.txt +20 -0
- unitx-0.0.1/src/unitx.egg-info/dependency_links.txt +1 -0
- unitx-0.0.1/src/unitx.egg-info/top_level.txt +1 -0
- unitx-0.0.1/tests/test_area.py +41 -0
- unitx-0.0.1/tests/test_distance.py +41 -0
- unitx-0.0.1/tests/test_mass.py +41 -0
- unitx-0.0.1/tests/test_temperature.py +47 -0
- unitx-0.0.1/tests/test_volume.py +41 -0
unitx-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 devs_des1re
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
unitx-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unitx
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python library which dynamically converts different types of units
|
|
5
|
+
Author-email: devs_des1re <arjunbrij8811@gmail.com>
|
|
6
|
+
Maintainer-email: devs_des1re <arjunbrij8811@gmail.com>
|
|
7
|
+
License: Copyright (c) 2025 devs_des1re
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
Keywords: app,macOS,windows,linux,flatpak
|
|
27
|
+
Classifier: Development Status :: 4 - Beta
|
|
28
|
+
Classifier: Intended Audience :: Developers
|
|
29
|
+
Classifier: Operating System :: OS Independent
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Topic :: Software Development
|
|
38
|
+
Classifier: Topic :: Utilities
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# unitx
|
|
45
|
+
What is unitx? Unitx is the best Python library for converting units between each other dynamically! It currently provides support to 5 different type of unit categories, but more will be added in the future!
|
unitx-0.0.1/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=75.0.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "unitx"
|
|
7
|
+
description = "A Python library which dynamically converts different types of units"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
version = "0.0.1"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
|
|
13
|
+
authors = [ { name="devs_des1re", email="arjunbrij8811@gmail.com" } ]
|
|
14
|
+
maintainers = [ { name="devs_des1re", email="arjunbrij8811@gmail.com" } ]
|
|
15
|
+
|
|
16
|
+
keywords = [
|
|
17
|
+
"app",
|
|
18
|
+
"macOS",
|
|
19
|
+
"windows",
|
|
20
|
+
"linux",
|
|
21
|
+
"flatpak",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 4 - Beta",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
33
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Topic :: Software Development",
|
|
35
|
+
"Topic :: Utilities",
|
|
36
|
+
]
|
|
37
|
+
dependencies = []
|
unitx-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""unitx Library"""
|
|
2
|
+
from .distance import Distance, convert_distance
|
|
3
|
+
from .mass import Mass, convert_mass
|
|
4
|
+
from .volume import Volume, convert_volume
|
|
5
|
+
from .temperature import Temperature, convert_temperature
|
|
6
|
+
from .area import Area, convert_area
|
|
7
|
+
from .exceptions import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Distance",
|
|
11
|
+
"Mass",
|
|
12
|
+
"Volume",
|
|
13
|
+
"Temperature",
|
|
14
|
+
"Area",
|
|
15
|
+
"convert_distance",
|
|
16
|
+
"convert_mass",
|
|
17
|
+
"convert_volume",
|
|
18
|
+
"convert_temperature",
|
|
19
|
+
"convert_area",
|
|
20
|
+
"InvalidUnitError",
|
|
21
|
+
"NonNumericError",
|
|
22
|
+
"UnsupportedUnitError"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
__author__ = "devs_des1re"
|
|
27
|
+
__license__ = "MIT"
|
|
28
|
+
__email__ = "arjunbrij8811@gmail.com"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Converts units of area"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .validate import _validate_conversion
|
|
4
|
+
|
|
5
|
+
class Area(Enum):
|
|
6
|
+
"""Class for which contains Area Enums.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
Enum (float): The Area Enum.
|
|
10
|
+
"""
|
|
11
|
+
SQUARE_METER = 1.0
|
|
12
|
+
SQUARE_KILOMETER = 1_000_000.0
|
|
13
|
+
SQUARE_CENTIMETER = 0.0001
|
|
14
|
+
SQUARE_MILLIMETER = 0.000001
|
|
15
|
+
HECTARE = 10_000.0
|
|
16
|
+
ACRE = 4046.86
|
|
17
|
+
SQUARE_FOOT = 0.092903
|
|
18
|
+
SQUARE_YARD = 0.836127
|
|
19
|
+
SQUARE_MILE = 2_589_988.0
|
|
20
|
+
|
|
21
|
+
def convert_area(value: float, from_unit: Area, to_unit: Area) -> float:
|
|
22
|
+
"""Convert a area value from a unit to another unit.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
value (float): The numeric value to convert.
|
|
26
|
+
from_unit (Area): The unit you are converting from.
|
|
27
|
+
to_unit (Area): The unit you are converting to.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
NonNumericError: Raised when value is not int or float.
|
|
31
|
+
UnsupportedUnitError: Raised when a unit is not recognized.
|
|
32
|
+
InvalidUnitError: Raised when units are from a different category.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
float: The converted numeric value
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
_validate_conversion(value, from_unit, to_unit, Area)
|
|
39
|
+
|
|
40
|
+
return value * from_unit.value / to_unit.value
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Converts units of distances"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .validate import _validate_conversion
|
|
4
|
+
|
|
5
|
+
class Distance(Enum):
|
|
6
|
+
"""Class for which contains Distance Enums.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
Enum (float): The Distance Enum.
|
|
10
|
+
"""
|
|
11
|
+
METERS = 1.0
|
|
12
|
+
KILOMETERS = 1000.0
|
|
13
|
+
CENTIMETERS = 0.01
|
|
14
|
+
MILLIMETERS = 0.001
|
|
15
|
+
FEET = 0.3048
|
|
16
|
+
INCHES = 0.0254
|
|
17
|
+
YARDS = 0.9144
|
|
18
|
+
MILES = 1609.34
|
|
19
|
+
|
|
20
|
+
def convert_distance(value: float, from_unit: Distance, to_unit: Distance) -> float:
|
|
21
|
+
"""Convert a distance value from a unit to another unit.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
value (float): The numeric value to convert.
|
|
25
|
+
from_unit (Distance): The unit you are converting from.
|
|
26
|
+
to_unit (Distance): The unit you are converting to.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
NonNumericError: Raised when value is not int or float.
|
|
30
|
+
UnsupportedUnitError: Raised when a unit is not recognized.
|
|
31
|
+
InvalidUnitError: Raised when units are from a different category.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
float: The converted numeric value
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
_validate_conversion(value, from_unit, to_unit, Distance)
|
|
38
|
+
|
|
39
|
+
return value * from_unit.value / to_unit.value
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Exceptions Module"""
|
|
2
|
+
|
|
3
|
+
class UnsupportedUnitError(Exception):
|
|
4
|
+
"""Raised when a unit is not recognized."""
|
|
5
|
+
|
|
6
|
+
def __init__(self, message):
|
|
7
|
+
super().__init__(message)
|
|
8
|
+
|
|
9
|
+
class InvalidUnitError(Exception):
|
|
10
|
+
"""Raised when units are from a different category."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, message):
|
|
13
|
+
super().__init__(message)
|
|
14
|
+
|
|
15
|
+
class NonNumericError(Exception):
|
|
16
|
+
"""Raised when value is not int or float."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, message):
|
|
19
|
+
super().__init__(message)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Converts units of mass"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .validate import _validate_conversion
|
|
4
|
+
|
|
5
|
+
class Mass(Enum):
|
|
6
|
+
"""Class for which contains Mass Enums.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
Enum (float): The Mass Enum.
|
|
10
|
+
"""
|
|
11
|
+
KILOGRAM = 1.0
|
|
12
|
+
GRAM = 0.001
|
|
13
|
+
MILLIGRAM = 0.000001
|
|
14
|
+
MICROGRAM = 1e-9
|
|
15
|
+
TONNE = 1000.0
|
|
16
|
+
POUND = 0.45359237
|
|
17
|
+
OUNCE = 0.0283495231
|
|
18
|
+
STONE = 6.35029318
|
|
19
|
+
|
|
20
|
+
def convert_mass(value: float, from_unit: Mass, to_unit: Mass) -> float:
|
|
21
|
+
"""Convert a mass value from a unit to another unit.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
value (float): The numeric value to convert.
|
|
25
|
+
from_unit (Mass): The unit you are converting from.
|
|
26
|
+
to_unit (Mass): The unit you are converting to.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
NonNumericError: Raised when value is not int or float.
|
|
30
|
+
UnsupportedUnitError: Raised when a unit is not recognized.
|
|
31
|
+
InvalidUnitError: Raised when units are from a different category.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
float: The converted numeric value
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
_validate_conversion(value, from_unit, to_unit, Mass)
|
|
38
|
+
|
|
39
|
+
return value * from_unit.value / to_unit.value
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Converts units of temperature"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .validate import _validate_conversion
|
|
4
|
+
|
|
5
|
+
class Temperature(Enum):
|
|
6
|
+
"""Class for which contains Temperature Enums.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
Enum (float): The Temperature Enum.
|
|
10
|
+
"""
|
|
11
|
+
CELSIUS = "C"
|
|
12
|
+
FAHRENHEIT = "F"
|
|
13
|
+
KELVIN = "K"
|
|
14
|
+
RANKINE = "R"
|
|
15
|
+
|
|
16
|
+
def convert_temperature(value: float, from_unit: Temperature, to_unit: Temperature) -> float:
|
|
17
|
+
"""Convert a temperature value from a unit to another unit.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
value (float): The numeric value to convert.
|
|
21
|
+
from_unit (Temperature): The unit you are converting from.
|
|
22
|
+
to_unit (Temperature): The unit you are converting to.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
NonNumericError: Raised when value is not int or float.
|
|
26
|
+
UnsupportedUnitError: Raised when a unit is not recognized.
|
|
27
|
+
InvalidUnitError: Raised when units are from a different category.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
float: The converted numeric value
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
_validate_conversion(value, from_unit, to_unit, Temperature)
|
|
34
|
+
|
|
35
|
+
converted_value = None
|
|
36
|
+
|
|
37
|
+
if from_unit == Temperature.CELSIUS:
|
|
38
|
+
converted_value = value
|
|
39
|
+
elif from_unit == Temperature.FAHRENHEIT:
|
|
40
|
+
converted_value = (value - 32) * 5/9
|
|
41
|
+
elif from_unit == Temperature.KELVIN:
|
|
42
|
+
converted_value = value - 273.15
|
|
43
|
+
elif from_unit == Temperature.RANKINE:
|
|
44
|
+
converted_value = (value - 491.67) * 5/9
|
|
45
|
+
|
|
46
|
+
# Convert from Celsius to target unit
|
|
47
|
+
if to_unit == Temperature.FAHRENHEIT:
|
|
48
|
+
converted_value = converted_value * 9/5 + 32
|
|
49
|
+
elif to_unit == Temperature.KELVIN:
|
|
50
|
+
converted_value = converted_value + 273.15
|
|
51
|
+
elif to_unit == Temperature.RANKINE:
|
|
52
|
+
converted_value = (converted_value + 273.15) * 9/5
|
|
53
|
+
|
|
54
|
+
return converted_value
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Validates conversion"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .exceptions import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _validate_conversion(value, from_unit, to_unit, category):
|
|
7
|
+
# Check if value is numeric
|
|
8
|
+
if not isinstance(value, (int, float)):
|
|
9
|
+
raise NonNumericError(f"Value must be numeric, got {type(value).__name__}")
|
|
10
|
+
|
|
11
|
+
# Check if units are valid Enum members
|
|
12
|
+
if not isinstance(from_unit, Enum):
|
|
13
|
+
raise UnsupportedUnitError(f"From unit must be enum, got {type(from_unit).__name__}")
|
|
14
|
+
|
|
15
|
+
if not isinstance(to_unit, Enum):
|
|
16
|
+
raise UnsupportedUnitError(f"From unit must be enum, got {type(to_unit).__name__}")
|
|
17
|
+
|
|
18
|
+
# Check if category mismatch
|
|
19
|
+
if from_unit.__class__ is not to_unit.__class__:
|
|
20
|
+
raise InvalidUnitError(f"From unit and to unit must be from the category, got {type(from_unit).__name__}, {type(from_unit).__name__}")
|
|
21
|
+
|
|
22
|
+
# Check if from unit is from correct category Enum
|
|
23
|
+
if not isinstance(from_unit, category):
|
|
24
|
+
raise InvalidUnitError(f"From unit must be from the {category.__name__} enum, got {type(from_unit).__name__}")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Converts units of volume"""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from .validate import _validate_conversion
|
|
4
|
+
|
|
5
|
+
class Volume(Enum):
|
|
6
|
+
"""Class for which contains Volume Enums.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
Enum (float): The Volume Enum.
|
|
10
|
+
"""
|
|
11
|
+
LITER = 1.0
|
|
12
|
+
MILLILITER = 0.001
|
|
13
|
+
CUBIC_METER = 1000.0
|
|
14
|
+
CUBIC_CENTIMETER = 0.001
|
|
15
|
+
GALLON_US = 3.78541
|
|
16
|
+
QUART_US = 0.946353
|
|
17
|
+
PINT_US = 0.473176
|
|
18
|
+
CUP_US = 0.24
|
|
19
|
+
FLUID_OUNCE_US = 0.0295735
|
|
20
|
+
TABLESPOON_US = 0.0147868
|
|
21
|
+
TEASPOON_US = 0.00492892
|
|
22
|
+
|
|
23
|
+
def convert_volume(value: float, from_unit: Volume, to_unit: Volume) -> float:
|
|
24
|
+
"""Convert a volume value from a unit to another unit.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
value (float): The numeric value to convert.
|
|
28
|
+
from_unit (Volume): The unit you are converting from.
|
|
29
|
+
to_unit (Volume): The unit you are converting to.
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
NonNumericError: Raised when value is not int or float.
|
|
33
|
+
UnsupportedUnitError: Raised when a unit is not recognized.
|
|
34
|
+
InvalidUnitError: Raised when units are from a different category.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
float: The converted numeric value
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
_validate_conversion(value, from_unit, to_unit, Volume)
|
|
41
|
+
|
|
42
|
+
return value * from_unit.value / to_unit.value
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unitx
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python library which dynamically converts different types of units
|
|
5
|
+
Author-email: devs_des1re <arjunbrij8811@gmail.com>
|
|
6
|
+
Maintainer-email: devs_des1re <arjunbrij8811@gmail.com>
|
|
7
|
+
License: Copyright (c) 2025 devs_des1re
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
Keywords: app,macOS,windows,linux,flatpak
|
|
27
|
+
Classifier: Development Status :: 4 - Beta
|
|
28
|
+
Classifier: Intended Audience :: Developers
|
|
29
|
+
Classifier: Operating System :: OS Independent
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Topic :: Software Development
|
|
38
|
+
Classifier: Topic :: Utilities
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# unitx
|
|
45
|
+
What is unitx? Unitx is the best Python library for converting units between each other dynamically! It currently provides support to 5 different type of unit categories, but more will be added in the future!
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/unitx/__init__.py
|
|
5
|
+
src/unitx/area.py
|
|
6
|
+
src/unitx/distance.py
|
|
7
|
+
src/unitx/exceptions.py
|
|
8
|
+
src/unitx/mass.py
|
|
9
|
+
src/unitx/temperature.py
|
|
10
|
+
src/unitx/validate.py
|
|
11
|
+
src/unitx/volume.py
|
|
12
|
+
src/unitx.egg-info/PKG-INFO
|
|
13
|
+
src/unitx.egg-info/SOURCES.txt
|
|
14
|
+
src/unitx.egg-info/dependency_links.txt
|
|
15
|
+
src/unitx.egg-info/top_level.txt
|
|
16
|
+
tests/test_area.py
|
|
17
|
+
tests/test_distance.py
|
|
18
|
+
tests/test_mass.py
|
|
19
|
+
tests/test_temperature.py
|
|
20
|
+
tests/test_volume.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
unitx
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Testing Library"""
|
|
2
|
+
import pytest
|
|
3
|
+
from unitx import Mass, Area, convert_area
|
|
4
|
+
from unitx import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
5
|
+
|
|
6
|
+
def test_conversion():
|
|
7
|
+
"""Tests the conversion so its converting right."""
|
|
8
|
+
|
|
9
|
+
converted = convert_area(10, Area.SQUARE_KILOMETER, Area.SQUARE_METER) # Metric Conversion
|
|
10
|
+
assert converted == 10_000_000
|
|
11
|
+
|
|
12
|
+
converted = convert_area(10, Area.SQUARE_FOOT, Area.SQUARE_YARD) # Imperial Conversion
|
|
13
|
+
assert converted == 10 / 9
|
|
14
|
+
|
|
15
|
+
converted = convert_area(10, Area.SQUARE_METER, Area.SQUARE_MILE) # Metric --> Imperial
|
|
16
|
+
assert round(converted, 8) == 3.86e-06
|
|
17
|
+
|
|
18
|
+
def test_errors():
|
|
19
|
+
"""Tests the conversion errors so its been handled properly."""
|
|
20
|
+
|
|
21
|
+
# Value is non numeric
|
|
22
|
+
with pytest.raises(NonNumericError):
|
|
23
|
+
convert_area("string", Area.SQUARE_FOOT, Area.SQUARE_YARD)
|
|
24
|
+
|
|
25
|
+
# Unit is not enum
|
|
26
|
+
with pytest.raises(UnsupportedUnitError):
|
|
27
|
+
convert_area(10, "non enum", Area.SQUARE_YARD)
|
|
28
|
+
|
|
29
|
+
with pytest.raises(UnsupportedUnitError):
|
|
30
|
+
convert_area(10, Area.SQUARE_YARD, "non enum")
|
|
31
|
+
|
|
32
|
+
# Unit is category mismatch
|
|
33
|
+
with pytest.raises(InvalidUnitError):
|
|
34
|
+
convert_area(10, Mass.KILOGRAM, Area.SQUARE_YARD)
|
|
35
|
+
|
|
36
|
+
with pytest.raises(InvalidUnitError):
|
|
37
|
+
convert_area(10, Area.SQUARE_FOOT, Mass.MILLIGRAM)
|
|
38
|
+
|
|
39
|
+
# Enum is from area class
|
|
40
|
+
with pytest.raises(InvalidUnitError):
|
|
41
|
+
convert_area(10, Mass.KILOGRAM, Mass.TONNE)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Testing Library"""
|
|
2
|
+
import pytest
|
|
3
|
+
from unitx import Mass, Distance, convert_distance
|
|
4
|
+
from unitx import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
5
|
+
|
|
6
|
+
def test_conversion():
|
|
7
|
+
"""Tests the conversion so its converting right."""
|
|
8
|
+
|
|
9
|
+
converted = convert_distance(10, Distance.KILOMETERS, Distance.METERS) # Metric Conversion
|
|
10
|
+
assert converted == 10000
|
|
11
|
+
|
|
12
|
+
converted = convert_distance(10, Distance.FEET, Distance.INCHES) # Imperial Conversion
|
|
13
|
+
assert converted == 120
|
|
14
|
+
|
|
15
|
+
converted = convert_distance(10, Distance.METERS, Distance.MILES) # Metric --> Imperial
|
|
16
|
+
assert round(converted, 8) == 0.00621373
|
|
17
|
+
|
|
18
|
+
def test_errors():
|
|
19
|
+
"""Tests the conversion errors so its been handled properly."""
|
|
20
|
+
|
|
21
|
+
# Value is non numeric
|
|
22
|
+
with pytest.raises(NonNumericError):
|
|
23
|
+
convert_distance("string", Distance.FEET, Distance.YARDS)
|
|
24
|
+
|
|
25
|
+
# Unit is not enum
|
|
26
|
+
with pytest.raises(UnsupportedUnitError):
|
|
27
|
+
convert_distance(10, "non enum", Distance.YARDS)
|
|
28
|
+
|
|
29
|
+
with pytest.raises(UnsupportedUnitError):
|
|
30
|
+
convert_distance(10, Distance.YARDS, "non enum")
|
|
31
|
+
|
|
32
|
+
# Unit is category mismatch
|
|
33
|
+
with pytest.raises(InvalidUnitError):
|
|
34
|
+
convert_distance(10, Mass.KILOGRAM, Distance.YARDS)
|
|
35
|
+
|
|
36
|
+
with pytest.raises(InvalidUnitError):
|
|
37
|
+
convert_distance(10, Distance.FEET, Mass.MILLIGRAM)
|
|
38
|
+
|
|
39
|
+
# Enum is from distance class
|
|
40
|
+
with pytest.raises(InvalidUnitError):
|
|
41
|
+
convert_distance(10, Mass.KILOGRAM, Mass.TONNE)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Testing Library"""
|
|
2
|
+
import pytest
|
|
3
|
+
from unitx import Distance, Mass, convert_mass
|
|
4
|
+
from unitx import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
5
|
+
|
|
6
|
+
def test_conversion():
|
|
7
|
+
"""Tests the conversion so its converting right."""
|
|
8
|
+
|
|
9
|
+
converted = convert_mass(10, Mass.KILOGRAM, Mass.GRAM) # Metric Conversion
|
|
10
|
+
assert converted == 10000
|
|
11
|
+
|
|
12
|
+
converted = convert_mass(10, Mass.OUNCE, Mass.POUND) # Imperial Conversion
|
|
13
|
+
assert round(converted, 3) == 0.625
|
|
14
|
+
|
|
15
|
+
converted = convert_mass(10, Mass.TONNE, Mass.STONE) # Metric --> Imperial
|
|
16
|
+
assert round(converted, 8) == 1574.73044418
|
|
17
|
+
|
|
18
|
+
def test_errors():
|
|
19
|
+
"""Tests the conversion errors so its been handled properly."""
|
|
20
|
+
|
|
21
|
+
# Value is non numeric
|
|
22
|
+
with pytest.raises(NonNumericError):
|
|
23
|
+
convert_mass("string", Mass.OUNCE, Mass.POUND)
|
|
24
|
+
|
|
25
|
+
# Unit is not enum
|
|
26
|
+
with pytest.raises(UnsupportedUnitError):
|
|
27
|
+
convert_mass(10, "non enum", Mass.KILOGRAM)
|
|
28
|
+
|
|
29
|
+
with pytest.raises(UnsupportedUnitError):
|
|
30
|
+
convert_mass(10, Mass.GRAM, "non enum")
|
|
31
|
+
|
|
32
|
+
# Unit is category mismatch
|
|
33
|
+
with pytest.raises(InvalidUnitError):
|
|
34
|
+
convert_mass(10, Distance.FEET, Mass.POUND)
|
|
35
|
+
|
|
36
|
+
with pytest.raises(InvalidUnitError):
|
|
37
|
+
convert_mass(10, Mass.TONNE, Distance.YARDS)
|
|
38
|
+
|
|
39
|
+
# Enum is from Mass class
|
|
40
|
+
with pytest.raises(InvalidUnitError):
|
|
41
|
+
convert_mass(10, Distance.CENTIMETERS, Distance.INCHES)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Testing Library"""
|
|
2
|
+
import pytest
|
|
3
|
+
from unitx import Distance, Temperature, convert_temperature
|
|
4
|
+
from unitx import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
5
|
+
|
|
6
|
+
def test_conversion():
|
|
7
|
+
"""Tests the conversion so its converting right."""
|
|
8
|
+
|
|
9
|
+
converted = convert_temperature(10, Temperature.CELSIUS, Temperature.KELVIN) # Metric Conversion
|
|
10
|
+
assert converted == 283.15
|
|
11
|
+
|
|
12
|
+
converted = convert_temperature(32, Temperature.FAHRENHEIT, Temperature.RANKINE) # Imperial Conversion
|
|
13
|
+
assert round(converted, 3) == 491.67
|
|
14
|
+
|
|
15
|
+
converted = convert_temperature(0, Temperature.CELSIUS, Temperature.FAHRENHEIT) # Metric --> Imperial
|
|
16
|
+
assert converted == 32
|
|
17
|
+
|
|
18
|
+
converted = convert_temperature(10, Temperature.KELVIN, Temperature.CELSIUS) # codecov
|
|
19
|
+
assert converted == -263.15
|
|
20
|
+
|
|
21
|
+
converted = convert_temperature(10, Temperature.RANKINE, Temperature.FAHRENHEIT) # codecov
|
|
22
|
+
assert round(converted, 5) == -449.67
|
|
23
|
+
|
|
24
|
+
def test_errors():
|
|
25
|
+
"""Tests the conversion errors so its been handled properly."""
|
|
26
|
+
|
|
27
|
+
# Value is non numeric
|
|
28
|
+
with pytest.raises(NonNumericError):
|
|
29
|
+
convert_temperature("string", Temperature.CELSIUS, Temperature.FAHRENHEIT)
|
|
30
|
+
|
|
31
|
+
# Unit is not enum
|
|
32
|
+
with pytest.raises(UnsupportedUnitError):
|
|
33
|
+
convert_temperature(10, "non enum", Temperature.CELSIUS)
|
|
34
|
+
|
|
35
|
+
with pytest.raises(UnsupportedUnitError):
|
|
36
|
+
convert_temperature(10, Temperature.RANKINE, "non enum")
|
|
37
|
+
|
|
38
|
+
# Unit is category mismatch
|
|
39
|
+
with pytest.raises(InvalidUnitError):
|
|
40
|
+
convert_temperature(10, Distance.FEET, Temperature.CELSIUS)
|
|
41
|
+
|
|
42
|
+
with pytest.raises(InvalidUnitError):
|
|
43
|
+
convert_temperature(10, Temperature.RANKINE, Distance.YARDS)
|
|
44
|
+
|
|
45
|
+
# Enum is from Temperature class
|
|
46
|
+
with pytest.raises(InvalidUnitError):
|
|
47
|
+
convert_temperature(10, Distance.CENTIMETERS, Distance.INCHES)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Testing Library"""
|
|
2
|
+
import pytest
|
|
3
|
+
from unitx import Distance, Volume, convert_volume
|
|
4
|
+
from unitx import InvalidUnitError, NonNumericError, UnsupportedUnitError
|
|
5
|
+
|
|
6
|
+
def test_conversion():
|
|
7
|
+
"""Tests the conversion so its converting right."""
|
|
8
|
+
|
|
9
|
+
converted = convert_volume(10, Volume.LITER, Volume.MILLILITER) # Metric Conversion
|
|
10
|
+
assert converted == 10000
|
|
11
|
+
|
|
12
|
+
converted = convert_volume(10, Volume.GALLON_US, Volume.PINT_US) # Imperial Conversion
|
|
13
|
+
assert round(converted, 3) == 80
|
|
14
|
+
|
|
15
|
+
converted = convert_volume(10, Volume.CUBIC_METER, Volume.PINT_US) # Metric --> Imperial
|
|
16
|
+
assert converted == 21133.78531455526
|
|
17
|
+
|
|
18
|
+
def test_errors():
|
|
19
|
+
"""Tests the conversion errors so its been handled properly."""
|
|
20
|
+
|
|
21
|
+
# Value is non numeric
|
|
22
|
+
with pytest.raises(NonNumericError):
|
|
23
|
+
convert_volume("string", Volume.GALLON_US, Volume.MILLILITER)
|
|
24
|
+
|
|
25
|
+
# Unit is not enum
|
|
26
|
+
with pytest.raises(UnsupportedUnitError):
|
|
27
|
+
convert_volume(10, "non enum", Volume.PINT_US)
|
|
28
|
+
|
|
29
|
+
with pytest.raises(UnsupportedUnitError):
|
|
30
|
+
convert_volume(10, Volume.GALLON_US, "non enum")
|
|
31
|
+
|
|
32
|
+
# Unit is category mismatch
|
|
33
|
+
with pytest.raises(InvalidUnitError):
|
|
34
|
+
convert_volume(10, Distance.FEET, Volume.CUBIC_METER)
|
|
35
|
+
|
|
36
|
+
with pytest.raises(InvalidUnitError):
|
|
37
|
+
convert_volume(10, Volume.PINT_US, Distance.YARDS)
|
|
38
|
+
|
|
39
|
+
# Enum is from Volume class
|
|
40
|
+
with pytest.raises(InvalidUnitError):
|
|
41
|
+
convert_volume(10, Distance.CENTIMETERS, Distance.INCHES)
|