Skip to content

Commit

Permalink
neurodamus: move core modifications into packages (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
matz-e committed Jun 9, 2022
1 parent 82a47b2 commit b00c856
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from spack import *

from .sim_model import SimModel
from .sim_model import SimModel, copy_all, make_link


class ModelNeocortex(SimModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from spack import *

from .sim_model import SimModel
from .sim_model import SimModel, copy_all

# Definitions
_CORENRN_MODLIST_FNAME = "coreneuron_modlist.txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from spack import *

from .py_neurodamus import PyNeurodamus
from .sim_model import SimModel
from .sim_model import SimModel, copy_all, make_link

# Definitions
_CORENRN_MODLIST_FNAME = "coreneuron_modlist.txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from .neurodamus_model import (
NeurodamusModel,
copy_all,
make_link,
version_from_model_core_dep,
version_from_model_ndpy_dep,
)
Expand Down
36 changes: 36 additions & 0 deletions bluebrain/repo-bluebrain/packages/sim-model/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,39 @@ def profiling_wrapper_on():
os.environ['USE_PROFILER_WRAPPER'] = '1'
yield
del os.environ['USE_PROFILER_WRAPPER']


def copy_all(src, dst, copyfunc=shutil.copy):
"""Copy/process all files in a src dir into a destination dir.
"""
isdir = os.path.isdir
for name in os.listdir(src):
pth = join_path(src, name)
isdir(pth) or copyfunc(pth, dst)


def make_link(src, dst):
"""Create a symlink in a given destination.
make_link is copy compatible i.e. will take the same args and behave
similarly to shutil.copy except that it will create a soft link instead.
If destination is a directory then a new symlink is created inside with
the same name as the original file.
Relative src paths create a relative symlink (properly relocated) while
absolute paths crete an abolute-path symlink.
If another link already exists in the destination with the same it is
deleted before link creation.
Args:
src (str): The path of the file to create a link to
dst (str): The link destination path (may be a directory)
"""
if os.path.isdir(dst):
dst_dir = dst
dst = join_path(dst, os.path.basename(src))
else:
dst_dir = os.path.dirname(dst)
if not os.path.isabs(src):
src = os.path.relpath(src, dst_dir) # update path relation
# Silently replace links, just like copy replaces files
if os.path.islink(dst):
os.remove(dst)
os.symlink(src, dst)
38 changes: 0 additions & 38 deletions lib/spack/llnl/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
'is_exe',
'join_path',
'last_modification_time_recursive',
'copy_all',
'make_link',
'mkdirp',
'partition_path',
'prefixes',
Expand Down Expand Up @@ -645,42 +643,6 @@ def force_remove(*paths):
pass


def copy_all(src, dst, copyfunc=shutil.copy):
"""Copy/process all files in a src dir into a destination dir.
"""
isdir = os.path.isdir
for name in os.listdir(src):
pth = join_path(src, name)
isdir(pth) or copyfunc(pth, dst)


def make_link(src, dst):
"""Create a symlink in a given destination.
make_link is copy compatible i.e. will take the same args and behave
similarly to shutil.copy except that it will create a soft link instead.
If destination is a directory then a new symlink is created inside with
the same name as the original file.
Relative src paths create a relative symlink (properly relocated) while
absolute paths crete an abolute-path symlink.
If another link already exists in the destination with the same it is
deleted before link creation.
Args:
src (str): The path of the file to create a link to
dst (str): The link destination path (may be a directory)
"""
if os.path.isdir(dst):
dst_dir = dst
dst = join_path(dst, os.path.basename(src))
else:
dst_dir = os.path.dirname(dst)
if not os.path.isabs(src):
src = os.path.relpath(src, dst_dir) # update path relation
# Silently replace links, just like copy replaces files
if os.path.islink(dst):
os.remove(dst)
os.symlink(src, dst)


@contextmanager
def working_dir(dirname, **kwargs):
if kwargs.get('create', False):
Expand Down

0 comments on commit b00c856

Please sign in to comment.