12
12
from ..conda import CondaBuildPack
13
13
14
14
# Minimum version of python for use with Poetry
15
- COMPATIBLE_PYTHON2_VERSIONS = parse_constraint (' >=2.7' )
15
+ COMPATIBLE_PYTHON2_VERSIONS = parse_constraint (" >=2.7" )
16
16
17
17
# Min and max compatible versions of python3. N.B. the maximum constraint will
18
18
# have to be manually bumped
19
- COMPATIBLE_PYTHON3_VERSIONS = parse_constraint ('>=3.5, <3.10' )
19
+ COMPATIBLE_PYTHON3_VERSIONS = parse_constraint (">=3.5, <3.10" )
20
+
20
21
21
22
class PoetryBuildPack (CondaBuildPack ):
22
23
"""Setup Python with poetry for use with a repository."""
@@ -32,18 +33,17 @@ def python_version(self):
32
33
if hasattr (self , "_python_version" ):
33
34
return self ._python_version
34
35
35
- requested_version = '*'
36
+ requested_version = "*"
36
37
37
38
pyproject = self .binder_path ("pyproject.toml" )
38
39
if os .path .exists (pyproject ):
39
40
with open (pyproject ) as f :
40
41
pyproject_info = toml .load (f )
41
42
specified_version = (
42
- pyproject_info
43
- .get ('tool' , {})
44
- .get ('poetry' , {})
45
- .get ('dependencies' , {})
46
- .get ('python' , None )
43
+ pyproject_info .get ("tool" , {})
44
+ .get ("poetry" , {})
45
+ .get ("dependencies" , {})
46
+ .get ("python" , None )
47
47
)
48
48
49
49
if not specified_version is None :
@@ -53,22 +53,21 @@ def python_version(self):
53
53
if os .path .exists (lockfile ):
54
54
with open (lockfile ) as f :
55
55
lock_info = toml .load (f )
56
- specified_version = (
57
- lock_info .get ('metadata' , {})
58
- .get ('python-versions' , None )
56
+ specified_version = lock_info .get ("metadata" , {}).get (
57
+ "python-versions" , None
59
58
)
60
59
61
60
if not specified_version is None :
62
61
requested_version = specified_version
63
62
64
63
requested_constraint = parse_constraint (requested_version )
65
64
66
- version_range = parse_constraint ('*' )
65
+ version_range = parse_constraint ("*" )
67
66
68
- if requested_constraint .allows (parse_constraint ('2' )):
67
+ if requested_constraint .allows (parse_constraint ("2" )):
69
68
version_range = version_range .intersect (COMPATIBLE_PYTHON2_VERSIONS )
70
69
71
- if requested_constraint .allows (parse_constraint ('3' )):
70
+ if requested_constraint .allows (parse_constraint ("3" )):
72
71
# If the given constraint allows for python 3, then this will
73
72
# overwrite the range provided by python 2
74
73
version_range = version_range .intersect (COMPATIBLE_PYTHON3_VERSIONS )
@@ -180,7 +179,9 @@ def detect(self):
180
179
if os .path .exists (pyproject ):
181
180
with open (pyproject ) as f :
182
181
pyproject_info = toml .load (f )
183
- backend = pyproject_info .get ('build-system' , {}).get ('build-backend' , '' )
184
- is_poetry = backend == 'poetry.masonry.api'
182
+ backend = pyproject_info .get ("build-system" , {}).get (
183
+ "build-backend" , ""
184
+ )
185
+ is_poetry = backend == "poetry.masonry.api"
185
186
186
187
return is_poetry or os .path .exists (poetry_lock )
0 commit comments