1
1
import os
2
2
import pathlib
3
+ import re
3
4
from conan import ConanFile
4
5
from conan .tools .files import get , replace_in_file , download , rmdir , copy
5
6
from conan .tools .scm import Version
10
11
# noinspection PyUnresolvedReferences
11
12
class EmbeddedPython (ConanFile ):
12
13
name = "embedded_python"
13
- version = "1.5.1 " # of the Conan package, `options.version` is the Python version
14
+ version = "1.5.2 " # of the Conan package, `options.version` is the Python version
14
15
license = "PSFL"
15
16
description = "Embedded distribution of Python"
16
17
topics = "embedded" , "python"
@@ -86,16 +87,11 @@ def pyver(self):
86
87
"""Two-digit integer version, e.g. 3.7.3 -> 37"""
87
88
return "" .join (self .pyversion .split ("." )[:2 ])
88
89
89
- def make_requirements_file (self , extra_packages = None ):
90
- """Create a `requirements.txt` based on `self.options.packages` and return its path
91
-
92
- We accept `self.options.packages` as either a space-separated list of packages (as
93
- you would pass to `pip install <packages>`) or the full contents of a `requirements.txt`
94
- file (as you would pass to `pip install -r <file>`). But in either case, we generate
95
- a `requirements.txt` file internally for installation.
96
90
97
- The `extra_packages` can be used to add extra packages (as a Python `list`) to be
98
- installed in addition to `self.options.packages`.
91
+ def make_package_list (self ):
92
+ """Create a list of package names based on `self.options.packages`
93
+
94
+ For details of the `self.options.packages` format see `make_requirements_file`
99
95
"""
100
96
101
97
def split_lines (string ):
@@ -110,7 +106,21 @@ def split_lines(string):
110
106
return string .split (" " )
111
107
112
108
packages_str = str (self .options .packages ).strip ()
113
- packages_list = split_lines (packages_str )
109
+ return split_lines (packages_str )
110
+
111
+
112
+ def make_requirements_file (self , extra_packages = None ):
113
+ """Create a `requirements.txt` based on `self.options.packages` and return its path
114
+
115
+ We accept `self.options.packages` as either a space-separated list of packages (as
116
+ you would pass to `pip install <packages>`) or the full contents of a `requirements.txt`
117
+ file (as you would pass to `pip install -r <file>`). But in either case, we generate
118
+ a `requirements.txt` file internally for installation.
119
+
120
+ The `extra_packages` can be used to add extra packages (as a Python `list`) to be
121
+ installed in addition to `self.options.packages`.
122
+ """
123
+ packages_list = self .make_package_list ()
114
124
if extra_packages :
115
125
packages_list .extend (extra_packages )
116
126
@@ -136,6 +146,15 @@ def _gather_licenses(self, bootstrap):
136
146
f" --with-license-file --no-license-path --output-file=package_licenses.txt"
137
147
)
138
148
149
+ def _gather_packages (self ):
150
+ """Gather all the required packages into a file for future reference"""
151
+ matcher = re .compile (r"^([\w.-]+)==[\w.-]+$" )
152
+ matches = map (matcher .match , self .make_package_list ())
153
+ package_names = (match .group (1 ) for match in filter (None , matches ))
154
+ with open ("packages.txt" , "w" ) as output :
155
+ output .write ("\n " .join (package_names ))
156
+
157
+
139
158
def source (self ):
140
159
replace_in_file (self , "embedded_python.cmake" , "${self.pyversion}" , str (self .pyversion ))
141
160
@@ -160,6 +179,7 @@ def build(self):
160
179
self .build_helper .enable_site_packages ()
161
180
bootstrap = self .build_helper .build_bootstrap ()
162
181
self ._gather_licenses (bootstrap )
182
+ self ._gather_packages ()
163
183
164
184
# Some modules always assume that `setuptools` is installed (e.g. pytest)
165
185
requirements = self .make_requirements_file (
@@ -176,6 +196,7 @@ def package(self):
176
196
copy (self , "embedded_python*" , src , self .package_folder )
177
197
copy (self , "embedded_python/LICENSE.txt" , src , license_folder , keep_path = False )
178
198
copy (self , "package_licenses.txt" , src , license_folder , keep_path = False )
199
+ copy (self , "packages.txt" , src , license_folder , keep_path = False )
179
200
180
201
def package_info (self ):
181
202
self .env_info .PYTHONPATH .append (self .package_folder )
0 commit comments