Skip to content

Commit

Permalink
Use "sort_paths" from domdf_python_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Mar 4, 2021
1 parent 8f877b6 commit bc98b5c
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions repo_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import yapf_isort
from domdf_python_tools.dates import calc_easter
from domdf_python_tools.import_tools import discover_entry_points
from domdf_python_tools.paths import PathPlus
from domdf_python_tools.paths import PathPlus, sort_paths
from domdf_python_tools.pretty_print import FancyPrinter
from domdf_python_tools.stringlist import StringList
from domdf_python_tools.typing import PathLike
Expand Down Expand Up @@ -358,37 +358,6 @@ def no_dev_versions(versions: Iterable[str]) -> List[str]:
return [v for v in versions if not v.endswith("-dev")]


def sort_paths(*paths: PathLike) -> List[PathPlus]:
"""
Sort the list of paths by directory, then by file.
:param paths:
"""

directories: Dict[str, List[PathPlus]] = {}
local_contents: List[PathPlus] = []
files: List[PathPlus] = []

for obj in [PathPlus(path) for path in paths]:
if len(obj.parts) > 1:
key = obj.parts[0]
if key in directories:
directories[key].append(obj)
else:
directories[key] = [obj]
else:
local_contents.append(obj)

# sort directories
directories = {directory: directories[directory] for directory in sorted(directories.keys())}

for directory, contents in directories.items():
contents = [path.relative_to(directory) for path in contents]
files.extend(PathPlus(directory) / path for path in sort_paths(*contents))

return files + sorted(local_contents)


def stage_changes(
repo: Union[PathLike, dulwich.repo.Repo],
files: Iterable[PathLike],
Expand Down

0 comments on commit bc98b5c

Please sign in to comment.