|
|
@@ -23,6 +23,7 @@ |
|
|
|
# SUCH DAMAGE. |
|
|
|
|
|
|
|
import contextlib |
|
|
|
import filecmp |
|
|
|
import functools |
|
|
|
import glob |
|
|
|
import hashlib |
|
|
@@ -341,8 +342,18 @@ class CASFinder(MetaPathFinder, Loader): |
|
|
|
exec(data, module.__dict__) |
|
|
|
|
|
|
|
def defaultinit(casf): |
|
|
|
cachedir = pathlib.Path.home() / '.casimport_cache' |
|
|
|
cachedir.mkdir(exist_ok=True) |
|
|
|
basedir = pathlib.Path.home() / '.casimport' |
|
|
|
|
|
|
|
conffile = basedir / 'casimport.conf' |
|
|
|
if not conffile.exists(): |
|
|
|
basedir.mkdir(exist_ok=True) |
|
|
|
import casimport |
|
|
|
with importlib.resources.path(casimport, |
|
|
|
'default.conf') as defconf: |
|
|
|
shutil.copy(defconf, conffile) |
|
|
|
|
|
|
|
cachedir = basedir / 'cache' |
|
|
|
cachedir.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
|
|
casf.register(FileDirCAS(cachedir)) |
|
|
|
casf.register(IPFSCAS()) |
|
|
@@ -458,18 +469,24 @@ class Test(unittest.TestCase): |
|
|
|
def test_defaultinit(self): |
|
|
|
temphome = self.tempdir / 'home' |
|
|
|
temphome.mkdir() |
|
|
|
cachedir = temphome / '.casimport_cache' |
|
|
|
defcachedir = temphome / '.casimport' / 'cache' |
|
|
|
|
|
|
|
# testing w/ default config |
|
|
|
with tempset(os.environ, 'HOME', str(temphome)): |
|
|
|
with CASFinder() as f: |
|
|
|
# Setup the defaults |
|
|
|
defaultinit(f) |
|
|
|
|
|
|
|
# That the default.conf file got copied over. |
|
|
|
filecmp.cmp(defcachedir.parent / |
|
|
|
'casimport.conf', |
|
|
|
pathlib.Path(__file__).parent / 'default.conf') |
|
|
|
|
|
|
|
# that the cache got created |
|
|
|
self.assertTrue(cachedir.is_dir()) |
|
|
|
self.assertTrue(defcachedir.is_dir()) |
|
|
|
|
|
|
|
# and that when hello.py is copied to the cache |
|
|
|
shutil.copy(self.fixtures / 'hello.py', cachedir) |
|
|
|
shutil.copy(self.fixtures / 'hello.py', defcachedir) |
|
|
|
|
|
|
|
# it can be imported |
|
|
|
from cas.v1_f_330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3 import hello |
|
|
@@ -525,10 +542,16 @@ class Test(unittest.TestCase): |
|
|
|
'load_mod_aliases', f.load_mod_aliases): |
|
|
|
defaultinit(f) |
|
|
|
|
|
|
|
# XXX - fix this so this is properly |
|
|
|
# used. It's using other methods to |
|
|
|
# work currently |
|
|
|
|
|
|
|
# and that hello.py is in the cache |
|
|
|
shutil.copy(self.fixtures / 'hello.py', |
|
|
|
cachedir) |
|
|
|
|
|
|
|
self.assertNotIn('randpkg', sys.modules) |
|
|
|
|
|
|
|
# that the import is successful |
|
|
|
import randpkg |
|
|
|
|
|
|
@@ -570,6 +593,8 @@ class Test(unittest.TestCase): |
|
|
|
|
|
|
|
# and pulled in the method |
|
|
|
self.assertTrue(hasattr(randpkg, 'hello')) |
|
|
|
|
|
|
|
del sys.modules['randpkg'] |
|
|
|
finally: |
|
|
|
sys.path.remove(fixdir) |
|
|
|
|
|
|
|