@@ -269,53 +269,52 @@ async def unload_scripts(global_ctx_only=None, unload_all=False):
269
269
@bind_hass
270
270
async def install_requirements (hass ):
271
271
"""Install missing requirements from requirements.txt."""
272
- requirements_path = os .path .join (hass .config .path (FOLDER ), "requirements.txt" )
273
-
274
- if os .path .exists (requirements_path ):
275
- with open (requirements_path , "r" ) as requirements_file :
276
- requirements_to_install = []
277
- for pkg in requirements_file .readlines ():
278
- # Remove inline comments which are accepted by pip but not by Home
279
- # Assistant's installation method.
280
- # https://rosettacode.org/wiki/Strip_comments_from_a_string#Python
281
- i = pkg .find ("#" )
282
- if i >= 0 :
283
- pkg = pkg [:i ]
284
- pkg = pkg .strip ()
285
-
286
- try :
287
- # Attempt to get version of package. Do nothing if it's found since
288
- # we want to use the version that's already installed to be safe
289
- requirement = pkg_resources .Requirement .parse (pkg )
290
- requirement_installed_version = installed_version (requirement .project_name )
291
-
292
- if requirement_installed_version in requirement :
293
- _LOGGER .debug ("`%s` already found" , requirement .project_name )
294
- else :
295
- _LOGGER .warning (
296
- (
297
- "`%s` already found but found version `%s` does not"
298
- " match requirement. Keeping found version."
299
- ),
300
- requirement .project_name ,
301
- requirement_installed_version ,
302
- )
303
- except PackageNotFoundError :
304
- # Since package wasn't found, add it to installation list
305
- _LOGGER .debug ("%s not found, adding it to package installation list" , pkg )
306
- requirements_to_install .append (pkg )
307
- except ValueError :
308
- # Not valid requirements line so it can be skipped
309
- _LOGGER .debug ("Ignoring `%s` because it is not a valid package" , pkg )
310
- if requirements_to_install :
311
- _LOGGER .info (
312
- "Installing the following packages from %s: %s" ,
313
- requirements_path ,
314
- ", " .join (requirements_to_install ),
315
- )
316
- await async_process_requirements (hass , DOMAIN , requirements_to_install )
317
- else :
318
- _LOGGER .debug ("All packages in %s are already available" , requirements_path )
272
+ for root in ("" , "apps/*" , "modules/*" ):
273
+ for requirements_path in glob .glob (os .path .join (hass .config .path (FOLDER ), root , "requirements.txt" )):
274
+ with open (requirements_path , "r" ) as requirements_file :
275
+ requirements_to_install = []
276
+ for pkg in requirements_file .readlines ():
277
+ # Remove inline comments which are accepted by pip but not by Home
278
+ # Assistant's installation method.
279
+ # https://rosettacode.org/wiki/Strip_comments_from_a_string#Python
280
+ i = pkg .find ("#" )
281
+ if i >= 0 :
282
+ pkg = pkg [:i ]
283
+ pkg = pkg .strip ()
284
+
285
+ try :
286
+ # Attempt to get version of package. Do nothing if it's found since
287
+ # we want to use the version that's already installed to be safe
288
+ requirement = pkg_resources .Requirement .parse (pkg )
289
+ requirement_installed_version = installed_version (requirement .project_name )
290
+
291
+ if requirement_installed_version in requirement :
292
+ _LOGGER .debug ("`%s` already found" , requirement .project_name )
293
+ else :
294
+ _LOGGER .warning (
295
+ (
296
+ "`%s` already found but found version `%s` does not"
297
+ " match requirement. Keeping found version."
298
+ ),
299
+ requirement .project_name ,
300
+ requirement_installed_version ,
301
+ )
302
+ except PackageNotFoundError :
303
+ # Since package wasn't found, add it to installation list
304
+ _LOGGER .debug ("%s not found, adding it to package installation list" , pkg )
305
+ requirements_to_install .append (pkg )
306
+ except ValueError :
307
+ # Not valid requirements line so it can be skipped
308
+ _LOGGER .debug ("Ignoring `%s` because it is not a valid package" , pkg )
309
+ if requirements_to_install :
310
+ _LOGGER .info (
311
+ "Installing the following packages from %s: %s" ,
312
+ requirements_path ,
313
+ ", " .join (requirements_to_install ),
314
+ )
315
+ await async_process_requirements (hass , DOMAIN , requirements_to_install )
316
+ else :
317
+ _LOGGER .debug ("All packages in %s are already available" , requirements_path )
319
318
320
319
321
320
@bind_hass
0 commit comments