Skip to content

Commit 73dbf12

Browse files
committed
Merge branch 'develop' into update-test-paths
2 parents 8c8da07 + 81abb68 commit 73dbf12

33 files changed

Lines changed: 1053 additions & 504 deletions

nexus/nexus/basisset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def read(self,filepath=None):
154154
#end if
155155
file = TextFile(filepath)
156156
self.read_file(file)
157+
file.close()
157158
#end def read
158159

159160
def read_file(self,file):
@@ -319,7 +320,8 @@ def read(self,filepath,format=None):
319320
#end if
320321
#self.name = split_delims(os.path.split(filepath)[1])[0]
321322
self.name = os.path.split(filepath)[1].split('.')[0]
322-
text = open(filepath,'r').read()
323+
with open(filepath, "r") as f:
324+
text = f.read()
323325
self.read_text(text,format)
324326
#end def read
325327

nexus/nexus/bin/eshdf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import sys
66
from pathlib import Path
77
from optparse import OptionParser
88

9+
if sys.version_info[0:3] < (3, 10, 0):
10+
v = sys.version_info[0:3]
11+
print(
12+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
13+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
14+
"If you already have a higher version installed, ensure that your Python\n"
15+
"environment is properly activated and your $PATH is set correctly."
16+
)
17+
sys.exit(1)
18+
919
# Non-standard Python library imports
1020
import numpy as np
1121

nexus/nexus/bin/nxs-redo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#! /usr/bin/env python3
22

33
import os
4+
import sys
45
from pathlib import Path
56
from optparse import OptionParser
67

8+
if sys.version_info[0:3] < (3, 10, 0):
9+
v = sys.version_info[0:3]
10+
print(
11+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
12+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
13+
"If you already have a higher version installed, ensure that your Python\n"
14+
"environment is properly activated and your $PATH is set correctly."
15+
)
16+
sys.exit(1)
17+
718
# Copied from qmca. Modification must done on qmca first
819
# Locate and import the closely coupled Nexus module
920
search_basepath = Path(__file__).resolve().parent.parent

nexus/nexus/bin/nxs-sim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#! /usr/bin/env python3
22

33
import os
4+
import sys
45
from pathlib import Path
56
from optparse import OptionParser
67

8+
if sys.version_info[0:3] < (3, 10, 0):
9+
v = sys.version_info[0:3]
10+
print(
11+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
12+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
13+
"If you already have a higher version installed, ensure that your Python\n"
14+
"environment is properly activated and your $PATH is set correctly."
15+
)
16+
sys.exit(1)
17+
718
# Copied from qmca. Modification must done on qmca first
819
# Locate and import the closely coupled Nexus module
920
search_basepath = Path(__file__).resolve().parent.parent

nexus/nexus/bin/nxs-test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ for development.
1212

1313
import sys
1414

15+
if sys.version_info[0:3] < (3, 10, 0):
16+
v = sys.version_info[0:3]
17+
print(
18+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
19+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
20+
"If you already have a higher version installed, ensure that your Python\n"
21+
"environment is properly activated and your $PATH is set correctly."
22+
)
23+
sys.exit(1)
24+
1525
try:
1626
import pytest
1727
except ImportError:

nexus/nexus/bin/qdens

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
import gc
44
import os
5+
import sys
56
from pathlib import Path
67
from optparse import OptionParser
78

9+
if sys.version_info[0:3] < (3, 10, 0):
10+
v = sys.version_info[0:3]
11+
print(
12+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
13+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
14+
"If you already have a higher version installed, ensure that your Python\n"
15+
"environment is properly activated and your $PATH is set correctly."
16+
)
17+
sys.exit(1)
18+
819
# Copied from qmca. Modification must done on qmca first
920
# Locate and import the closely coupled Nexus module
1021
search_basepath = Path(__file__).resolve().parent.parent

nexus/nexus/bin/qdens-radial

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
from pathlib import Path
44
from optparse import OptionParser
5+
import sys
6+
7+
if sys.version_info[0:3] < (3, 10, 0):
8+
v = sys.version_info[0:3]
9+
print(
10+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
11+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
12+
"If you already have a higher version installed, ensure that your Python\n"
13+
"environment is properly activated and your $PATH is set correctly."
14+
)
15+
sys.exit(1)
516

617
# Copied from qmca. Modification must done on qmca first
718
# Locate and import the closely coupled Nexus module

nexus/nexus/bin/qmc-fit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import sys
55
import argparse
66
from pathlib import Path
77

8+
if sys.version_info[0:3] < (3, 10, 0):
9+
v = sys.version_info[0:3]
10+
print(
11+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
12+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
13+
"If you already have a higher version installed, ensure that your Python\n"
14+
"environment is properly activated and your $PATH is set correctly."
15+
)
16+
sys.exit(1)
17+
818
try:
919
import numpy as np
1020
except:

nexus/nexus/bin/qmca

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ from pathlib import Path
55
import sys
66
from optparse import OptionParser
77

8+
if sys.version_info[0:3] < (3, 10, 0):
9+
v = sys.version_info[0:3]
10+
print(
11+
f"Your version of Python ({v[0]}.{v[1]}.{v[2]}) is less than the minimum required for Nexus!\n"
12+
"To use Nexus, please install at least Python 3.10.0 or higher!\n\n"
13+
"If you already have a higher version installed, ensure that your Python\n"
14+
"environment is properly activated and your $PATH is set correctly."
15+
)
16+
sys.exit(1)
817

918
# Gold implementation. All the Nexus scripts need to be updated once modified.
1019
# Locate and import the closely coupled Nexus module

nexus/nexus/fileio.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .periodic_table import Elements
3131
from .unit_converter import convert
3232
from . import numpy_extensions as npe
33+
from .utilities import path_string
3334

3435
class TextFile(DevBase):
3536
# interface to mmap files
@@ -39,11 +40,13 @@ def __init__(self,filepath=None):
3940
self.mm = None
4041
self.f = None
4142
if filepath is not None:
43+
filepath = path_string(filepath)
4244
self.open(filepath)
4345
#end if
4446
#end def __init__
4547

4648
def open(self,filepath):
49+
filepath = path_string(filepath)
4750
if not os.path.exists(filepath):
4851
self.error('cannot open non-existent file: {0}'.format(filepath))
4952
#end if
@@ -243,7 +246,8 @@ class StandardFile(DevBase):
243246
def __init__(self,filepath=None):
244247
if filepath is None:
245248
None
246-
elif isinstance(filepath, (str, Path)):
249+
elif isinstance(filepath, str | bytes | Path):
250+
filepath = path_string(filepath)
247251
self.read(filepath)
248252
else:
249253
self.error('unsupported input: {0}'.format(filepath))
@@ -255,7 +259,9 @@ def read(self,filepath):
255259
if not os.path.exists(filepath):
256260
self.error('read failed\nfile does not exist: {0}'.format(filepath))
257261
#end if
258-
self.read_text(open(filepath,'r').read())
262+
with open(filepath, "r") as f:
263+
self.read_text(f.read())
264+
259265
self.check_valid('read failed')
260266
#end def read
261267

@@ -264,7 +270,8 @@ def write(self,filepath=None):
264270
self.check_valid('write failed')
265271
text = self.write_text()
266272
if filepath is not None:
267-
open(filepath,'w').write(text)
273+
with open(filepath, "w") as f:
274+
f.write(text)
268275
#end if
269276
return text
270277
#end def write

0 commit comments

Comments
 (0)