Add configurable requests cache directory

As I expected, on Google App Engine we can't write the cache file
to the current working directory. I modified csv-metadata-quality
CLI to check for the REQUESTS_CACHE_DIR environment variable so we
don't really have to do anything different other than setting the
variable.
This commit is contained in:
2021-03-14 10:06:39 +02:00
parent e7dd8d1421
commit 4e52d1bcc9
3 changed files with 13 additions and 3 deletions

10
main.py
View File

@ -68,12 +68,22 @@ def process():
if "experimental" in request.form:
args.append("-e")
# Set cache dir to our upload path so we can tell csv-metadata-quality
# to store its requests-cache database there instead of in the current
# working directory (we can only write to /tmp on Google App Engine).
# Also, make sure to keep our PATH!
env = {
"REQUESTS_CACHE_DIR": app.config["UPLOAD_PATH"],
"PATH": os.environ["PATH"],
}
# run subprocess and capture output as UTF-8 so we get a string instead of
# bytes for ansi2html
results = subprocess.run(
["csv-metadata-quality"] + args,
capture_output=True,
encoding="UTF-8",
env=env,
)
# convert the output to HTML using ansi2html
conv = Ansi2HTMLConverter()