Skip to content

Commit

Permalink
259 fix zip app so pre requisites installed (#260)
Browse files Browse the repository at this point in the history
* 259 - add requirements to build

* 259 - fix artifacts upload

* 259 - add requirements into app

* 259 - fix to arm version

* 259 - add platform to pip install

* 259 - update mac os build

* 259 - add bash script for building zipapp

* 259 - update script

* 259 - update script

* 259 - update script

* 259 - add init file and update script

* 259 - update script

* 259 - fix adding of paths

* 259 - update script

* 259 - set script to use command line argument

* 259 - update wokflow

* 259 - update tests for main_handler name change

* 259 - correct file name

* 259 - remove matplotlib import

* 259 - add lazy install of requirements to script

* 259 - update build script to use temporary directory

* 259 - update README to account for change

* 259 - update workflow

* 259 - change path of artifact

* 259 - reinstate plotting function

* 259 - add docstring
  • Loading branch information
FreddieMatherSmartDCSIT authored Oct 29, 2024
1 parent eb0eca4 commit 145ed6c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
29 changes: 3 additions & 26 deletions .github/workflows/build-push-arifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,11 @@ jobs:
with:
python-version: '3.11'

- name: Create tel2puml-amd.pyz
run: python -m zipapp tel2puml -o tel2puml-amd.pyz
- name: Create tel2puml.pyz
run: ./scripts/build_zip_app.sh

- name: Upload to GitHub Releases
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: tel2puml-amd.pyz

zipapp-arm-build-and-push:
if: |
github.repository == 'xtuml/otel2puml'
&& github.actor != 'dependabot[bot]'
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Create tel2puml-arm.pyz
run: python -m zipapp tel2puml -o tel2puml-arm.pyz

- name: Upload to GitHub Releases
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: tel2puml-arm.pyz
files: dist/tel2puml.pyz
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ Explanation:
Replace `/path/to/` with the actual paths on your local machine.

## Using Python Executable
On each new [release](https://github.com/xtuml/otel2puml/releases) of otel2puml, both an amd and arm python executable are attached as artifacts.
These are downloadable and can be run from the terminal (assuming python is installed). Below is an example of usage using the arm version:
On each new [release](https://github.com/xtuml/otel2puml/releases) of otel2puml, a python executable, `tel2puml.pyz` will be built and distributed with the release.
This is downloadable and can be run from the terminal (assuming python and pip are installed). Below is an example of usage:

```bash
python tel2puml-arm.pyz otel2puml -o /path/to/output -c /path/to/config.yaml
python tel2puml.pyz otel2puml -o /path/to/output -c /path/to/config.yaml
```

Note that:
- an internet connection will be required to download the dependencies for the first time.
- pip must be resolvable in the terminal as `pip` for the dependencies to be installed.

## Dependencies

TEL2PUML depends on one other repository:
Expand Down
40 changes: 40 additions & 0 deletions scripts/build_zip_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# Fail if any part of this script fails
set -e

# install zipapps
pip install zipapps

# make dist directory
mkdir -p dist

# get current directory
DIR=$(pwd)

# make temp build directory
mkdir -p /tmp/otel2puml_build

# copy files to build directory
cp -r tel2puml /tmp/otel2puml_build/tel2puml
cp -r requirements.txt /tmp/otel2puml_build/requirements.txt


# get janus
git clone https://github.com/xtuml/janus.git /tmp/otel2puml_build/janus
cd /tmp/otel2puml_build/janus
git fetch --all --tags
git checkout tags/v1.0.0 -b latest
cp -r test_event_generator /tmp/otel2puml_build/test_event_generator
cp requirements.txt /tmp/otel2puml_build/janus_requirements.txt



# change directory to build directory
cd /tmp/otel2puml_build
# create zipapp
python -m zipapps -c -a tel2puml,test_event_generator \
-m tel2puml.__main__:main -o $DIR/dist/tel2puml.pyz -d -r requirements.txt -r janus_requirements.txt

# return to original directory
cd $DIR
Empty file added tel2puml/__init__.py
Empty file.
14 changes: 9 additions & 5 deletions tel2puml/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from tel2puml.otel_to_pv.data_sources.json_data_source.json_jq_converter \
import JQCompileError, JQExtractionError

warnings.filterwarnings("ignore")

ERROR_MESSAGES = {
ValidationError: "Input validation failed. Please check the input data.",
Expand Down Expand Up @@ -319,7 +320,7 @@ def handle_exception(
exit(1)


def main(
def main_handler(
args_dict: dict[str, Any],
errors_lookup: dict[Type[Exception], str],
) -> None:
Expand Down Expand Up @@ -355,9 +356,12 @@ def main(
handle_exception(e, debug)


if __name__ == "__main__":
warnings.filterwarnings("ignore")

def main() -> None:
"""Main function to execute the tel2puml command."""
args: argparse.Namespace = parser.parse_args()
args_dict = vars(args)
main(args_dict, ERROR_MESSAGES)
main_handler(args_dict, ERROR_MESSAGES)


if __name__ == "__main__":
main()
14 changes: 7 additions & 7 deletions tests/tel2puml/main/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
find_files,
generate_component_options,
handle_exception,
main,
main_handler,
)
from tel2puml.otel_to_pv.data_sources.json_data_source.json_jq_converter \
import JQCompileError, JQExtractionError
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_handle_exception(
)


def test_main_error_handling(
def test_main_handler_error_handling(
monkeypatch: MonkeyPatch,
capfd: CaptureFixture[str],
) -> None:
Expand Down Expand Up @@ -261,7 +261,7 @@ def test_main_error_handling(
) as mock_generate_options:
mock_generate_options.side_effect = JQCompileError("Test error")

main(args_dict, errors_lookup)
main_handler(args_dict, errors_lookup)
captured = capfd.readouterr()
# Check if the correct error message was printed
assert (
Expand All @@ -277,7 +277,7 @@ def test_main_error_handling(
) as mock_generate_options:
mock_generate_options.side_effect = JQExtractionError("Test error")

main(args_dict, errors_lookup)
main_handler(args_dict, errors_lookup)
captured = capfd.readouterr()
# Check if the correct error message was printed
assert (
Expand All @@ -295,7 +295,7 @@ def test_main_error_handling(
"JSONDecodeError", "", 0
)

main(args_dict, errors_lookup)
main_handler(args_dict, errors_lookup)
captured = capfd.readouterr()
# Check if the correct error message was printed
assert (
Expand All @@ -316,7 +316,7 @@ def test_main_error_handling(
ValidationError.from_exception_data("Invalid data", line_errors=[])
)

main(args_dict, errors_lookup)
main_handler(args_dict, errors_lookup)
captured = capfd.readouterr()
# Check if the correct error message was printed
assert (
Expand All @@ -333,7 +333,7 @@ def test_main_error_handling(
) as mock_generate_options:
mock_generate_options.side_effect = Exception("Unexpected error")

main(args_dict, errors_lookup)
main_handler(args_dict, errors_lookup)
captured = capfd.readouterr()
# Check if the correct error message was printed
assert (
Expand Down

0 comments on commit 145ed6c

Please sign in to comment.