Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
name: Tests
on:
push:
branches: ['*']
pull_request:
push:
branches: [main]
jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ utilo_tidy = "utilo.xyz.tidy:main"
dev = [
"PyYAML>=6.0.3,<7.0.0",
"pytest-timeout>=2.4.0,<3.0.0",
"utilotest>=1.0.5,<2.0.0",
"iamraw>=4.94.1,<5.0.0",
"utilotest>=1.1.1,<2.0.0",
"iamraw>=4.95.0,<5.0.0",
]

[project.urls]
Expand Down
14 changes: 12 additions & 2 deletions utilo/file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,16 @@ def file_ext(path: str) -> str:
return None


def files_sort(files: list) -> list:
def files_sort(files: list) -> list[str]:
"""Sort `files` path alphabetically. Sort file names by number if given.

>>> files_sort(('/c/a', '/c/200.txt', '/c/2.txt', '/c/3', '/c/0.bmp'))
['/c/0.bmp', '/c/2.txt', '/c/3', '/c/200.txt', '/c/a']
>>> import os
>>> files_sort(os.scandir('.'))
[...]
"""
files = [utilo.forward_slash(item) for item in files]
files = [file_path(item) for item in files]

def number_filename(item):
# sort file names if they are numbers: 0,1,2,3,4,5,6,7,8,9,10
Expand All @@ -502,6 +505,13 @@ def number_filename(item):
return files


def file_path(path):
if isinstance(path, os.DirEntry):
return file_path(str(path.path))
path = utilo.forward_slash(path)
return path


# Alphabetic with Nn and Tt to avoid \n\t in connex with file names
POOL = 'ABCDEFGHIJKLMOPQRSUVYXYZabcdefghijklmtpqrsuvyxyz123456789'

Expand Down