mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
Meta: Refactor map_to_path()
to use a basic loop
This commit is contained in:
parent
ccb4c205cd
commit
cc76225c1f
Notes:
github-actions[bot]
2024-12-19 09:55:42 +00:00
Author: https://github.com/LucasChollet
Commit: cc76225c1f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2929
Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 13 additions and 24 deletions
|
@ -96,34 +96,23 @@ class TestTypeIdentifier(HTMLParser):
|
||||||
self.ref_test_link_found = True
|
self.ref_test_link_found = True
|
||||||
|
|
||||||
|
|
||||||
def map_to_path(sources, is_resource=True, resource_path=None):
|
def map_to_path(sources: list[str], is_resource=True, resource_path=None) -> list[PathMapping]:
|
||||||
if is_resource:
|
filepaths: list[PathMapping] = []
|
||||||
# Add it as a sibling path if it's a relative resource
|
|
||||||
sibling_location = Path(resource_path).parent.__str__()
|
|
||||||
sibling_import_path = test_type.input_path + '/' + sibling_location
|
|
||||||
|
|
||||||
def remapper(x):
|
for source in sources:
|
||||||
if x.startswith('/'):
|
if source.startswith('/') or not is_resource:
|
||||||
return test_type.input_path + x
|
file_path = test_type.input_path + '/' + source
|
||||||
return sibling_import_path + '/' + x
|
|
||||||
|
|
||||||
filepaths = list(map(remapper, sources))
|
|
||||||
filepaths = list(map(lambda x: Path(x), filepaths))
|
|
||||||
else:
|
else:
|
||||||
# Add the test_type.input_path to the sources if root files
|
# Add it as a sibling path if it's a relative resource
|
||||||
def remapper(x):
|
sibling_location = str(Path(resource_path).parent)
|
||||||
if x.startswith('/'):
|
parent_directory = test_type.input_path + '/' + sibling_location
|
||||||
return test_type.input_path + x
|
|
||||||
return test_type.input_path + '/' + x
|
|
||||||
|
|
||||||
filepaths = list(map(lambda x: Path(remapper(x)), sources))
|
file_path = parent_directory + '/' + source
|
||||||
|
|
||||||
# Map to source and destination
|
# Map to source and destination
|
||||||
def path_mapper(x):
|
output_path = wpt_base_url + file_path.replace(test_type.input_path, '')
|
||||||
output_path = wpt_base_url + x.__str__().replace(test_type.input_path, '')
|
|
||||||
return PathMapping(output_path, x.absolute())
|
|
||||||
|
|
||||||
filepaths = list(map(path_mapper, filepaths))
|
filepaths.append(PathMapping(output_path, Path(file_path).absolute()))
|
||||||
|
|
||||||
return filepaths
|
return filepaths
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue