Skip to content

Commit

Permalink
Remove firedrake_configuration from init
Browse files Browse the repository at this point in the history
  • Loading branch information
JDBetteridge committed Nov 1, 2024
1 parent 34dd9d5 commit 35e1eb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 88 deletions.
17 changes: 2 additions & 15 deletions firedrake/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import firedrake_configuration
import os
import sys
config = firedrake_configuration.get_config()
if "PETSC_DIR" in os.environ and not config["options"]["honour_petsc_dir"]:
if os.environ["PETSC_DIR"] != os.path.join(sys.prefix, "src", "petsc")\
or os.environ["PETSC_ARCH"] != "default":
raise ImportError("PETSC_DIR is set, but you did not install with --honour-petsc-dir.\n"
"Please unset PETSC_DIR (and PETSC_ARCH) before using Firedrake.")
elif "PETSC_DIR" not in os.environ and config["options"]["honour_petsc_dir"]:
raise ImportError("Firedrake was installed with --honour-petsc-dir, but PETSC_DIR is not set.\n"
"Please set PETSC_DIR (and PETSC_ARCH) before using Firedrake.")
elif not config["options"]["honour_petsc_dir"]: # Using our own PETSC.
os.environ["PETSC_DIR"] = os.path.join(sys.prefix, "src", "petsc")
os.environ["PETSC_ARCH"] = "default"
del config
from firedrake.configuration import setup_cache_dirs

# Set up the cache directories before importing PyOP2.
firedrake_configuration.setup_cache_dirs()
setup_cache_dirs()

# Ensure petsc is initialised by us before anything else gets in there.
#
Expand Down
30 changes: 15 additions & 15 deletions firedrake/scripts/firedrake_clean
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#!/usr/bin/env python3
import os
import shutil
import tempfile
import firedrake_configuration
from firedrake.configuration import setup_cache_dirs
from pyop2.compilation import clear_compiler_disk_cache as pyop2_clear_cache
from firedrake.tsfc_interface import clear_cache as tsfc_clear_cache
try:
import platformdirs as appdirs
except ImportError:
import appdirs


def main():
firedrake_configuration.setup_cache_dirs()
tsfc_cache = os.environ.get('FIREDRAKE_TSFC_KERNEL_CACHE_DIR',
os.path.join(tempfile.gettempdir(),
'firedrake-tsfc-kernel-cache-uid%d' % os.getuid()))
pyop2_cache = os.environ.get('PYOP2_CACHE_DIR',
os.path.join(tempfile.gettempdir(),
'pyop2-cache-uid%d' % os.getuid()))
print("Setup cache directories")
setup_cache_dirs()

print(f"Removing cached TSFC kernels from {os.environ.get('FIREDRAKE_TSFC_KERNEL_CACHE_DIR', '???')}")
tsfc_clear_cache()

print(f"Removing cached PyOP2 code from {os.environ.get('FIREDRAKE_TSFC_KERNEL_CACHE_DIR', '???')}")
pyop2_clear_cache()

pytools_cache = appdirs.user_cache_dir("pytools", "pytools")
print('Removing cached TSFC kernels from %s' % tsfc_cache)
print('Removing cached PyOP2 code from %s' % pyop2_cache)
print('Removing cached pytools files from %s' % pytools_cache)
for cache in [tsfc_cache, pyop2_cache, pytools_cache]:
if os.path.exists(cache):
shutil.rmtree(cache, ignore_errors=True)
print(f"Removing cached pytools files from {pytools_cache}")
if os.path.exists(pytools_cache):
shutil.rmtree(pytools_cache, ignore_errors=True)


if __name__ == '__main__':
Expand Down
58 changes: 0 additions & 58 deletions firedrake_configuration/__init__.py

This file was deleted.

0 comments on commit 35e1eb6

Please sign in to comment.