Skip to content

Commit

Permalink
Upgrade and format directory_writer.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
VaeterchenFrost committed Dec 18, 2024
1 parent 30d7da7 commit d718ed7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/directory_writer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.12

Expand All @@ -27,7 +27,7 @@ jobs:
uses: EndBug/add-and-commit@v4
with:
author_name: Martin Röbke
author_email: martin.roebke@tu-dresden.de
author_email: martin.roebke@web.de
message: "Automatic Update: DIRECTORY.md"
add: "DIRECTORY.md"
env:
Expand Down
27 changes: 15 additions & 12 deletions scripts/build_directory_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@

URL_BASE = "https://github.com/VaeterchenFrost/tdvisu/blob/master"

AFFECTED_EXT = ('.py', '.ipynb',)
AFFECTED_EXT = (
".py",
".ipynb",
)

EXCLUDED_FILENAMES = ('__init__.py',)
EXCLUDED_FILENAMES = ("__init__.py",)


def good_file_paths(top_dir: str = '.') -> Iterator[str]:
def good_file_paths(top_dir: str = ".") -> Iterator[str]:
"""Return relative path to files with extension in AFFECTED_EXT."""
for dir_path, dir_names, filenames in os.walk(top_dir):
dir_names[:] = [d for d in dir_names
if d != 'scripts' and d[0] not in '._']
dir_names[:] = [d for d in dir_names if d != "scripts" and d[0] not in "._"]
for filename in filenames:
if filename in EXCLUDED_FILENAMES:
continue
if os.path.splitext(filename)[1] in AFFECTED_EXT:
normalized_path = os.path.normpath(dir_path)
if normalized_path != '.':
if normalized_path != ".":
yield os.path.join(normalized_path, filename)
else:
yield filename
Expand All @@ -68,19 +70,20 @@ def print_path(old_path: str, new_path: str) -> str:
return new_path


def print_directory_md(top_dir: str = '.') -> None:
def print_directory_md(top_dir: str = ".") -> None:
"""Print the markdown for files with selected extensions recursing top_dir."""
old_path = ''
old_path = ""
for filepath in sorted(good_file_paths(top_dir)):
filepath, filename = os.path.split(filepath)
if filepath != old_path:
old_path = print_path(old_path, filepath)
indent = (filepath.count(os.sep) + 1) if filepath else 0
url = '/'.join((URL_BASE, *[quote(part)
for part in (filepath, filename) if part]))
filename = os.path.splitext(filename.replace('_', ' ').title())[0]
url = "/".join(
(URL_BASE, *[quote(part) for part in (filepath, filename) if part])
)
filename = os.path.splitext(filename.replace("_", " ").title())[0]
print(f"{md_prefix(indent)} [{filename}]({url})")


if __name__ == "__main__":
print_directory_md('.')
print_directory_md(".")

0 comments on commit d718ed7

Please sign in to comment.