From 0f91f69036c384f42fa43db594498a60dfaefc09 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Sat, 21 Sep 2024 13:46:33 +0100 Subject: [PATCH] build: script to create Python virtual env --- ChangeLog | 1 + scripts/lib/env.py | 8 ++++++-- scripts/setup_venv.py | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100755 scripts/setup_venv.py diff --git a/ChangeLog b/ChangeLog index 056f236c1..9dab6d5b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Enhancements: - #7533 Always upgrade packages on Arch Linux in deps script - #7539 Lint and add comment to PR on lint failure - #7544 Use system deps for `tomlplusplus` and `CLI11` +- #7549 Script to create Python virtual environment (venv) # 1.16.1 diff --git a/scripts/lib/env.py b/scripts/lib/env.py index 46d90b908..fe44f31b6 100644 --- a/scripts/lib/env.py +++ b/scripts/lib/env.py @@ -131,8 +131,12 @@ def ensure_in_venv(script_file, auto_create=False): if not in_venv(): if not os.path.exists(VENV_DIR): if not auto_create: - print("Hint: Run the `install_deps.py` script first.") - raise RuntimeError(f"Virtual environment not found at: {VENV_DIR}") + print( + "The Python virtual environment (.venv) needs to be created before you can " + "run this script.\n" + "Please run: scripts/setup_venv.py" + ) + sys.exit(1) print(f"Creating virtual environment at {VENV_DIR}") venv.create(VENV_DIR, with_pip=True) diff --git a/scripts/setup_venv.py b/scripts/setup_venv.py new file mode 100755 index 000000000..5d76e6154 --- /dev/null +++ b/scripts/setup_venv.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +# Deskflow -- mouse and keyboard sharing utility +# Copyright (C) 2024 Symless Ltd. +# +# This package is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# found in the file LICENSE that should have accompanied this file. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import lib.env as env + +env.ensure_in_venv(__file__, auto_create=True) +env.install_requirements() + +import lib.colors as colors + +print(colors.SUCCESS_TEXT, "Python virtual environment is ready.")