Skip to content

Commit

Permalink
User proper environment to get dependencies list
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Nov 15, 2024
1 parent 806fede commit 656573e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ def _urls(self):
return "staging"
return "default"

@property
def _root_dir(self):
return Path(self.deploy_folder if hasattr(self, "deploy_folder") else self.source_folder)

@property
def _base_dir(self):
return Path(self.source_folder if self.source_folder is not None else self.deploy_folder, "venv")
return self._root_dir.joinpath("venv")

@property
def _share_dir(self):
Expand Down Expand Up @@ -140,23 +144,14 @@ def _python_installs(self):
self.output.info("Collecting python installs")
python_installs = {}

# list of python installs
# 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()
# with venv_vars.apply():
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 = ["conanrun", "virtual_python_env"],
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)

print(f"############################################################ {buffer.getvalue()}")
# for name, value in venv_vars.items():
# print(f"{name}={value}")
packages = str(buffer.getvalue()).strip('\r\n').split(";")
for package in packages:
name, version = package.split(",")
Expand Down

0 comments on commit 656573e

Please sign in to comment.