Skip to content

Commit 118d13c

Browse files
authored
Merge pull request #783 from OpenSimulationInterface/build/modernize-python
Modernize python build setup, protoc dependency
2 parents f9de56c + 2a89e61 commit 118d13c

File tree

10 files changed

+318
-247
lines changed

10 files changed

+318
-247
lines changed

.github/workflows/protobuf.yml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ jobs:
4545
- name: Install Python Dependencies
4646
run: |
4747
python -m pip install --upgrade pip
48-
python -m pip install -r requirements_develop.txt
48+
python -m pip install build
49+
python -m pip install -r requirements_tests.txt
4950
5051
- name: Check black format
51-
run: black --check --diff .
52+
run: |
53+
black --check --diff .
5254
5355
- name: Install Doxygen
5456
run: sudo apt-get install doxygen graphviz
@@ -88,10 +90,14 @@ jobs:
8890
- name: Prepare C++ Build
8991
run: mkdir build
9092

91-
# Versioning
92-
- name: Get versioning
93+
- name: Add Development Version Suffix
94+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
95+
run: |
96+
echo "VERSION_SUFFIX = .dev`date -u '+%Y%m%d%H%M%S'`" >> VERSION
97+
98+
- name: Get git Version
9399
id: get_version
94-
run: echo "VERSION=$(git describe --always)" >> $GITHUB_OUTPUT
100+
run: echo "VERSION=$(git describe --tags --always)" >> $GITHUB_OUTPUT
95101

96102
- name: Prepare Documentation Build
97103
run: |
@@ -108,7 +114,7 @@ jobs:
108114
run: cmake --build . --config Release -j 4
109115

110116
- name: Build Python
111-
run: python setup.py build && python setup.py sdist
117+
run: python -m build
112118

113119
- name: Install Python
114120
run: python -m pip install .
@@ -124,7 +130,14 @@ jobs:
124130
path: doc/html
125131
if-no-files-found: error
126132

127-
- name: deploy to gh-pages if push to master branch
133+
- name: Upload Python Distribution
134+
if: ${{ github.event_name == 'pull_request' }}
135+
uses: actions/upload-artifact@v4
136+
with:
137+
name: python-dist
138+
path: dist/
139+
140+
- name: Deploy to gh-pages if push to master branch
128141
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
129142
uses: peaceiris/actions-gh-pages@v3
130143
with:
@@ -148,7 +161,10 @@ jobs:
148161
python-version: '3.8'
149162

150163
- name: Install Python Dependencies
151-
run: python -m pip install --upgrade pip setuptools wheel pyyaml
164+
run: |
165+
python -m pip install --upgrade pip
166+
python -m pip install build
167+
python -m pip install -r requirements_tests.txt
152168
153169
- name: Cache Dependencies
154170
id: cache-depends
@@ -187,6 +203,11 @@ jobs:
187203
bash convert-to-proto3.sh
188204
rm *.pb2
189205
206+
- name: Add Development Version Suffix
207+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
208+
run: |
209+
echo "VERSION_SUFFIX = .dev`date -u '+%Y%m%d%H%M%S'`" >> VERSION
210+
190211
- name: Configure C++ Build
191212
working-directory: build
192213
run: cmake ${{ env.PROTOBUF_VARIANT =='' && '-DCMAKE_CXX_STANDARD=17' }} ..
@@ -196,7 +217,7 @@ jobs:
196217
run: cmake --build . --config Release -j 4
197218

198219
- name: Build Python
199-
run: python setup.py build && python setup.py sdist
220+
run: python -m build
200221

201222
- name: Install Python
202223
run: python -m pip install .

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ build
2020
cmake_install.cmake
2121
install_manifest.txt
2222
osi_version.proto
23-
version.py
24-
pyproject.toml
2523

2624
compile_commands.json
2725

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include VERSION

format/OSITrace.py

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

format/osi2read.py renamed to osi3trace/osi2read.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
python3 osi2read.py -d trace.osi -o myreadableosifile
66
"""
77

8-
from OSITrace import OSITrace
9-
import struct
10-
import lzma
8+
from osi3trace.osi_trace import OSITrace
119
import argparse
12-
import os
10+
import pathlib
1311

1412

1513
def command_line_arguments():
1614
"""Define and handle command line interface"""
1715

18-
dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
19-
2016
parser = argparse.ArgumentParser(
2117
description="Convert a serialized osi trace file to a readable txth output.",
22-
prog="osi2read converter",
18+
prog="osi2read",
2319
)
2420
parser.add_argument(
25-
"--data", "-d", help="Path to the file with serialized data.", type=str
21+
"--data",
22+
"-d",
23+
help="Path to the file with serialized data.",
24+
type=str,
25+
required=True,
2626
)
2727
parser.add_argument(
2828
"--type",
@@ -37,7 +37,6 @@ def command_line_arguments():
3737
"--output",
3838
"-o",
3939
help="Output name of the file.",
40-
default="converted.txth",
4140
type=str,
4241
required=False,
4342
)
@@ -50,16 +49,17 @@ def main():
5049
args = command_line_arguments()
5150

5251
# Initialize the OSI trace class
53-
trace = OSITrace()
54-
trace.from_file(path=args.data, type_name=args.type)
52+
trace = OSITrace(args.data, args.type)
5553

56-
args.output = args.output.split(".", 1)[0] + ".txth"
54+
if not args.output:
55+
path = pathlib.Path(args.data).with_suffix(".txth")
56+
args.output = str(path)
5757

58-
if args.output == "converted.txth":
59-
args.output = args.data.split(".", 1)[0] + ".txth"
58+
with open(args.output, "wt") as f:
59+
for message in trace:
60+
f.write(str(message))
6061

61-
trace.make_readable(args.output)
62-
trace.scenario_file.close()
62+
trace.close()
6363

6464

6565
if __name__ == "__main__":

0 commit comments

Comments
 (0)