Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 25: Imports not working #27

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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