Skip to content

Commit 33d739f

Browse files
authored
fix: cli performance issue and startup speed improvement (#300)
1 parent 4a42ec2 commit 33d739f

File tree

3 files changed

+87
-66
lines changed

3 files changed

+87
-66
lines changed

cli/app/main.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1+
import os
2+
import time
13
import typer
4+
25
from importlib.metadata import version as get_version
36
from rich.console import Console
47
from rich.panel import Panel
58
from rich.text import Text
69

7-
from app.commands.clone.command import clone_app
8-
from app.commands.conf.command import conf_app
9-
from app.commands.install.command import install_app
10-
from app.commands.preflight.command import preflight_app
11-
from app.commands.proxy.command import proxy_app
12-
from app.commands.service.command import service_app
13-
from app.commands.test.command import test_app
14-
from app.commands.uninstall.command import uninstall_app
15-
from app.commands.version.command import main_version_callback, version_app
16-
from app.commands.version.version import VersionCommand
10+
from app.commands.version.command import main_version_callback
11+
1712
from app.utils.message import application_add_completion, application_description, application_name, application_version_help
1813
from app.utils.config import Config
1914

@@ -33,46 +28,57 @@ def main(
3328
"-v",
3429
callback=main_version_callback,
3530
help=application_version_help,
36-
)
31+
),
3732
):
3833
if ctx.invoked_subcommand is None:
3934
console = Console()
40-
35+
4136
ascii_art = """
4237
_ _ _ _
4338
| \\ | (_)
44-
| \\| |___ _____ _ __ _ _ ___
45-
| . ` | \\ \\/ / _ \\| '_ \\| | | / __|
39+
| \\| |___ _____ _ __ _ _ ___ ____
40+
| . ` | \\ \\/ / _ \\| '_ \\| | | / __|
4641
| |\\ | |> < (_) | |_) | |_| \\__ \\
4742
|_| \\_|_/_/\\_\\___/| .__/ \\__,_|___/
4843
| |
4944
|_|
5045
"""
51-
46+
5247
text = Text(ascii_art, style="bold cyan")
5348
panel = Panel(text, title="[bold white]Welcome to[/bold white]", border_style="cyan", padding=(1, 2))
54-
49+
5550
console.print(panel)
56-
51+
5752
cli_version = get_version("nixopus")
5853
version_text = Text()
5954
version_text.append("Version: ", style="bold white")
6055
version_text.append(f"v{cli_version}", style="green")
61-
56+
6257
description_text = Text()
6358
description_text.append(application_description, style="dim")
64-
59+
6560
console.print(version_text)
6661
console.print(description_text)
6762
console.print()
68-
63+
6964
help_text = Text()
7065
help_text.append("Run ", style="dim")
7166
help_text.append("nixopus --help", style="bold green")
7267
help_text.append(" to explore all available commands", style="dim")
7368
console.print(help_text)
7469
console.print()
7570

71+
72+
from app.commands.clone.command import clone_app
73+
from app.commands.conf.command import conf_app
74+
from app.commands.install.command import install_app
75+
from app.commands.preflight.command import preflight_app
76+
from app.commands.proxy.command import proxy_app
77+
from app.commands.service.command import service_app
78+
from app.commands.test.command import test_app
79+
from app.commands.uninstall.command import uninstall_app
80+
from app.commands.version.command import version_app
81+
7682
app.add_typer(preflight_app, name="preflight")
7783
app.add_typer(clone_app, name="clone")
7884
app.add_typer(conf_app, name="conf")

cli/build.sh

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
104104
exe = EXE(
105105
pyz,
106106
a.scripts,
107-
a.binaries,
108-
a.zipfiles,
109-
a.datas,
110107
[],
108+
exclude_binaries=True,
111109
name='nixopus',
112110
debug=False,
113111
bootloader_ignore_signals=False,
@@ -122,6 +120,17 @@ exe = EXE(
122120
codesign_identity=None,
123121
entitlements_file=None,
124122
)
123+
124+
coll = COLLECT(
125+
exe,
126+
a.binaries,
127+
a.zipfiles,
128+
a.datas,
129+
strip=False,
130+
upx=True,
131+
upx_exclude=[],
132+
name='nixopus'
133+
)
125134
EOF
126135

127136
log_success "Spec file created: $SPEC_FILE"
@@ -136,7 +145,7 @@ build_wheel() {
136145
}
137146

138147
build_binary() {
139-
log_info "Building binary..."
148+
log_info "Building binary"
140149

141150
poetry run pyinstaller --clean --noconfirm $SPEC_FILE
142151

@@ -148,53 +157,46 @@ build_binary() {
148157
aarch64|arm64) ARCH="arm64" ;;
149158
esac
150159

151-
BINARY_NAME="${APP_NAME}_${OS}_${ARCH}"
160+
BINARY_DIR_NAME="${APP_NAME}_${OS}_${ARCH}"
152161

153-
if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then
154-
if [[ -f "$BUILD_DIR/$APP_NAME" ]]; then
155-
mv $BUILD_DIR/$APP_NAME $BUILD_DIR/$BINARY_NAME
156-
ln -sf "$BINARY_NAME" "$BUILD_DIR/$APP_NAME"
157-
fi
158-
elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then
159-
if [[ -f "$BUILD_DIR/${APP_NAME}.exe" ]]; then
160-
mv $BUILD_DIR/${APP_NAME}.exe $BUILD_DIR/${BINARY_NAME}.exe
161-
cp "$BUILD_DIR/${BINARY_NAME}.exe" "$BUILD_DIR/${APP_NAME}.exe"
162-
fi
163-
fi
164162

165-
log_success "Binary built: $BUILD_DIR/$BINARY_NAME"
166-
log_success "User-friendly link created: $BUILD_DIR/$APP_NAME"
163+
if [[ -d "$BUILD_DIR/$APP_NAME" ]]; then
164+
mv "$BUILD_DIR/$APP_NAME" "$BUILD_DIR/$BINARY_DIR_NAME"
165+
166+
167+
cat > "$BUILD_DIR/$APP_NAME" << EOF
168+
#!/bin/bash
169+
# Nixopus CLI wrapper
170+
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
171+
exec "\$SCRIPT_DIR/$BINARY_DIR_NAME/$APP_NAME" "\$@"
172+
EOF
173+
chmod +x "$BUILD_DIR/$APP_NAME"
174+
175+
log_success "Binary directory built: $BUILD_DIR/$BINARY_DIR_NAME/"
176+
log_success "Wrapper script created: $BUILD_DIR/$APP_NAME"
177+
else
178+
log_error "Build failed - directory $BUILD_DIR/$APP_NAME not found"
179+
exit 1
180+
fi
167181
}
168182

169183
test_binary() {
170-
log_info "Testing binary..."
171-
172-
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
173-
ARCH=$(uname -m)
174-
175-
case $ARCH in
176-
x86_64) ARCH="amd64" ;;
177-
aarch64|arm64) ARCH="arm64" ;;
178-
esac
179184

180-
BINARY_NAME="${APP_NAME}_${OS}_${ARCH}"
181-
BINARY_PATH="$BUILD_DIR/$BINARY_NAME"
182-
183-
if [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then
184-
BINARY_PATH="$BUILD_DIR/${BINARY_NAME}.exe"
185-
fi
185+
log_info "Testing binary..."
186+
187+
WRAPPER_PATH="$BUILD_DIR/$APP_NAME"
186188

187-
if [[ -f "$BINARY_PATH" ]]; then
188-
chmod +x "$BINARY_PATH"
189+
if [[ -f "$WRAPPER_PATH" ]]; then
190+
chmod +x "$WRAPPER_PATH"
189191

190-
if $BINARY_PATH --version; then
192+
if "$WRAPPER_PATH" --version; then
191193
log_success "Binary test passed"
192194
else
193195
log_error "Binary test failed"
194196
exit 1
195197
fi
196198
else
197-
log_error "Binary not found for testing: $BINARY_PATH"
199+
log_error "Wrapper script not found for testing: $WRAPPER_PATH"
198200
exit 1
199201
fi
200202
}
@@ -211,20 +213,17 @@ create_release_archive() {
211213
esac
212214

213215
ARCHIVE_NAME="${APP_NAME}_${OS}_${ARCH}"
214-
BINARY_NAME="${APP_NAME}_${OS}_${ARCH}"
216+
BINARY_DIR_NAME="${APP_NAME}_${OS}_${ARCH}"
215217

216218
cd $BUILD_DIR
217219

220+
218221
if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then
219-
if [[ -f "$BINARY_NAME" ]]; then
220-
tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME"
221-
log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.tar.gz"
222-
fi
222+
tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_DIR_NAME" "$APP_NAME"
223+
log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.tar.gz"
223224
elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then
224-
if [[ -f "${BINARY_NAME}.exe" ]]; then
225-
zip "${ARCHIVE_NAME}.zip" "${BINARY_NAME}.exe"
226-
log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.zip"
227-
fi
225+
zip -r "${ARCHIVE_NAME}.zip" "$BINARY_DIR_NAME" "$APP_NAME"
226+
log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.zip"
228227
fi
229228

230229
cd ..

cli/perf_check.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TODO: @shravan20 - Delte before merging to master or feat/dev
2+
echo "itr \tBinary RUN\t Poetry Run"
3+
4+
x=()
5+
y=()
6+
7+
8+
for i in {1..3}; do
9+
x[$i]=$( (time ./dist/nixopus --help > /dev/null 2>&1) 2>&1 | grep real | awk '{print $2}' )
10+
echo "$i\t${x[$i]}\t\t-"
11+
done
12+
13+
for i in {1..3}; do
14+
y[$i]=$( (time poetry run nixopus --help > /dev/null 2>&1) 2>&1 | grep real | awk '{print $2}' )
15+
echo "$i\t-\t\t ${y[$i]}"
16+
done

0 commit comments

Comments
 (0)