Skip to content

Commit b45d0ae

Browse files
committed
Rename modules, adjust imports, move build_examples.py
1 parent 6c84db7 commit b45d0ae

File tree

13 files changed

+315
-327
lines changed

13 files changed

+315
-327
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
python -m pip install --upgrade pip
2323
pip install .
2424
- name: Create Examples
25-
run: PYTHONPATH=$(pwd)/src:$PYTHONPATH cd src/wireviz/ && python build_examples.py
25+
run: PYTHONPATH=$(pwd)/src:$PYTHONPATH && python src/wireviz/tools/build_examples.py
2626
- name: Upload examples, demos, and tutorials
2727
uses: actions/upload-artifact@v2
2828
with:
2929
name: examples-and-tutorials
3030
path: |
3131
examples/
32-
tutorial/
32+
tutorial/

src/wireviz/svgembed.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/wireviz/build_examples.py renamed to src/wireviz/tools/build_examples.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
from pathlib import Path
88

99
script_path = Path(__file__).absolute()
10-
11-
sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module
12-
from wv_helper import open_file_append, open_file_read, open_file_write
10+
sys.path.insert(0, str(script_path.parent.parent.parent)) # to find wireviz module
1311

1412
from wireviz import APP_NAME, __version__, wireviz
13+
from wireviz.wv_utils import open_file_append, open_file_read, open_file_write
1514

16-
dir = script_path.parent.parent.parent
15+
dir = script_path.parent.parent.parent.parent
1716
readme = "readme.md"
1817
groups = {
1918
"examples": {

src/wireviz/wireviz.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
if __name__ == "__main__":
1111
sys.path.insert(0, str(Path(__file__).parent.parent)) # add src/wireviz to PATH
1212

13-
from wireviz.DataClasses import AUTOGENERATED_PREFIX, Metadata, Options, Tweak
14-
from wireviz.Harness import Harness
15-
from wireviz.wv_helper import (
13+
from wireviz.wv_dataclasses import AUTOGENERATED_PREFIX, Metadata, Options, Tweak
14+
from wireviz.wv_harness import Harness
15+
from wireviz.wv_utils import (
1616
expand,
1717
get_single_key_and_value,
1818
is_arrow,
@@ -396,19 +396,12 @@ def alternate_type(): # flip between connector and cable/arrow
396396
def _get_yaml_data_and_path(inp: Union[str, Path, Dict]) -> (Dict, Path):
397397
# determine whether inp is a file path, a YAML string, or a Dict
398398
if not isinstance(inp, Dict): # received a str or a Path
399-
try:
399+
if isinstance(inp, Path) or (isinstance(inp, str) and not "\n" in inp):
400400
yaml_path = Path(inp).expanduser().resolve(strict=True)
401-
# if no FileNotFoundError exception happens, get file contents
402401
yaml_str = open_file_read(yaml_path).read()
403-
except (FileNotFoundError, OSError) as e:
404-
# if inp is a long YAML string, Pathlib will raise OSError: [Errno 63]
405-
# when trying to expand and resolve it as a path.
406-
# Catch this error, but raise any others
407-
if type(e) is OSError and e.errno != 63:
408-
raise e
409-
# file does not exist; assume inp is a YAML string
410-
yaml_str = inp
402+
else:
411403
yaml_path = None
404+
yaml_str = inp
412405
yaml_data = yaml.safe_load(yaml_str)
413406
else:
414407
# received a Dict, use as-is

src/wireviz/wv_bom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from enum import Enum
66
from typing import List, Optional, Union
77

8-
from wireviz.wv_helper import html_line_breaks
8+
from wireviz.wv_utils import html_line_breaks
99

1010
BOM_HASH_FIELDS = "description unit partnumbers"
1111
BomHash = namedtuple("BomHash", BOM_HASH_FIELDS)

src/wireviz/wv_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import wireviz.wireviz as wv
1313
from wireviz import APP_NAME, __version__
14-
from wireviz.wv_helper import open_file_read
14+
from wireviz.wv_utils import open_file_read
1515

1616
format_codes = {
1717
"c": "csv",
@@ -23,10 +23,11 @@
2323
"t": "tsv",
2424
}
2525

26+
2627
epilog = (
2728
"The -f or --format option accepts a string containing one or more of the "
2829
"following characters to specify which file types to output:\n"
29-
f", ".join([f"{key} ({value.upper()})" for key, value in format_codes.items()])
30+
+ f", ".join([f"{key} ({value.upper()})" for key, value in format_codes.items()])
3031
)
3132

3233

src/wireviz/DataClasses.py renamed to src/wireviz/wv_dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SingleColor,
1515
get_color_by_colorcode_index,
1616
)
17-
from wireviz.wv_helper import aspect_ratio, awg_equiv, mm2_equiv, remove_links
17+
from wireviz.wv_utils import aspect_ratio, awg_equiv, mm2_equiv, remove_links
1818

1919
# Each type alias have their legal values described in comments
2020
# - validation might be implemented in the future

src/wireviz/wv_gv_html.py renamed to src/wireviz/wv_graphviz.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from typing import Any, List, Union
66

77
from wireviz import APP_NAME, APP_URL, __version__
8-
from wireviz.DataClasses import (
8+
from wireviz.wv_bom import partnumbers_to_list
9+
from wireviz.wv_dataclasses import (
910
ArrowDirection,
1011
ArrowWeight,
1112
Cable,
@@ -18,9 +19,8 @@
1819
ShieldClass,
1920
WireClass,
2021
)
21-
from wireviz.wv_bom import partnumbers_to_list
22-
from wireviz.wv_helper import html_line_breaks, remove_links
23-
from wireviz.wv_table_util import * # TODO: explicitly import each needed tag later
22+
from wireviz.wv_html import Img, Table, Td, Tr
23+
from wireviz.wv_utils import html_line_breaks, remove_links
2424

2525

2626
def gv_node_component(component: Component) -> Table:

src/wireviz/Harness.py renamed to src/wireviz/wv_harness.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from graphviz import Graph
99

1010
import wireviz.wv_colors
11-
from wireviz.DataClasses import (
11+
from wireviz.wv_dataclasses import (
1212
AUTOGENERATED_PREFIX,
1313
AdditionalComponent,
1414
Arrow,
@@ -23,8 +23,7 @@
2323
Side,
2424
Tweak,
2525
)
26-
from wireviz.svgembed import embed_svg_images_file
27-
from wireviz.wv_gv_html import (
26+
from wireviz.wv_graphviz import (
2827
apply_dot_tweaks,
2928
calculate_node_bgcolor,
3029
gv_connector_loops,
@@ -34,8 +33,8 @@
3433
parse_arrow_str,
3534
set_dot_basics,
3635
)
37-
from wireviz.wv_helper import open_file_write, tuplelist2tsv
38-
from wireviz.wv_html import generate_html_output
36+
from wireviz.wv_output import embed_svg_images_file, generate_html_output
37+
from wireviz.wv_utils import open_file_write, tuplelist2tsv
3938

4039

4140
@dataclass

0 commit comments

Comments
 (0)