From 057ea653c039d2338cd1160a5f20769b0bd8e8e3 Mon Sep 17 00:00:00 2001 From: "Lara A. Ross" Date: Tue, 10 Mar 2015 13:03:29 -0700 Subject: [PATCH] Put cache in the correct place Closes #90. --- .gitignore | 3 ++- proselint/tools.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7b3d9465a..88e5fd147 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ *.pyc cached_func_calls/* site/_posts/* -proselint/cache/* profile_output site/write/* tests/corpus/newyorker/* +cache/* +proselint/cache/* diff --git a/proselint/tools.py b/proselint/tools.py index 81ea56808..22893afa5 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -9,11 +9,25 @@ import re +def on_heroku(): + """Figure out if we're on Heroku.""" + if 'DYNO' in os.environ: + return True + else: + return False + + def memoize(f): """Cache results of computations on disk.""" path_of_this_file = os.path.dirname(os.path.realpath(__file__)) - cache_dirname = os.path.join(path_of_this_file, "cache") + # Determine the location of the cache. + if on_heroku(): + cache_dirname = os.path.join(os.path.dirname(path_of_this_file), "tmp") + else: + cache_dirname = os.path.join(path_of_this_file, "cache") + + # Create the cache if it does not already exist. if not os.path.isdir(cache_dirname): os.mkdir(cache_dirname)