Skip to content

Commit

Permalink
Make dist.py fail early. (#39)
Browse files Browse the repository at this point in the history
Before this patch, errors thrown by commands executed by os.system were
ignored. This creates a new run_command function which is does
esentially the same thing as os.system but checks if the command ran
successfuly. If not, it exits with the return code of the command.

Signed-off-by: Slendi <[email protected]>
  • Loading branch information
xslendix authored Aug 21, 2023
1 parent c71960e commit 25ebceb
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
parser.add_argument("--venv-path", type=str, help="[Relative] path to virtual environment to use")
args = parser.parse_args()


def run_command(command: str):
ret: int = os.system(command)
if ret != os.EX_OK:
sys.exit(ret)


# Get OS
os_name = "notwin"
venv_path = f"{args.venv_path if args.venv_path else 'venv'}/bin/"
Expand All @@ -38,30 +45,30 @@
# Create virtual environment if it doesn't exist
if not os.path.isdir("venv"):
print("Existing virtual environment not found, creating new one...")
os.system("python -m venv venv")
run_command("python3 -m venv venv")
else:
print("Found existing virtual environment")

# Install requirements
print("Installing requirements...")
os.system(f"{python_name} -m pip install --upgrade pip -r requirements.txt")
run_command(f"{python_name} -m pip install --upgrade pip -r requirements.txt")

# Convert ui files to python
print("Converting ui files to python...")
os.system(f"{venv_path}pyside6-uic ui/main.ui -o src/nexus/ui/MainWindow.py")
os.system(f"{venv_path}pyside6-uic ui/banlist.ui -o src/nexus/ui/BanlistDialog.py")
os.system(f"{venv_path}pyside6-uic ui/banword.ui -o src/nexus/ui/BanwordDialog.py")
os.system(f"{venv_path}pyside6-uic ui/confirm.ui -o src/nexus/ui/ConfirmDialog.py")
run_command(f"{venv_path}pyside6-uic ui/main.ui -o src/nexus/ui/MainWindow.py")
run_command(f"{venv_path}pyside6-uic ui/banlist.ui -o src/nexus/ui/BanlistDialog.py")
run_command(f"{venv_path}pyside6-uic ui/banword.ui -o src/nexus/ui/BanwordDialog.py")
run_command(f"{venv_path}pyside6-uic ui/confirm.ui -o src/nexus/ui/ConfirmDialog.py")

# Generate translations
print("Generating TS templates...")
os.system(f"{venv_path}pyside6-lupdate " +
' '.join(glob.glob('ui/*.ui') + ["src/nexus/GUI.py"]) +
" -ts translations/i18n_en.ts")
run_command(f"{venv_path}pyside6-lupdate " +
' '.join(glob.glob('ui/*.ui') + ["src/nexus/GUI.py"]) +
" -ts translations/i18n_en.ts")
print("Generating QM files...")
os.makedirs('src/nexus/translations', exist_ok=True)
for i in glob.glob('translations/*.ts'):
os.system(f"{venv_path}pyside6-lrelease {i} -qm src/nexus/translations/{Path(i).stem}.qm")
run_command(f"{venv_path}pyside6-lrelease {i} -qm src/nexus/translations/{Path(i).stem}.qm")

if not (args.no_build or args.ui_only):
# Pyinstaller command
Expand All @@ -71,30 +78,30 @@

# Build executable
print("Building executable...")
os.system(f"{venv_path}{build_cmd}")
run_command(f"{venv_path}{build_cmd}")

# Rename darwin executable
if os_name == "darwin":
os.rename("dist/nexus", "dist/nexus-macos")

# Copy README and LICENSE to dist
if os_name == "win":
os.system("copy README.md dist")
os.system("copy LICENSE dist")
run_command("copy README.md dist")
run_command("copy LICENSE dist")
else:
os.system("cp README.md LICENSE dist")
run_command("cp README.md LICENSE dist")

if args.devel:
# Install dev/test requirements
print("Installing dev/test requirements...")
os.system(f"{python_name} -m pip install --upgrade pip -r test-requirements.txt")
run_command(f"{python_name} -m pip install --upgrade pip -r test-requirements.txt")

# Setup git hooks
print("Setting up git hooks...")
os.system(f"{venv_path}pre-commit install")
run_command(f"{venv_path}pre-commit install")

# Install module locally
print("Installing module locally...")
os.system(f"{python_name} -m pip install -e .")
run_command(f"{python_name} -m pip install -e .")

print(f"Done!{' Built executable is in dist/' if not (args.no_build or args.ui_only) else ''}")

0 comments on commit 25ebceb

Please sign in to comment.