clean up of spack clean (#8610)
* update help of `clean --all` to include `-p` * remove old orphaned `.pyc` removal * restrict removal or orphaned pyc files to `lib/spack` and `var/spack`
This commit is contained in:
parent
5192a3d6d6
commit
79b407f59e
24
bin/spack
24
bin/spack
@ -56,30 +56,6 @@ else:
|
|||||||
spack_yaml_libs = os.path.join(spack_external_libs, "yaml/lib3")
|
spack_yaml_libs = os.path.join(spack_external_libs, "yaml/lib3")
|
||||||
sys.path.insert(0, spack_yaml_libs)
|
sys.path.insert(0, spack_yaml_libs)
|
||||||
|
|
||||||
# Quick and dirty check to clean orphaned .pyc files left over from
|
|
||||||
# previous revisions. These files were present in earlier versions of
|
|
||||||
# Spack, were removed, but shadow system modules that Spack still
|
|
||||||
# imports. If we leave them, Spack will fail in mysterious ways.
|
|
||||||
# TODO: more elegant solution for orphaned pyc files.
|
|
||||||
orphaned_pyc_files = [
|
|
||||||
os.path.join(spack_external_libs, 'functools.pyc'),
|
|
||||||
os.path.join(spack_external_libs, 'ordereddict.pyc'),
|
|
||||||
os.path.join(spack_lib_path, 'spack', 'platforms', 'cray_xc.pyc'),
|
|
||||||
os.path.join(spack_lib_path, 'spack', 'cmd', 'package-list.pyc'),
|
|
||||||
os.path.join(spack_lib_path, 'spack', 'cmd', 'test-install.pyc'),
|
|
||||||
os.path.join(spack_lib_path, 'spack', 'cmd', 'url-parse.pyc'),
|
|
||||||
os.path.join(spack_lib_path, 'spack', 'test', 'yaml.pyc')
|
|
||||||
]
|
|
||||||
|
|
||||||
for pyc_file in orphaned_pyc_files:
|
|
||||||
if not os.path.exists(pyc_file):
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
os.remove(pyc_file)
|
|
||||||
except OSError as e:
|
|
||||||
print("WARNING: Spack may fail mysteriously. "
|
|
||||||
"Couldn't remove orphaned .pyc file: %s" % pyc_file)
|
|
||||||
|
|
||||||
# Once we've set up the system path, run the spack main method
|
# Once we've set up the system path, run the spack main method
|
||||||
import spack.main # noqa
|
import spack.main # noqa
|
||||||
sys.exit(spack.main.main())
|
sys.exit(spack.main.main())
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
import spack.cmd
|
import spack.cmd
|
||||||
import spack.repo
|
import spack.repo
|
||||||
import spack.stage
|
import spack.stage
|
||||||
from spack.paths import spack_root
|
from spack.paths import lib_path, var_path
|
||||||
|
|
||||||
|
|
||||||
description = "remove temporary build files and/or downloaded archives"
|
description = "remove temporary build files and/or downloaded archives"
|
||||||
section = "build"
|
section = "build"
|
||||||
@ -59,7 +60,7 @@ def setup_parser(subparser):
|
|||||||
'-p', '--python-cache', action='store_true',
|
'-p', '--python-cache', action='store_true',
|
||||||
help="remove .pyc, .pyo files and __pycache__ folders")
|
help="remove .pyc, .pyo files and __pycache__ folders")
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-a', '--all', action=AllClean, help="equivalent to -sdm", nargs=0
|
'-a', '--all', action=AllClean, help="equivalent to -sdmp", nargs=0
|
||||||
)
|
)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'specs',
|
'specs',
|
||||||
@ -97,7 +98,8 @@ def clean(parser, args):
|
|||||||
|
|
||||||
if args.python_cache:
|
if args.python_cache:
|
||||||
tty.msg('Removing python cache files')
|
tty.msg('Removing python cache files')
|
||||||
for root, dirs, files in os.walk(spack_root):
|
for directory in [lib_path, var_path]:
|
||||||
|
for root, dirs, files in os.walk(directory):
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.endswith('.pyc') or f.endswith('.pyo'):
|
if f.endswith('.pyc') or f.endswith('.pyo'):
|
||||||
fname = os.path.join(root, f)
|
fname = os.path.join(root, f)
|
||||||
|
Loading…
Reference in New Issue
Block a user