Skip to content

Commit 8a8d4e7

Browse files
committed
Separately version the conan recipe and the Python interpreter
1 parent 2c4e482 commit 8a8d4e7

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

conanfile.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,45 @@
55

66
class EmbeddedPython(ConanFile):
77
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
119
description = "Embedded distribution of Python"
1210
url = "https://www.python.org/"
1311
license = "PSFL"
1412
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"
1715
exports = "embedded_python_tools.py"
1816
short_paths = True # some of the pip packages go over the 260 char path limit on Windows
1917

20-
def _get_binaries(self):
18+
def _get_binaries(self, version):
2119
"""Get the binaries from the special embeddable Python package"""
2220
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")
2422

25-
def _get_headers_and_lib(self):
23+
def _get_headers_and_lib(self, version):
2624
"""We also need headers and the `python3.lib` file to link against"""
2725
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")
2927
self.run("tmp\\installer.exe /quiet /layout")
3028
dst = os.path.join(self.build_folder, "embedded_python")
3129
self.run(f"msiexec.exe /a {self.build_folder}\\tmp\\dev.msi targetdir={dst}")
3230
tools.rmdir("tmp")
3331

3432
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)
3736

38-
if not self.options.pip_packages:
37+
if not self.options.packages:
3938
return
4039

4140
# 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
4342
tools.replace_in_file("embedded_python/python{}._pth".format(pyver), "#import site", "import site")
4443

45-
packages = self.options.pip_packages.value
46-
packages += " setuptools==41.0.1" # some modules always assume it's installed (e.g. pytest)
4744
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)
4847
self.run(f'{sys.executable} -m pip install --no-deps --python-version {pyver} --target "{target}" {packages}')
4948

5049
def package(self):

readme.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Embedded python distribution
44
This conan recipe builds an embedded Python distribution which can be placed directly into the `bin` directory of an application for its exclusive use.
55
Windows-only for now.
66

7-
The base recipe uses the stock embeddable Python version from the python.org website.
8-
If the `embedded_python:pip_packages=...` option is passed, the recipe will `pip install` additional packages.
9-
The contents of that option is hashed by Conan, so `embedded_python:pip_packages="numpy=1.15 scipy=1.2"` is clearly different from `embedded_python:pip_packages="numpy=1.16 scipy=1.3"`.
10-
That way, the full Python environment is controlled via Conan.
7+
The base recipe uses the stock embeddable Python version from the python.org website.
8+
The Python version is specified using the mandatory `embedded_python:version=x.y.z` option.
9+
If the `embedded_python:packages=...` option is passed, the recipe will `pip install` additional packages.
10+
The contents of that option is hashed by Conan, so `embedded_python:packages="numpy=1.15 scipy=1.2"` is clearly different from `embedded_python:packages="numpy=1.16 scipy=1.3"`.
11+
That way, the full Python environment is controlled via Conan.
1112
The initial build of a new Python environment can take some time but after that it's caches as a binary package.

test_package/conanfile.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
class TestEmbeddedPython(ConanFile):
66
settings = "os"
7+
default_options = (
8+
"embedded_python:version=3.7.6",
9+
)
710

811
def imports(self):
912
import embedded_python_tools

0 commit comments

Comments
 (0)