make starting with an unexpected prefix an exception

This commit is contained in:
Jeff Epler 2023-07-31 10:41:10 -05:00
parent f3c4a981c3
commit 2e040b0d13
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -239,6 +239,10 @@ def get_repository_url(directory):
repository_urls[directory] = path
return path
def remove_prefix(s, prefix):
if not s.startswith(prefix):
raise ValueError(f"{s=} does not start with {prefix=}")
return s.removeprefix(prefix)
def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
"""
@ -251,7 +255,7 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
"""
frozen_modules = []
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
frozen_path = frozen_path.removeprefix('../../')
frozen_path = remove_prefix(frozen_path, '../../')
source_dir = get_circuitpython_root_dir() / frozen_path
url_repository = get_repository_url(source_dir)
for sub in source_dir.glob("*"):