mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
replace simplify walk method
This commit is contained in:
parent
3d97490c11
commit
440d7785d2
@ -461,7 +461,7 @@ def trim_package(package_name: str) -> str:
|
|||||||
str: package name without description or version bound
|
str: package name without description or version bound
|
||||||
"""
|
"""
|
||||||
for symbol in ("<", "=", ">", ":"):
|
for symbol in ("<", "=", ">", ":"):
|
||||||
package_name = package_name.partition(symbol)[0]
|
package_name, *_ = package_name.split(symbol, maxsplit=1)
|
||||||
return package_name
|
return package_name
|
||||||
|
|
||||||
|
|
||||||
@ -478,7 +478,6 @@ def utcnow() -> datetime.datetime:
|
|||||||
def walk(directory_path: Path) -> Generator[Path, None, None]:
|
def walk(directory_path: Path) -> Generator[Path, None, None]:
|
||||||
"""
|
"""
|
||||||
list all file paths in given directory
|
list all file paths in given directory
|
||||||
Credits to https://stackoverflow.com/a/64915960
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
directory_path(Path): root directory path
|
directory_path(Path): root directory path
|
||||||
@ -487,18 +486,13 @@ def walk(directory_path: Path) -> Generator[Path, None, None]:
|
|||||||
Path: all found files in given directory with full path
|
Path: all found files in given directory with full path
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
Since the :mod:`pathlib` module does not provide an alternative to :func:`os.walk()`, this wrapper
|
Wrapper around :func:`pathlib.Path.walk`, which yields only files instead::
|
||||||
can be used instead::
|
|
||||||
|
|
||||||
>>> from pathlib import Path
|
>>> from pathlib import Path
|
||||||
>>>
|
>>>
|
||||||
>>> for file_path in walk(Path.cwd()):
|
>>> for file_path in walk(Path.cwd()):
|
||||||
>>> print(file_path)
|
>>> print(file_path)
|
||||||
|
|
||||||
Note, however, that unlike the original method, it does not yield directories.
|
|
||||||
"""
|
"""
|
||||||
for element in directory_path.iterdir():
|
for root, _, files in directory_path.walk(follow_symlinks=True):
|
||||||
if element.is_dir():
|
for file in files:
|
||||||
yield from walk(element)
|
yield root / file
|
||||||
continue
|
|
||||||
yield element
|
|
||||||
|
Loading…
Reference in New Issue
Block a user