-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconanfile.py
More file actions
59 lines (50 loc) · 2.17 KB
/
conanfile.py
File metadata and controls
59 lines (50 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import copy
import os
import sys
import json
import textwrap
class PythonVirtualEnvironment(ConanFile):
name = "python-virtualenv"
version = "system"
description = "Install python packages into a virtual environment"
url = "https://github.com/samuel-emrys/python-virtualenv.git"
homepage = "https://github.com/samuel-emrys/python-virtualenv.git"
license = "MIT"
topics = ("python", "virtual environment", "venv")
settings = "arch", "os"
options = {"requirements": ["ANY"]}
default_options = {"requirements": "[]"}
python_requires = "pyvenv/[>=0.2.2]@mtolympus/stable"
# python venvs are not relocatable across environments, so we will not have binaries for this on artifactory.
# Just build it on first use
build_policy = "missing"
upload_policy = "skip"
_venv = None
def validate(self):
try:
json.loads(str(self.options.requirements))
except Exception as e:
raise ConanInvalidConfiguration(
f"Failed to parse requirements '{self.options.requirements}'. Ensure requirements are passed as valid JSON."
)
@property
def _bindir(self):
return "Scripts" if self.settings.os == "Windows" else "bin"
def _configure_venv(self):
venv = self.python_requires["pyvenv"].module.PythonVirtualEnv
if not self._venv:
self._venv = venv(self)
return self._venv
def build(self):
args_to_string = self.python_requires["pyvenv"].module.args_to_string
requirements = json.loads(str(self.options.get_safe("requirements", "[]")))
venv = self._configure_venv()
venv.create(folder=os.path.join(self.package_folder), requirements=requirements)
def package(self):
copy(self, "*", src=self.build_folder, dst=self.package_folder)
def package_info(self):
self.cpp_info.bindirs = [self._bindir]
self.conf_info.define("user.env.pythonenv:requirements", str(self.options.get_safe("requirements", "[]")))
self.conf_info.define("user.env.pythonenv:dir", self.package_folder)