Skip to content

Fix do all redirects #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 12, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use functools.cache in redirects script.
  • Loading branch information
QuLogic committed Feb 9, 2021
commit 6fcc3b744733fb9081825a96731fa5d3b42ce812
12 changes: 4 additions & 8 deletions _websiteutils/make_redirects_links.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import functools
import logging
import multiprocessing
import os
Expand Down Expand Up @@ -53,22 +54,17 @@
logging.basicConfig(level=logging.DEBUG)


# beware of triksy mutable defaults!
def findlast(fname, tocheck, *, _cache={}):
@functools.cache
def findlast(fname, tocheck):
"""
Check the directories listed in ``tocheck`` to see if they have
``fname`` in them. Return the first one found, or None
"""
if fname in _cache:
return _cache[fname]
for t in tocheck:
pnew = t / fname
if pnew.exists():
_cache[fname] = t
return t
else:
_cache[fname] = None
return None
return None


html_redirect = """<!DOCTYPE HTML>
Expand Down