aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorShyamnath Premnadh <shyamnath.premnadh@qt.io>2023-03-20 10:51:56 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-27 10:12:49 +0000
commit57679d3c02fc30ee6c78fe02cbdef644df4a157a (patch)
tree372f4e18fe6978d1441164352836e88f8b1647ab /sources
parent5580cc964a9e1a3ca059d367c57a67e4e1570b2a (diff)
Deployment Tool: Remove create_venv + fix --dry-run/--init
- As the deployment tool's code base grows larger, I realized that the ability to create a venv using pyside6-deploy was a bit of over engineering. There are instances where I have to use the current Python interpreter to fetch some information from the newly created venv Python, which results in weird code. Note: The tool would still work even if the user is using a globally installed Python interpreter with PySide6 installed. - Now, the user is warned if he is not in a virtual environment and prompted the requirement to install further Python packages. If the user input's "no", then the tool exits. - dry_run used to create an empty 'pysidedeploy.spec' which can wreck the normal deployment process. This is fixed by pyside6-deploy using the 'default.spec' instead of creating a new 'pysidedeploy.spec'. Fixes: PYSIDE-2258 Task-number: PYSIDE-1612 Change-Id: I376d2a6aea9f93582eab7a904a81f48426bfee18 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 4d4f744c570d2feb79163051d2fd4c73336f1758) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside-tools/deploy.py34
-rw-r--r--sources/pyside-tools/deploy_lib/config.py7
-rw-r--r--sources/pyside-tools/deploy_lib/python_helper.py20
-rw-r--r--sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py7
4 files changed, 22 insertions, 46 deletions
diff --git a/sources/pyside-tools/deploy.py b/sources/pyside-tools/deploy.py
index 731d20a51..418efd56d 100644
--- a/sources/pyside-tools/deploy.py
+++ b/sources/pyside-tools/deploy.py
@@ -82,36 +82,32 @@ def main(main_file: Path = None, config_file: Path = None, init: bool = False,
command_str = None
logging.info("[DEPLOY] Start")
-
+ generated_files_path = None
try:
python = None
+ response = "yes"
# checking if inside virtual environment
- if not PythonExecutable.is_venv():
- if not force:
- response = input("Not in virtualenv. Do you want to create one? [Y/n]")
- else:
- response = "no"
-
- if response.lower() in "yes":
- # creating new virtual environment
- python = PythonExecutable(create_venv=True, dry_run=dry_run)
- logging.info("[DEPLOY] virutalenv created")
-
- # in venv or user entered no
- if not python:
- python = PythonExecutable(dry_run=dry_run)
- logging.info(f"[DEPLOY] using python at {sys.executable}")
+ if not PythonExecutable.is_venv() and not force and not dry_run and not init:
+ response = input(("You are not in virtualenv. pyside6-deploy needs to install a "
+ "few Python packages for deployment to work seamlessly. \n"
+ "Proceed? [Y/n]"))
+
+ if response.lower() in ["no", "n"]:
+ print("Exiting ...")
+ sys.exit(0)
+
+ python = PythonExecutable(dry_run=dry_run)
+ logging.info(f"[DEPLOY] using python at {sys.executable}")
config = Config(config_file=config_file, source_file=main_file,
python_exe=python.exe, dry_run=dry_run)
source_file = config.project_dir / config.source_file
-
generated_files_path = source_file.parent / "deployment"
if generated_files_path.exists():
clean(generated_files_path)
- if not init and not dry_run:
+ if not init:
# install packages needed for deployment
print("[DEPLOY] Installing dependencies \n")
packages = config.get_value("python", "packages").split(",")
@@ -151,7 +147,7 @@ def main(main_file: Path = None, config_file: Path = None, init: bool = False,
finally:
# clean up generated deployment files and copy executable into
# final_exec_path
- if not keep_deployment_files and not dry_run and not init:
+ if (not keep_deployment_files and generated_files_path and generated_files_path.exists()):
generated_exec_path = generated_files_path / (source_file.stem + EXE_FORMAT)
if generated_exec_path.exists() and final_exec_path:
shutil.copy(generated_exec_path, final_exec_path)
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py
index ba165d20b..03dff70bf 100644
--- a/sources/pyside-tools/deploy_lib/config.py
+++ b/sources/pyside-tools/deploy_lib/config.py
@@ -24,8 +24,11 @@ class Config:
self.config_file = config_file
self.parser = ConfigParser(comment_prefixes="/", allow_no_value=True)
if not self.config_file.exists():
- logging.info(f"[DEPLOY] Creating config file {self.config_file}")
- shutil.copy(Path(__file__).parent / "default.spec", self.config_file)
+ if not dry_run:
+ logging.info(f"[DEPLOY] Creating config file {self.config_file}")
+ shutil.copy(Path(__file__).parent / "default.spec", self.config_file)
+ else:
+ self.config_file = Path(__file__).parent / "default.spec"
else:
print(f"Using existing config file {config_file}")
self.parser.read(self.config_file)
diff --git a/sources/pyside-tools/deploy_lib/python_helper.py b/sources/pyside-tools/deploy_lib/python_helper.py
index cc9a448b0..2fc0236bc 100644
--- a/sources/pyside-tools/deploy_lib/python_helper.py
+++ b/sources/pyside-tools/deploy_lib/python_helper.py
@@ -19,11 +19,9 @@ class PythonExecutable:
Wrapper class around Python executable
"""
- def __init__(self, python_path=None, create_venv=False, dry_run=False):
+ def __init__(self, python_path=None, dry_run=False):
self.exe = python_path if python_path else Path(sys.executable)
self.dry_run = dry_run
- if create_venv:
- self.__create_venv()
self.nuitka = Nuitka(nuitka=[os.fspath(self.exe), "-m", "nuitka"])
@property
@@ -39,21 +37,6 @@ class PythonExecutable:
venv = os.environ.get("VIRTUAL_ENV")
return True if venv else False
- def __create_venv(self):
- self.install("virtualenv")
- if not self.is_venv():
- run_command(
- command=[self.exe, "-m", "venv", Path.cwd() / "deployment" / "venv"],
- dry_run=self.dry_run,
- )
- venv_path = Path(os.environ["VIRTUAL_ENV"])
- if sys.platform == "win32":
- self.exe = venv_path / "Scripts" / "python.exe"
- elif sys.platform in ["linux", "darwin"]:
- self.exe = venv_path / "bin" / "python"
- else:
- logging.info("[DEPLOY] You are already in virtual environment!")
-
def install(self, packages: list = None):
for package in packages:
package_info = package.split('==')
@@ -104,4 +87,3 @@ class PythonExecutable:
)
return command_str
-
diff --git a/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py b/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
index 3f53683d5..e822ff01c 100644
--- a/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
+++ b/sources/pyside6/tests/tools/pyside6-deploy/test_pyside6_deploy.py
@@ -77,7 +77,6 @@ class TestPySide6Deploy(unittest.TestCase):
self.setUpWidgets()
original_output = self.deploy.main(self.main_file, dry_run=True, force=True)
self.assertEqual(original_output, self.expected_run_cmd)
- self.config_file.unlink()
def testWidgetConfigFile(self):
# includes both dry run and config_file tests
@@ -88,8 +87,7 @@ class TestPySide6Deploy(unittest.TestCase):
self.assertEqual(init_result, None)
# test with config
- config_path = self.temp_example_widgets / "pysidedeploy.spec"
- original_output = self.deploy.main(config_file=config_path, dry_run=True, force=True)
+ original_output = self.deploy.main(config_file=self.config_file, dry_run=True, force=True)
self.assertEqual(original_output, self.expected_run_cmd)
# # test config file contents
@@ -169,7 +167,6 @@ class TestPySide6Deploy(unittest.TestCase):
original_output = self.deploy.main(self.main_file, dry_run=True, force=True)
self.assertEqual(original_output, self.expected_run_cmd)
self.assertEqual(mock_qmlimportscanner.call_count, 1)
- self.config_file.unlink()
def testMainFileDryRun(self):
self.setUpQml()
@@ -178,7 +175,6 @@ class TestPySide6Deploy(unittest.TestCase):
original_output = self.deploy.main(Path.cwd() / "main.py", dry_run=True, force=True)
self.assertEqual(original_output, self.expected_run_cmd)
self.assertEqual(mock_qmlimportscanner.call_count, 1)
- self.config_file.unlink()
# this test case retains the QtWebEngine dlls
def testWebEngineQuickDryRun(self):
@@ -244,7 +240,6 @@ class TestPySide6Deploy(unittest.TestCase):
config_obj.get_value("qt", "excluded_qml_plugins"),
"QtCharts,QtQuick3D,QtSensors,QtTest",
)
- config_file.unlink()
def tearDown(self) -> None:
super().tearDown()