1
1
"""Create folder structure for index."""
2
2
from pathlib import Path
3
3
import re
4
- from typing import List , Set
4
+ from typing import List , Set , Dict
5
5
6
6
import requests
7
7
@@ -23,6 +23,29 @@ def create_wheels_index(base_index: str) -> str:
23
23
return f"{ base_index } /{ alpine_version ()} /{ build_arch ()} /"
24
24
25
25
26
+ def create_package_map (packages : List [str ]) -> Dict [str , str ]:
27
+ """Create a dictionary from package base name to package and version string."""
28
+ results = {}
29
+ for package in packages .copy ():
30
+ find = _RE_REQUIREMENT .match (package )
31
+ if not find :
32
+ continue
33
+ package = find ["package" ]
34
+ version = find ["version" ]
35
+ results [package ] = f"{ package } -{ version } "
36
+ return results
37
+
38
+
39
+ def check_existing_packages (index : str , package_map : Dict [str , str ]) -> Set [str ]:
40
+ """Return the set of package names that already exist in the index."""
41
+ available_data = requests .get (index , allow_redirects = True ).text
42
+ found : Set [str ] = set ({})
43
+ for (binary , package ) in package_map .items ():
44
+ if package in available_data :
45
+ found .add (binary )
46
+ return found
47
+
48
+
26
49
def check_available_binary (
27
50
index : str , skip_binary : str , packages : List [str ], constraints : List [str ]
28
51
) -> str :
@@ -31,33 +54,50 @@ def check_available_binary(
31
54
return skip_binary
32
55
33
56
list_binary = skip_binary .split ("," )
34
- available_data = requests .get (index , allow_redirects = True ).text
35
-
36
- list_needed : Set [str ] = set ()
37
- for binary in list_binary :
38
- for package in packages + constraints :
39
- if not package .startswith (binary ):
40
- continue
41
57
42
- # Check more details
43
- find = _RE_REQUIREMENT .match (package )
44
- if not find :
45
- raise ValueError (f"package requirement malformed: { package } " )
58
+ # Map of package basename to the desired package version
59
+ package_map = create_package_map (packages + constraints )
46
60
47
- # Check full name
48
- if binary != find ["package" ]:
49
- continue
50
-
51
- # Process packages
52
- name = f"{ binary } -{ find ['version' ]} "
53
- if name in available_data :
54
- continue
55
-
56
- # Ignore binary
57
- print (f"Ignore Binary { package } : { name } " , flush = True )
58
- list_needed .add (binary )
61
+ # View of package map limited to packages in --skip-binary
62
+ binary_package_map = {}
63
+ for binary in list_binary :
64
+ if not (package := package_map .get (binary )):
65
+ print (
66
+ f"Skip binary '{ binary } ' not in packages/constraints; Can't determine desired version" ,
67
+ flush = True ,
68
+ )
69
+ continue
70
+ binary_package_map [binary ] = package
71
+
72
+ print (f"Checking if binaries already exist for packages { binary_package_map } " )
73
+ list_found : Set [str ] = check_existing_packages (index , binary_package_map )
74
+ print (f"Packages already exist: { list_found } " )
75
+ list_needed = binary_package_map .keys () - list_found
59
76
60
77
# Generate needed list of skip binary
61
78
if not list_needed :
62
79
return ":none:"
80
+
81
+ print (f"Will force binary build for { list_needed } " )
63
82
return "," .join (list_needed )
83
+
84
+
85
+ def remove_local_wheels (
86
+ index : str ,
87
+ skip_exists : List [str ],
88
+ packages : List [str ],
89
+ wheels_dir : Path ,
90
+ ) -> str :
91
+ """Remove existing wheels if they already exist in the index to avoid syncing."""
92
+ package_map = create_package_map (packages )
93
+ binary_package_map = {
94
+ name : package_map [name ] for name in skip_exists if name in package_map
95
+ }
96
+ print (f"Checking if binaries already exist for packages { binary_package_map } " )
97
+ exists = check_existing_packages (index , binary_package_map )
98
+ for binary in exists :
99
+ package = binary_package_map [binary ]
100
+ print (f"Found existing wheels for { binary } , removing local copy { package } " )
101
+ for wheel in wheels_dir .glob (f"{ package } -*.whl" ):
102
+ print (f"Removing local wheel { wheel } " )
103
+ wheel .unlink ()
0 commit comments