-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateInstall.sh
More file actions
95 lines (82 loc) · 2.88 KB
/
Copy pathcreateInstall.sh
File metadata and controls
95 lines (82 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
#
# Copyright 2026 Deutsches Zentrum für Luft- und Raumfahrt e.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
VENV_NAME=${1:-./target/venv}
BUILDDIR=${2:-./target/build}
DISTDIR=${3:-./target}
SPECPATH=${4:-./target/specs}
CLIENTDIR=${5:-./target/src}
# activate virtual environment
. "$VENV_NAME/bin/activate" || exit 10
read -r VERSION < "./VERSION"
get_hidden_imports() {
# Default to current directory if no argument is passed
local target_dir="${1:-src}"
local module_prefix="${2:-de.dlr.wmp.task}"
# replace . with /
local module_path="${target_dir}/${module_prefix//./\/}"
if [ ! -d "$module_path" ]; then
echo "Error: Directory '$module_path' does not exist." >&2
return 1
fi
local args=()
# Find all .py files recursively in $module_path
while IFS= read -r -d '' pyfile; do
# Check if the file contains a Task implementation
if python3 -c "
import ast
import sys
filename = sys.argv[1]
try:
with open(filename, 'r') as f:
tree = ast.parse(f.read())
except SyntaxError:
sys.exit(1)
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef):
for base in node.bases:
# Handle Subscript (e.g., Task[Config])
if isinstance(base, ast.Subscript):
base = base.value
if isinstance(base, ast.Name) and base.id == 'Task':
sys.exit(0)
elif isinstance(base, ast.Attribute) and base.attr == 'Task':
sys.exit(0)
sys.exit(1)
" "$pyfile"; then
# Compute the module name relative to target_dir
local rel_path="${pyfile#$target_dir/}"
# Remove the .py extension
local module_name="${rel_path%.py}"
# Convert slashes to dots
module_name="${module_name//\//.}"
args+=("--hidden-import=$module_name")
fi
done < <(find "$module_path" -name '*.py' -print0)
# Output the combined arguments space-separated
echo "${args[@]}"
}
# create install
rm -f "$DISTDIR/ukis-wmp-python-task-${VERSION}"
pyinstaller --distpath "$DISTDIR" --workpath "$BUILDDIR" --specpath "$SPECPATH" \
--clean \
--noconfirm \
--onefile src/main.py \
$(get_hidden_imports src de.dlr.wmp.task) \
--path "${CLIENTDIR}" \
--name "ukis-wmp-python-task-${VERSION}" || exit 1
# deactivate environment
deactivate