Skip to content

Commit 732f617

Browse files
committed
Organized Python libraries into modules.
1 parent 1f8d876 commit 732f617

25 files changed

+197
-128
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
shell: bash
8383

8484
- name: Benchmark
85-
run: python tools/benchmark.py -g
85+
run: python -m tools.benchmark -g
8686
shell: bash
8787

8888
- name: Upload Graphs

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
shell: bash
5151

5252
- name: Lint
53-
run: python tools/run_clang_tidy.py -source-filter='.*lib.*' -p build
53+
run: python -m tools.run_clang_tidy -source-filter='.*lib.*' -p build

__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#####################################################################################################
2+
# Copyright (c) 2023-2024 NWSOFT #
3+
# #
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
5+
# of this software and associated documentation files (the "Software"), to deal #
6+
# in the Software without restriction, including without limitation the rights #
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
8+
# copies of the Software, and to permit persons to whom the Software is #
9+
# furnished to do so, subject to the following conditions: #
10+
# #
11+
# The above copyright notice and this permission notice shall be included in all #
12+
# copies or substantial portions of the Software. #
13+
# #
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
20+
# SOFTWARE. #
21+
#####################################################################################################

lib/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#####################################################################################################
2+
# Copyright (c) 2023-2024 NWSOFT #
3+
# #
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
5+
# of this software and associated documentation files (the "Software"), to deal #
6+
# in the Software without restriction, including without limitation the rights #
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
8+
# copies of the Software, and to permit persons to whom the Software is #
9+
# furnished to do so, subject to the following conditions: #
10+
# #
11+
# The above copyright notice and this permission notice shall be included in all #
12+
# copies or substantial portions of the Software. #
13+
# #
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
20+
# SOFTWARE. #
21+
#####################################################################################################
22+
23+
pass

lib/config.py

Whitespace-only changes.

lib/constants.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#####################################################################################################
2+
# Copyright (c) 2023-2024 NWSOFT #
3+
# #
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
5+
# of this software and associated documentation files (the "Software"), to deal #
6+
# in the Software without restriction, including without limitation the rights #
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
8+
# copies of the Software, and to permit persons to whom the Software is #
9+
# furnished to do so, subject to the following conditions: #
10+
# #
11+
# The above copyright notice and this permission notice shall be included in all #
12+
# copies or substantial portions of the Software. #
13+
# #
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
20+
# SOFTWARE. #
21+
#####################################################################################################
22+
23+
import platform
24+
25+
WINDOWS = platform.system() == "Windows"
26+
MACOSX = platform.system() == "Darwin"
27+
LINUX = platform.system() == "Linux"

tools/building/paths.py renamed to lib/paths.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626

2727
from pathlib import Path
2828

29+
# section Project paths
2930
PROJECT = "Steppable"
3031

31-
PROJECT_PATH = Path(__file__).parent.parent.parent
32+
PROJECT_PATH = Path(__file__).parent.parent
3233
SRC_DIR = PROJECT_PATH / "src"
3334
TESTS_DIR = PROJECT_PATH / "tests"
3435
INCLUDE_DIR = PROJECT_PATH / "include"
@@ -37,7 +38,4 @@
3738
OBJ_DIR = BUILD_DIR / "obj.temp"
3839
BIN_DIR = BUILD_DIR / "bin"
3940
LIB_DIR = BUILD_DIR / "lib"
40-
41-
STATIC = 0
42-
SHARED = 1
43-
EXECUTABLE = 2
41+
# endsection

tools/building/printing.py renamed to lib/printing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import sys
2424

25-
from building.directories import WINDOWS
25+
from lib.constants import WINDOWS
2626

2727

2828
def green() -> str:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ requires-python = ">= 3.10"
1212
dynamic = ["classifiers", "optional-dependencies"]
1313

1414
dependencies = [
15-
"matplotlib",
16-
"black",
17-
"isort",
15+
"matplotlib >= 3.9.0",
16+
"black >= 24.4.2",
17+
"isort >= 5.13.2",
1818
"setuptools >= 61.0",
1919
"nanobind >= 1.9.2"
2020
]

tests/random_tests/random_test_base.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,11 @@
2020
# SOFTWARE. #
2121
#####################################################################################################
2222

23-
import os
2423
import random
2524
import subprocess
2625
import time
2726

28-
29-
def green():
30-
"""
31-
Changes the output color to green, only if the output console is a terminal.
32-
"""
33-
if os.isatty(0):
34-
return "\033[92m"
35-
return ""
36-
37-
38-
def red():
39-
"""
40-
Changes the output color to red, only if the output console is a terminal.
41-
"""
42-
if os.isatty(0):
43-
return "\033[91m"
44-
return ""
45-
46-
47-
def reset():
48-
"""
49-
Resets output color, only if the output console is a terminal.
50-
"""
51-
if os.isatty(0):
52-
return "\033[0;0m"
53-
return ""
54-
55-
56-
def bold():
57-
"""
58-
Changes the output color to bold, only if the output console is a terminal.
59-
"""
60-
if os.isatty(0):
61-
return "\033[1m"
62-
return ""
27+
from lib.printing import bold, green, red, reset
6328

6429

6530
class RandomTest:
@@ -68,11 +33,11 @@ class RandomTest:
6833
"""
6934

7035
def __init__(
71-
self,
72-
executable="",
73-
times: int = 100,
74-
expression: str = "{} / {}",
75-
rounding: bool = True,
36+
self,
37+
executable="",
38+
times: int = 100,
39+
expression: str = "{} / {}",
40+
rounding: bool = True,
7641
):
7742
self.times = times
7843
if executable == "":
@@ -116,7 +81,7 @@ def random_test(self):
11681
python_output = eval(expression)
11782
print(
11883
f"\033[K\033[A\rTest [{i + 1}/{self.times}|{(i + 1) / self.times * 100:2.1f}%] - ",
119-
end=""
84+
end="",
12085
)
12186

12287
diff = abs(python_output - output)
@@ -146,7 +111,7 @@ def summary(self):
146111
+ reset()
147112
)
148113
for idx, (number1, number2, output, python_output) in enumerate(
149-
self.failed
114+
self.failed
150115
):
151116
print(f"TEST {idx + 1}")
152117
print(f" {self.expression.format(number1, number2)}")

tests/random_tests/test_add.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#####################################################################################################
2222

2323
from random_test_base import RandomTest
24-
from pathlib import Path
2524

26-
TOOL_PATH = Path(__file__).parent.parent.parent / "build" / "bin" / "add"
25+
from lib.paths import PROJECT_PATH
26+
27+
TOOL_PATH = PROJECT_PATH / "build" / "bin" / "add"
2728
r = RandomTest(TOOL_PATH.as_posix(), expression="{} + {}", rounding=False)
2829
r.random_test()

tests/random_tests/test_division.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#####################################################################################################
2222

2323
from random_test_base import RandomTest
24-
from pathlib import Path
2524

26-
TOOL_PATH = Path(__file__).parent.parent.parent / "build" / "bin" / "division"
25+
from lib.paths import PROJECT_PATH
26+
27+
TOOL_PATH = PROJECT_PATH / "build" / "bin" / "division"
2728
r = RandomTest(TOOL_PATH.as_posix(), expression="{} / {}")
2829
r.random_test()

tests/random_tests/test_multiply.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
# SOFTWARE. #
2121
#####################################################################################################
2222

23-
from pathlib import Path
24-
2523
from random_test_base import RandomTest
2624

27-
TOOL_PATH = Path(__file__).parent.parent.parent / "build" / "bin" / "multiply"
25+
from lib.paths import PROJECT_PATH
26+
27+
TOOL_PATH = PROJECT_PATH / "build" / "bin" / "multiply"
2828
r = RandomTest(TOOL_PATH.as_posix(), expression="{} * {}", rounding=False)
2929
r.random_test()

tests/random_tests/test_subtract.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#####################################################################################################
2222

2323
from random_test_base import RandomTest
24-
from pathlib import Path
2524

26-
TOOL_PATH = Path(__file__).parent.parent.parent / "build" / "bin" / "subtract"
25+
from lib.paths import PROJECT_PATH
26+
27+
TOOL_PATH = PROJECT_PATH / "build" / "bin" / "subtract"
2728
r = RandomTest(TOOL_PATH.as_posix(), expression="{} - {}", rounding=False)
2829
r.random_test()

tools/add_copyright_header.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def first_n_lines(text: str, n: int) -> str:
138138

139139
def process(file: Path):
140140
if (
141-
file.suffix in [".cpp", ".hpp"] or file.name == "cpp.hint"
141+
file.suffix in [".cpp", ".hpp", ".stp_settings"] or file.name == "cpp.hint"
142142
): # C++ Source / Header
143143
with open(file, "r") as f:
144144
contents = f.read()
@@ -195,9 +195,11 @@ def walk_into_directory(path: Path):
195195
if __name__ == "__main__":
196196
process(PROJECT_PATH / "CMakeLists.txt")
197197
process(PROJECT_PATH / "setup.py")
198+
process(PROJECT_PATH / "__init__.py")
198199
process(PROJECT_PATH / "cpp.hint")
199200
walk_into_directory(PROJECT_PATH / "include")
200201
walk_into_directory(PROJECT_PATH / "lib")
202+
walk_into_directory(PROJECT_PATH / "res")
201203
walk_into_directory(PROJECT_PATH / "src")
202204
walk_into_directory(PROJECT_PATH / "tests")
203205
walk_into_directory(PROJECT_PATH / "tools")

tools/benchmark.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
# SOFTWARE. #
2121
#####################################################################################################
2222

23-
from pathlib import Path
24-
import time
25-
from typing import Callable, List, Tuple
23+
import argparse
2624
import random
2725
import subprocess
28-
import argparse
26+
import time
27+
from pathlib import Path
28+
from typing import Callable, List, Tuple
29+
30+
from lib.paths import PROJECT_PATH
2931

30-
ROOT_PATH = Path(__file__).parent.parent
3132
BUILD_PATH_DEFAULT = "build"
3233

3334
FUNCTIONS = {
@@ -133,7 +134,7 @@ def main():
133134

134135
LIMIT = int(args.limit)
135136

136-
build_dir = Path(ROOT_PATH / args.build_dir).resolve()
137+
build_dir = Path(PROJECT_PATH / args.build_dir).resolve()
137138
if not build_dir.exists():
138139
print(f"Build directory {build_dir} does not exist.")
139140
return
@@ -169,7 +170,7 @@ def main():
169170
if (not args.graph) and args.verbose:
170171
print(f"Times: {times}")
171172
if args.graph:
172-
img_path = ROOT_PATH / "tools" / "figures" / f"benchmark_{exe.stem}.svg"
173+
img_path = PROJECT_PATH / "tools" / "figures" / f"benchmark_{exe.stem}.svg"
173174
print(f"Saving as {img_path}")
174175

175176
import matplotlib.pyplot as plt

tools/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
import logging
2828

29-
from building.directories import create_build_dirs
30-
from building.paths import BUILD_DIR
31-
from building.project import BuildSteppable
29+
from lib.paths import BUILD_DIR
30+
from tools.building.directories import create_build_dirs
31+
from tools.building.project import BuildSteppable
3232

3333
logger = logging.getLogger(__name__)
3434

tools/building/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#####################################################################################################
2+
# Copyright (c) 2023-2024 NWSOFT #
3+
# #
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
5+
# of this software and associated documentation files (the "Software"), to deal #
6+
# in the Software without restriction, including without limitation the rights #
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
8+
# copies of the Software, and to permit persons to whom the Software is #
9+
# furnished to do so, subject to the following conditions: #
10+
# #
11+
# The above copyright notice and this permission notice shall be included in all #
12+
# copies or substantial portions of the Software. #
13+
# #
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
20+
# SOFTWARE. #
21+
#####################################################################################################
22+
23+
pass

tools/building/compiler_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import subprocess
3232
from pathlib import Path
3333

34-
from building.paths import BUILD_DIR
34+
from lib.paths import BUILD_DIR
3535

3636
GCC_VERSION_RE = re.compile(r"g\+\+ (\(.+?\))? (\d+\.\d+\.\d+)")
3737
CLANG_VERSION_RE = re.compile(r"version (\d+\.\d+\.\d+)")

0 commit comments

Comments
 (0)