Skip to content

Commit b297462

Browse files
committed
New test, revert pydot-use in CI, clean-up
1 parent 1e4e80d commit b297462

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ucumvert is available as Python package from [PyPi](https://pypi.org/project/ucu
3434
pip install ucumvert
3535
```
3636

37-
To install the most recent code from git in developer mode including creation of a virtual environment (pip should be newer than 23.1) use:
37+
To install the most recent code from git in developer mode including creation of a virtual environment use:
3838

3939
Linux
4040

@@ -43,6 +43,7 @@ git clone https://github.com/dalito/ucumvert.git
4343
cd ucumvert
4444
python -m venv .venv
4545
source .venv/bin/activate
46+
python -m pip install --upgrade pip
4647
pip install -e .[dev]
4748
```
4849

@@ -53,6 +54,7 @@ git clone https://github.com/dalito/ucumvert.git
5354
cd ucumvert
5455
py -m venv .venv
5556
.venv\Scripts\activate.bat
57+
py -m pip install --upgrade pip
5658
pip install -e .[dev]
5759
```
5860

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ Changelog = "https://github.com/nfdi4cat/ucumvert/blob/main/CHANGELOG.md"
5050
tests = [
5151
"pytest",
5252
"coverage",
53-
"pydot",
5453
]
5554
lint = [
5655
"black",
5756
]
5857
dev = [
59-
"ucumvert[tests,lint]",
60-
"ruff",
61-
"openpyxl",
58+
"ucumvert[tests,lint]",
59+
"ruff",
60+
"openpyxl",
61+
"pydot",
6262
]
6363

6464
[project.scripts]

src/ucumvert/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from ucumvert.parser import (
88
get_ucum_parser,
9-
make_parse_tree_png,
109
update_lark_ucum_grammar_file,
1110
)
1211
from ucumvert.ucum_pint import (
@@ -22,7 +21,7 @@
2221
__version__ = "0.0.0"
2322
__version_tuple__ = (0, 0, 0)
2423

25-
try:
24+
try: # pragma: no cover
2625
import pydot # noqa: F401
2726

2827
HAS_PYDOT = True
@@ -31,7 +30,6 @@
3130

3231
__all__ = [
3332
"get_ucum_parser",
34-
"make_parse_tree_png",
3533
"ucum_preprocessor",
3634
"update_lark_ucum_grammar_file",
3735
"UcumToPintTransformer",

src/ucumvert/cli.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import textwrap
55
from pathlib import Path
66

7+
from lark import tree
78
from lark.exceptions import LarkError, UnexpectedInput, VisitError
89

910
import ucumvert
1011
from ucumvert.parser import (
1112
get_ucum_parser,
12-
make_parse_tree_png,
1313
update_lark_ucum_grammar_file,
1414
)
1515
from ucumvert.ucum_pint import UcumToPintTransformer, find_matching_pint_definitions
@@ -31,13 +31,9 @@ def interactive():
3131
if ucum_code and (ucum_code in "qQ"):
3232
break
3333
try:
34+
parsed_data = ucum_parser.parse(ucum_code)
3435
if ucumvert.HAS_PYDOT:
35-
parsed_data = make_parse_tree_png(
36-
ucum_parser, ucum_code, filename="parse_tree.png"
37-
)
38-
print("Created visualization of parse tree (parse_tree.png).")
39-
else:
40-
parsed_data = ucum_parser.parse(ucum_code)
36+
tree.pydot__tree_to_png(parsed_data, "parse_tree_unit.png")
4137
print(parsed_data.pretty())
4238
except UnexpectedInput as e:
4339
print(e)

src/ucumvert/parser.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import textwrap
55
from pathlib import Path
66

7-
from lark import Lark, Transformer, tree
7+
from lark import Lark, Transformer
88

99
import ucumvert
1010
from ucumvert.xml_util import (
@@ -175,9 +175,3 @@ def get_ucum_parser(grammar_file=None):
175175
with grammar_file.open("r", encoding="utf8") as f:
176176
ucum_grammar = f.read()
177177
return Lark(ucum_grammar, start="main_term", strict=True)
178-
179-
180-
def make_parse_tree_png(parser, data, filename="parse_tree_unit.png"):
181-
parsed_data = parser.parse(data)
182-
tree.pydot__tree_to_png(parsed_data, filename)
183-
return parsed_data

src/ucumvert/ucum_pint.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from ucumvert.parser import (
1616
get_ucum_parser,
17-
make_parse_tree_png,
1817
)
1918
from ucumvert.xml_util import (
2019
get_metric_units,
@@ -380,7 +379,6 @@ def run_examples(): # pragma: no cover
380379
parser = get_ucum_parser()
381380
for unit in test_ucum_units:
382381
print("parsing ucum code:", unit)
383-
make_parse_tree_png(unit, filename="parse_tree.png")
384382
parsed_data = parser.parse(unit)
385383
q = UcumToPintTransformer().transform(parsed_data)
386384
print(f"Pint {q!r}")

tests/test_xm_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ucumvert.xml_util import get_metric_units, get_non_metric_units, get_units
2+
3+
4+
def test_get_units():
5+
assert len(get_units()) == 303 # noqa: PLR2004
6+
assert set(get_units()) == set(get_metric_units() + get_non_metric_units())

0 commit comments

Comments
 (0)