|
5 | 5 |
|
6 | 6 | class EmbeddedPython(ConanFile):
|
7 | 7 | name = "embedded_python"
|
8 |
| - version = "3.7.4" # use x.y.z-n for build revisions on the same Python version, e.g. 3.7.4-1 |
9 |
| - pyversion = version.split("-")[0] # Python version sans build revision, e.g. 3.7.4-2 -> 3.7.4 |
10 |
| - md5 = "9b00c8cf6d9ec0b9abe83184a40729a2" |
| 8 | + version = "1.0.0" # of the Conan package, `options.version` is the Python version |
11 | 9 | description = "Embedded distribution of Python"
|
12 | 10 | url = "https://www.python.org/"
|
13 | 11 | license = "PSFL"
|
14 | 12 | settings = {"os": ["Windows"]}
|
15 |
| - options = {"pip_packages": "ANY"} |
16 |
| - default_options = "pip_packages=None" |
| 13 | + options = {"version": "ANY", "packages": "ANY"} |
| 14 | + default_options = "packages=None" |
17 | 15 | exports = "embedded_python_tools.py"
|
18 | 16 | short_paths = True # some of the pip packages go over the 260 char path limit on Windows
|
19 | 17 |
|
20 |
| - def _get_binaries(self): |
| 18 | + def _get_binaries(self, version): |
21 | 19 | """Get the binaries from the special embeddable Python package"""
|
22 | 20 | url = "https://www.python.org/ftp/python/{0}/python-{0}-embed-amd64.zip"
|
23 |
| - tools.get(url.format(self.pyversion), md5=self.md5, destination="embedded_python") |
| 21 | + tools.get(url.format(version), destination="embedded_python") |
24 | 22 |
|
25 |
| - def _get_headers_and_lib(self): |
| 23 | + def _get_headers_and_lib(self, version): |
26 | 24 | """We also need headers and the `python3.lib` file to link against"""
|
27 | 25 | url = "https://www.python.org/ftp/python/{0}/python-{0}-amd64-webinstall.exe"
|
28 |
| - tools.download(url.format(self.pyversion), filename="tmp\\installer.exe") |
| 26 | + tools.download(url.format(version), filename="tmp\\installer.exe") |
29 | 27 | self.run("tmp\\installer.exe /quiet /layout")
|
30 | 28 | dst = os.path.join(self.build_folder, "embedded_python")
|
31 | 29 | self.run(f"msiexec.exe /a {self.build_folder}\\tmp\\dev.msi targetdir={dst}")
|
32 | 30 | tools.rmdir("tmp")
|
33 | 31 |
|
34 | 32 | def build(self):
|
35 |
| - self._get_binaries() |
36 |
| - self._get_headers_and_lib() |
| 33 | + version = str(self.options.version) |
| 34 | + self._get_binaries(version) |
| 35 | + self._get_headers_and_lib(version) |
37 | 36 |
|
38 |
| - if not self.options.pip_packages: |
| 37 | + if not self.options.packages: |
39 | 38 | return
|
40 | 39 |
|
41 | 40 | # Enable site-packages, i.e. additional non-system packages
|
42 |
| - pyver = "".join(self.pyversion.split(".")[:2]) # e.g. 3.7.3 -> 37 |
| 41 | + pyver = "".join(version.split(".")[:2]) # e.g. 3.7.3 -> 37 |
43 | 42 | tools.replace_in_file("embedded_python/python{}._pth".format(pyver), "#import site", "import site")
|
44 | 43 |
|
45 |
| - packages = self.options.pip_packages.value |
46 |
| - packages += " setuptools==41.0.1" # some modules always assume it's installed (e.g. pytest) |
47 | 44 | target = self.build_folder + "/embedded_python/Lib/site-packages"
|
| 45 | + packages = self.options.packages.value |
| 46 | + packages += " setuptools==45.2.0" # some modules always assume it's installed (e.g. pytest) |
48 | 47 | self.run(f'{sys.executable} -m pip install --no-deps --python-version {pyver} --target "{target}" {packages}')
|
49 | 48 |
|
50 | 49 | def package(self):
|
|
0 commit comments