4040import pkg_resources
4141
4242BLINKA_LIBRARIES = [
43- "adafruit_blinka " ,
44- "adafruit_blinka_bleio " ,
45- "adafruit_blinka_displayio " ,
46- "adafruit_blinka_pyportal " ,
47- "adafruit_python_extended_bus " ,
43+ "adafruit-blinka " ,
44+ "adafruit-blinka-bleio " ,
45+ "adafruit-blinka-displayio " ,
46+ "adafruit-blinka-pyportal " ,
47+ "adafruit-python-extended-bus " ,
4848 "numpy" ,
4949 "pillow" ,
5050 "pyasn1" ,
5353]
5454
5555def normalize_dist_name (name : str ) -> str :
56- return name .lower ().replace ("-" , "_" )
56+ """Return a normalized pip name"""
57+ return name .lower ().replace ("_" , "-" )
5758
5859def add_file (bundle , src_file , zip_name ):
5960 bundle .write (src_file , zip_name )
@@ -70,7 +71,7 @@ def get_module_name(library_path):
7071 repo = repo .stdout .decode ("utf-8" , errors = "ignore" ).strip ().lower ()
7172 if repo [- 4 :] == ".git" :
7273 repo = repo [:- 4 ]
73- module_name = repo .split ("/" )[- 1 ]. replace ( "_" , "-" )
74+ module_name = normalize_dist_name ( repo .split ("/" )[- 1 ])
7475
7576 # circuitpython org repos are deployed to pypi without "org" in the pypi name
7677 module_name = re .sub (r"^circuitpython-org-" , "circuitpython-" , module_name )
@@ -83,8 +84,8 @@ def get_bundle_requirements(directory, package_list):
8384 Return the list
8485 """
8586
86- pypi_reqs = [] # For multiple bundle dependency
87- dependencies = [] # For intra-bundle dependency
87+ pypi_reqs = set () # For multiple bundle dependency
88+ dependencies = set () # For intra-bundle dependency
8889
8990 path = directory + "/requirements.txt"
9091 if os .path .exists (path ):
@@ -97,15 +98,16 @@ def get_bundle_requirements(directory, package_list):
9798 # skip comments
9899 pass
99100 else :
100- if any (operators in line for operators in [">" , "<" , "=" ]):
101- # Remove everything after any pip style version specifiers
102- line = re .split ("[<|>|=|]" , line )[0 ]
103- line = normalize_dist_name (line )
104- if line not in dependencies and line in package_list :
105- dependencies .append (package_list [line ]["module_name" ])
106- elif line not in pypi_reqs and line not in BLINKA_LIBRARIES :
107- pypi_reqs .append (line )
108- return dependencies , pypi_reqs
101+ # Remove any pip version and platform specifiers
102+ original_name = re .split ("[<>=~[;]" , line )[0 ].strip ()
103+ # Normalize to match the indexes in package_list
104+ line = normalize_dist_name (original_name )
105+ if line in package_list :
106+ dependencies .add (package_list [line ]["module_name" ])
107+ elif line not in BLINKA_LIBRARIES :
108+ # add with the exact spelling from requirements.txt
109+ pypi_reqs .add (original_name )
110+ return sorted (dependencies ), sorted (pypi_reqs )
109111
110112def build_bundle_json (libs , bundle_version , output_filename , package_folder_prefix ):
111113 """
@@ -137,7 +139,7 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref
137139 library ["dependencies" ], library ["external_dependencies" ] = get_bundle_requirements (packages [id ]["library_path" ], packages )
138140 library_submodules [packages [id ]["module_name" ]] = library
139141 out_file = open (output_filename , "w" )
140- json .dump (library_submodules , out_file )
142+ json .dump (library_submodules , out_file , sort_keys = True )
141143 out_file .close ()
142144
143145def build_bundle (libs , bundle_version , output_filename , package_folder_prefix ,
0 commit comments