Skip to content

Commit

Permalink
Merge pull request #27 from OxfordRSE/issue25-fix-imports
Browse files Browse the repository at this point in the history
Fix for issue 25: Imports not working
  • Loading branch information
mjaquiery authored Oct 12, 2023
2 parents 737e2fe + 0cfdd60 commit 70fdb37
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
venv/

.idea/

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ Units are converted to one another by asking one unit to convert to the other.
The `Unit.to_unit` function takes a number and a target `Unit`.

```python
import oxrse_unit_conv
from oxrse_unit_conv import km, mile

n = 42
km = oxrse_unit_conv.km
mile = oxrse_unit_conv.mile
print(f"{n}{km.abbr} in {mile} = {km.to_unit(n, mile)}")
```

Expand Down
4 changes: 2 additions & 2 deletions src/oxrse_unit_conv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .units import *
from .main import convert, click_convert
from oxrse_unit_conv.units import *
from oxrse_unit_conv.main import convert, click_convert
10 changes: 5 additions & 5 deletions src/oxrse_unit_conv/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Click interface to allow running from command line
import units
import meta.classes
from oxrse_unit_conv import units
from oxrse_unit_conv.meta import classes
import click
import logging

Expand All @@ -25,15 +25,15 @@ def click_convert(number, unit, to):
click.echo(convert(number, unit, to))


def convert(number: meta.classes.Number, unit: str, to: str):
def convert(number: classes.Number, unit: str, to: str):
logging.debug(f"Call: {number}: {unit} -> {to}")

my_unit: units.Unit = getattr(units, unit)
if not isinstance(my_unit, meta.classes.BaseUnit):
if not isinstance(my_unit, classes.BaseUnit):
raise TypeError(f"{unit} does not correspond to a known unit.")
if to:
target_unit = getattr(units, to)
if not isinstance(target_unit, meta.classes.BaseUnit):
if not isinstance(target_unit, classes.BaseUnit):
raise TypeError(f"{to} does not correspond to a known unit.")
else:
target_unit = my_unit.si_unit
Expand Down
2 changes: 1 addition & 1 deletion src/oxrse_unit_conv/si.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# the first unit is converted to the SI unit,
# and then the SI unit is converted to the second unit.

from meta import classes
from oxrse_unit_conv.meta import classes

second = classes.SIUnit("second", "s")
s = second
Expand Down
4 changes: 2 additions & 2 deletions src/oxrse_unit_conv/units.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from si import *
from meta.classes import Unit
from oxrse_unit_conv.si import *
from oxrse_unit_conv.meta.classes import Unit

# second
minute = Unit(name='minute', abbr='min', si=second, to_si_fun=lambda n: n * 60)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_conversion_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from oxrse_unit_conv.meta import classes
from oxrse_unit_conv import kilometer, m, m2, m3, s, hour
from oxrse_unit_conv.units import kilometer, m, m2, m3, s, hour


class TestConversionCore(unittest.TestCase):
Expand Down

0 comments on commit 70fdb37

Please sign in to comment.