Skip to content

Commit

Permalink
Merge pull request #181 from rayosborn/initialize-envs
Browse files Browse the repository at this point in the history
Initialize envs
  • Loading branch information
rayosborn authored Sep 29, 2022
2 parents 9e9ae6c + 1332e08 commit 939aedd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nexusformat/nexus/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/nexusformat/nexus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 939aedd

Please sign in to comment.