Skip to content

Commit

Permalink
Merge pull request #18138 from Ultimaker/fix_python_installs
Browse files Browse the repository at this point in the history
Fix Python Installs about dialog
  • Loading branch information
jellespijker authored Jan 31, 2024
2 parents d490eff + 0698f9a commit 63da3f6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from io import StringIO
from pathlib import Path

from jinja2 import Template
Expand Down Expand Up @@ -150,6 +151,7 @@ def _pyinstaller_spec_arch(self):
return "None"

def _conan_installs(self):
self.output.info("Collecting conan installs")
conan_installs = {}

# list of conan installs
Expand All @@ -161,13 +163,22 @@ def _conan_installs(self):
return conan_installs

def _python_installs(self):
self.output.info("Collecting python installs")
python_installs = {}

# list of python installs
python_ins_cmd = f"python -c \"import pkg_resources; print(';'.join([(s.key+','+ s.version) for s in pkg_resources.working_set]))\""
from six import StringIO
run_env = VirtualRunEnv(self)
env = run_env.environment()
env.prepend_path("PYTHONPATH", str(self._site_packages.as_posix()))
venv_vars = env.vars(self, scope = "run")

outer = '"' if self.settings.os == "Windows" else "'"
inner = "'" if self.settings.os == "Windows" else '"'
buffer = StringIO()
self.run(python_ins_cmd, run_environment= True, env = "conanrun", output=buffer)
with venv_vars.apply():
self.run(f"""python -c {outer}import pkg_resources; print({inner};{inner}.join([(s.key+{inner},{inner}+ s.version) for s in pkg_resources.working_set])){outer}""",
env = "conanrun",
output = buffer)

packages = str(buffer.getvalue()).split("-----------------\n")
packages = packages[1].strip('\r\n').split(";")
Expand Down Expand Up @@ -504,10 +515,14 @@ def package_info(self):

if self.in_local_cache:
self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "site-packages"))
self.env_info.PYTHONPATH.append(os.path.join(self.package_folder, "site-packages"))
self.runenv_info.append_path("PYTHONPATH", os.path.join(self.package_folder, "plugins"))
self.env_info.PYTHONPATH.append(os.path.join(self.package_folder, "plugins"))
else:
self.runenv_info.append_path("PYTHONPATH", self.source_folder)
self.env_info.PYTHONPATH.append(self.source_folder)
self.runenv_info.append_path("PYTHONPATH", os.path.join(self.source_folder, "plugins"))
self.env_info.PYTHONPATH.append(os.path.join(self.source_folder, "plugins"))

def package_id(self):
self.info.clear()
Expand Down

0 comments on commit 63da3f6

Please sign in to comment.