diff --git a/src/nexusformat/nexus/lock.py b/src/nexusformat/nexus/lock.py index f305129..96ad348 100644 --- a/src/nexusformat/nexus/lock.py +++ b/src/nexusformat/nexus/lock.py @@ -78,7 +78,7 @@ def __init__(self, filename, timeout=None, check_interval=1, expiry=28800, raise NXLockException( f"Lockfile directory '{directory}' does not exist") path = self.filename.relative_to(self.filename.anchor) - self.lock_file = Path(directory).joinpath('_'.join(path.parts) + self.lock_file = Path(directory).joinpath('!!'.join(path.parts) ).with_suffix(suffix) else: self.lock_file = self.filename.with_suffix(suffix) diff --git a/src/nexusformat/nexus/tree.py b/src/nexusformat/nexus/tree.py index 81b6775..273e816 100644 --- a/src/nexusformat/nexus/tree.py +++ b/src/nexusformat/nexus/tree.py @@ -216,9 +216,11 @@ warnings.simplefilter('ignore', category=FutureWarning) +# Default configuration parameters. NX_CONFIG = {'compression': 'gzip', 'encoding': 'utf-8', 'lock': 0, 'lockexpiry': 8 * 3600, 'lockdirectory': None, 'maxsize': 10000, 'memory': 2000, 'recursive': False} +# These are overwritten below by environment variables if defined. string_dtype = h5.special_dtype(vlen=str) np.set_printoptions(threshold=5, precision=6) @@ -7269,6 +7271,8 @@ def setconfig(**kwargs): value = None else: value = str(value) + if not NX_CONFIG['lock']: + NX_CONFIG['lock'] = 10 elif parameter == 'recursive': if value in ['True', 'true', 'Yes', 'yes', 'Y', 'y', '1']: value = True @@ -7277,11 +7281,16 @@ def setconfig(**kwargs): NX_CONFIG[parameter] = value +# Update configuration parameters that are defined as environment variables. for parameter in NX_CONFIG: if 'NX_' + parameter.upper() in os.environ: value = os.environ['NX_'+parameter.upper()] setconfig(**{parameter: value}) +# If a lock directory is defined, locking should be turned on by default. +if NX_CONFIG['lockdirectory'] and not NX_CONFIG['lock']: + NX_CONFIG['lock'] = 10 + nxgetconfig = getconfig nxsetconfig = setconfig