|
|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
from pathlib import Path |
|
|
|
|
from typing import Dict |
|
|
|
|
|
|
|
|
|
from jinja2 import Template |
|
|
|
|
from conan import ConanFile |
|
|
|
|
from conan.tools.scm import Version |
|
|
|
|
from jinja2 import Template |
|
|
|
|
from conan.tools.files import save |
|
|
|
|
from conan.tools.env.virtualrunenv import VirtualRunEnv |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,17 +29,13 @@ class PyCharmRunEnv:
|
|
|
|
|
def _site_packages(self): |
|
|
|
|
if self.settings.os == "Windows": |
|
|
|
|
return self._base_dir.joinpath("Lib", "site-packages") |
|
|
|
|
py_version = Version(self.dependencies["cpython"].ref.version) |
|
|
|
|
py_version = Version(self.conanfile.dependencies["cpython"].ref.version) |
|
|
|
|
return self._base_dir.joinpath("lib", f"python{py_version.major}.{py_version.minor}", "site-packages") |
|
|
|
|
|
|
|
|
|
def generate(self) -> Dict[str, str]: |
|
|
|
|
# Mapping of file names -> files |
|
|
|
|
# Mapping of file names -> files |
|
|
|
|
run_configurations: Dict[str, str] = {} |
|
|
|
|
|
|
|
|
|
if not hasattr(self.conanfile, "_pycharm_targets"): |
|
|
|
|
def generate(self) -> None: |
|
|
|
|
if self.conanfile.conan_data is None or "pycharm_targets" not in self.conanfile.conan_data: |
|
|
|
|
# There are no _pycharm_targets in the conanfile for the package using this generator. |
|
|
|
|
return run_configurations |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
# Collect environment variables for use in the template |
|
|
|
|
env = VirtualRunEnv(self.conanfile).environment() |
|
|
|
|
@ -50,14 +47,13 @@ class PyCharmRunEnv:
|
|
|
|
|
env.compose_env(project_run_env) # TODO: Add logic for dependencies |
|
|
|
|
|
|
|
|
|
# Create Pycharm run configuration from template for each target |
|
|
|
|
for target in self.conanfile._pycharm_targets: |
|
|
|
|
for target in self.conanfile.conan_data["pycharm_targets"]: |
|
|
|
|
target["env_vars"] = env.vars(self.conanfile, scope="run") |
|
|
|
|
target["sdk_path"] = str(self._py_interp) |
|
|
|
|
if "parameters" not in target: |
|
|
|
|
target["parameters"] = "" |
|
|
|
|
|
|
|
|
|
with open(target["jinja_path"], "r") as f: |
|
|
|
|
with open(Path(self.conanfile.source_folder, target["jinja_path"]), "r") as f: |
|
|
|
|
template = Template(f.read()) |
|
|
|
|
run_configuration = template.render(target) |
|
|
|
|
run_configurations[str(Path(self.conanfile.source_folder).joinpath(".run", |
|
|
|
|
f"{target['name']}.run.xml"))] = run_configuration |
|
|
|
|
save(self.conanfile, Path(".run", f"{target['name']}.run.xml"), run_configuration) |
|
|
|
|
|