From 6ceb0a41ff8cdae0d8236ab2dd51e387ce8fb190 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 23 Jan 2015 17:47:26 +0100 Subject: [PATCH] venv: Save cache to standard cache location. Saving the cache inside the repository means the buildbot will clear it automatically. --- .gitignore | 1 - scripts/init_venv.py | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index c7458da18..3cb08b141 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,3 @@ __pycache__ /doc/*.html /README.html /qutebrowser/html/doc/ -/.venv-cache diff --git a/scripts/init_venv.py b/scripts/init_venv.py index 4d9c21b07..7f6116ef6 100644 --- a/scripts/init_venv.py +++ b/scripts/init_venv.py @@ -34,6 +34,8 @@ import venv import urllib.request import tempfile +from PyQt5.QtCore import QStandardPaths + sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) from scripts import utils @@ -62,8 +64,8 @@ def parse_args(): parser.add_argument('--dev', help="Set up an environment suitable for " "developing qutebrowser.", action='store_true') - parser.add_argument('--cache', help="Cache the clean virtualenv in " - "NAME-cache and copy it when a new one is requested.", + parser.add_argument('--cache', help="Cache the clean virtualenv and " + "copy it when a new one is requested.", action='store_true') parser.add_argument('path', help="Path to the venv folder", default='.venv', nargs='?') @@ -186,7 +188,7 @@ def create_venv(): install_pip() -def restore_cache(): +def restore_cache(cache_path): """Restore a cache if one is present and --cache is given.""" utils.print_title("Restoring cache") if g_args.cache: @@ -195,7 +197,7 @@ def restore_cache(): except FileNotFoundError: pass try: - shutil.copytree(g_args.path + '-cache', g_args.path, symlinks=True) + shutil.copytree(cache_path, g_args.path, symlinks=True) except FileNotFoundError: print("No cache present!") else: @@ -203,15 +205,15 @@ def restore_cache(): return False -def save_cache(): +def save_cache(cache_path): """Save the cache if --cache is given.""" utils.print_title("Saving cache") if g_args.cache: try: - shutil.rmtree(g_args.path + '-cache') + shutil.rmtree(cache_path) except FileNotFoundError: pass - shutil.copytree(g_args.path, g_args.path + '-cache', symlinks=True) + shutil.copytree(g_args.path, cache_path, symlinks=True) def main(): @@ -229,7 +231,11 @@ def main(): "--upgrade.".format(g_path), file=sys.stderr) sys.exit(1) - restored = restore_cache() + os_cache_dir = QStandardPaths.writableLocation( + QStandardPaths.CacheLocation) + cache_path = os.path.join(os_cache_dir, 'qutebrowser-venv') + + restored = restore_cache(cache_path) if not restored: create_venv() @@ -241,7 +247,7 @@ def main(): install_dev_packages() link_pyqt() test_toolchain() - save_cache() + save_cache(cache_path) if __name__ == '__main__':