Skip to content

Commit

Permalink
Change the way we get Python installs
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Nov 15, 2024
1 parent 656573e commit fc85817
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CuraVersion.py.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2023 UltiMaker
# Cura is released under the terms of the LGPLv3 or higher.

import importlib.metadata

CuraAppName = "{{ cura_app_name }}"
CuraAppDisplayName = "{{ cura_app_display_name }}"
CuraVersion = "{{ cura_version }}"
Expand All @@ -14,4 +16,3 @@ CuraDigitalFactoryURL = "{{ cura_digital_factory_url }}"
CuraLatestURL = "{{ cura_latest_url }}"

ConanInstalls = {{ conan_installs }}
PythonInstalls = {{ python_installs }}
21 changes: 0 additions & 21 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,6 @@ def _conan_installs(self):
}
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):
with open(os.path.join(self.recipe_folder, "CuraVersion.py.jinja"), "r") as f:
cura_version_py = Template(f.read())
Expand Down Expand Up @@ -188,7 +168,6 @@ def _generate_cura_version(self, location):
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"],
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):
Expand Down
4 changes: 4 additions & 0 deletions cura/__init__.py
Original file line number Diff line number Diff line change
@@ -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()}

0 comments on commit fc85817

Please sign in to comment.