Change the way we get Python installs

This commit is contained in:
Erwan MATHIEU 2024-11-15 15:28:43 +01:00
parent 656573e905
commit fc85817095
3 changed files with 6 additions and 22 deletions

View File

@ -1,6 +1,8 @@
# Copyright (c) 2023 UltiMaker # Copyright (c) 2023 UltiMaker
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import importlib.metadata
CuraAppName = "{{ cura_app_name }}" CuraAppName = "{{ cura_app_name }}"
CuraAppDisplayName = "{{ cura_app_display_name }}" CuraAppDisplayName = "{{ cura_app_display_name }}"
CuraVersion = "{{ cura_version }}" CuraVersion = "{{ cura_version }}"
@ -14,4 +16,3 @@ CuraDigitalFactoryURL = "{{ cura_digital_factory_url }}"
CuraLatestURL = "{{ cura_latest_url }}" CuraLatestURL = "{{ cura_latest_url }}"
ConanInstalls = {{ conan_installs }} ConanInstalls = {{ conan_installs }}
PythonInstalls = {{ python_installs }}

View File

@ -140,26 +140,6 @@ class CuraConan(ConanFile):
} }
return conan_installs return conan_installs
def _python_installs(self):
self.output.info("Collecting python installs")
python_installs = {}
outer = '"' if self.settings.os == "Windows" else "'"
inner = "'" if self.settings.os == "Windows" else '"'
buffer = StringIO()
env_path = str(self._root_dir.joinpath("conanrun"))
self.run(f"""python -c {outer}import importlib.metadata; print({inner};{inner}.join([(package.metadata[{inner}Name{inner}]+{inner},{inner}+ package.metadata[{inner}Version{inner}]) for package in importlib.metadata.distributions()])){outer}""",
env = env_path,
stdout = buffer)
packages = str(buffer.getvalue()).strip('\r\n').split(";")
for package in packages:
name, version = package.split(",")
python_installs[name] = {"version": version}
print(python_installs)
return python_installs
def _generate_cura_version(self, location): def _generate_cura_version(self, location):
with open(os.path.join(self.recipe_folder, "CuraVersion.py.jinja"), "r") as f: with open(os.path.join(self.recipe_folder, "CuraVersion.py.jinja"), "r") as f:
cura_version_py = Template(f.read()) cura_version_py = Template(f.read())
@ -188,7 +168,6 @@ class CuraConan(ConanFile):
cura_digital_factory_url = self.conan_data["urls"][self._urls]["digital_factory_url"], cura_digital_factory_url = self.conan_data["urls"][self._urls]["digital_factory_url"],
cura_latest_url=self.conan_data["urls"][self._urls]["cura_latest_url"], cura_latest_url=self.conan_data["urls"][self._urls]["cura_latest_url"],
conan_installs=self._conan_installs(), conan_installs=self._conan_installs(),
python_installs=self._python_installs(),
)) ))
def _generate_pyinstaller_spec(self, location, entrypoint_location, icon_path, entitlements_file, cura_source_folder): def _generate_pyinstaller_spec(self, location, entrypoint_location, icon_path, entitlements_file, cura_source_folder):

View File

@ -0,0 +1,4 @@
import importlib.metadata
from . import CuraVersion
CuraVersion.PythonInstalls = {package.metadata['Name']: {'version': package.metadata['Version']} for package in importlib.metadata.distributions()}