Skip to content

Commit

Permalink
fixed some import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
flxdot committed Jul 26, 2019
1 parent 502b8eb commit f750749
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
17 changes: 17 additions & 0 deletions pyUnitTypes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pathlib import Path
import sys
import inspect
import pkgutil
from importlib import import_module

# make sure to add all dynamically created classes to the modules
# found at: https://www.bnmetrics.com/blog/dynamic-import-in-python3
for (_, name, _) in pkgutil.iter_modules([Path(__file__).parent]):

imported_module = import_module('.' + name, package=__name__)

for i in dir(imported_module):
attribute = getattr(imported_module, i)

if inspect.isclass(attribute):
setattr(sys.modules[__name__], name, attribute)
3 changes: 2 additions & 1 deletion pyUnitTypes/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(self, value=float()):
class_name = '{}Ampere'.format(name)

# generate the new class
generatedClass = class_factory(BaseClass=Current, name=class_name, symbol=symbol, to_base=Conversion(base10))
generatedClass = class_factory(BaseClass=Current, name='{}A'.format(symbol), symbol=symbol,
to_base=Conversion(base10))
# register the class to the module
globals()[generatedClass.__name__] = generatedClass
# get rid of the temporary stuff
Expand Down
3 changes: 2 additions & 1 deletion pyUnitTypes/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def __init__(self, value=float()):
class_name = '{}Meter'.format(name)

# generate the new class
generatedClass = class_factory(BaseClass=Length, name=class_name, symbol=symbol, to_base=Conversion(base10))
generatedClass = class_factory(BaseClass=Length, name=class_name, symbol='{}m'.format(symbol),
to_base=Conversion(base10))
# register the class to the module
globals()[generatedClass.__name__] = generatedClass
# get rid of the temporary stuff
Expand Down
6 changes: 4 additions & 2 deletions pyUnitTypes/mass.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pyUnitTypes.basics import BaseUnit, Conversion, SI_PREFIXES
from pyUnitTypes.auxiliary import class_factory

Expand Down Expand Up @@ -121,13 +122,14 @@ def __init__(self, value=float()):
for name, symbol, base10 in SI_PREFIXES:
if name == 'Kilo':
continue
class_name = '{}Meter'.format(name)
class_name = '{}Gram'.format(name)

# account for the fact that kilogram is the base unit of the mass
base10 /= 1e3

# generate the new class
generatedClass = class_factory(BaseClass=Mass, name=class_name, symbol=symbol, to_base=Conversion(base10))
generatedClass = class_factory(BaseClass=Mass, name=class_name, symbol='{}g'.format(symbol),
to_base=Conversion(base10))
# register the class to the module
globals()[generatedClass.__name__] = generatedClass
# get rid of the temporary stuff
Expand Down
3 changes: 2 additions & 1 deletion pyUnitTypes/substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def __init__(self, value=float()):
class_name = '{}Mole'.format(name)

# generate the new class
generatedClass = class_factory(BaseClass=Substance, name=class_name, symbol=symbol, to_base=Conversion(base10))
generatedClass = class_factory(BaseClass=Substance, name='{}mol'.format(symbol), symbol=symbol,
to_base=Conversion(base10))
# register the class to the module
globals()[generatedClass.__name__] = generatedClass
# get rid of the temporary stuff
Expand Down

0 comments on commit f750749

Please sign in to comment.