Skip to content

Commit ca6402f

Browse files
committed
change path hacking to opt-in & have that turned on in pixi run ui, off in self-tests; fix print code that generated a warning
1 parent a5fe752 commit ca6402f

File tree

10 files changed

+459
-47
lines changed

10 files changed

+459
-47
lines changed

GSASII/GSASII.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#
44
# This can be used when GSAS-II is installed, but why bother as the command:
55
# python -c "from GSASII.GSASIIGUI import main; main()"
6-
# will do just as well.
6+
# will do just as well.
7+
# Even better:
8+
# GSASII_NOPATHHACKING="true" python -c "from GSASII.GSASIIGUI import main; main()"
9+
710
import os
811
import sys
912
import importlib
@@ -13,10 +16,8 @@
1316
pkginfo = None
1417

1518
if __name__ == '__main__':
16-
if pkginfo is None: # fixup path if GSASII not installed into Python
17-
os.environ["GSASII_YOLO_PATH"] = "True"
19+
if pkginfo is None: # hack path if GSASII not installed into Python
20+
print('GSAS-II not installed in Python; Hacking sys.path')
1821
sys.path.insert(0,os.path.dirname(os.path.dirname(__file__)))
1922
from GSASII.GSASIIGUI import main
20-
if pkginfo is None: # fixup path if GSASII not installed into Python
21-
print('GSAS-II not installed in Python: Hacking sys.path')
2223
main()

GSASII/GSASIIstrIO.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def PrintBlength(BLtables,wave,pFile):
292292
for El in BLtables:
293293
if 'Q' not in El:
294294
BP,BPP = G2el.BlenResCW([El,],BLtables,wave)
295-
Elstr += ' %8s'%(El)
296-
FPstr += ' %8.3f'%(BP)
297-
FPPstr += ' %8.3f'%(BPP)
295+
Elstr += f' {El:>8}'
296+
FPstr += f' {BP[0]:8.3f}'
297+
FPPstr += f' {BPP[0]:8.3f}'
298298
pFile.write(Elstr+'\n')
299299
pFile.write(FPstr+'\n')
300300
pFile.write(FPPstr+'\n')

GSASII/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def no_path_hacking(event_name, args):
2323
raise PathHackingException(lines[-2].strip())
2424
return no_path_hacking
2525

26-
if not os.environ.get("GSASII_YOLO_PATH", ''):
26+
if os.environ.get("GSASII_NOPATHHACKING", ''):
2727
sys.addaudithook(make_path_watcher())
2828

2929
del sys, make_path_watcher, os

GSASII/git_verinfo.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# git_verinfo.py - GSAS-II version info from git
3-
# Do not edit, generated by 'install/tag-version.py' command
4-
# Created 2025-01-03 12:00:34.178846-06:00
3+
# Do not edit, generated by 'save-versions.py' script
4+
# Created 2025-02-06 12:06:41.159839-06:00
55

6-
git_version = '45480f29835216e3376b2941edfbdba4de1f22dc'
7-
git_tags = ['5802']
8-
git_prevtaggedversion = '3872eefc9bf830b08491e55f2f1e51562a35b20e'
9-
git_prevtags = ['5801']
6+
git_version = 'a5fe752531cf6ff9ce941a93e89bcdf01f9c6ce9'
7+
git_tags = []
8+
git_prevtaggedversion = '45480f29835216e3376b2941edfbdba4de1f22dc'
9+
git_prevtags = ['5802']
10+
git_versiontag = '5.0.1'

GSASII/install/save-versions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@
5656
fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} script\n')
5757
fp.write(f'# Created {now}\n\n')
5858
fp.write(f'git_version = {commit0!r}\n')
59-
if tags:
59+
if tags0:
6060
fp.write(f'git_tags = {tags0}\n')
6161
else:
6262
fp.write('git_tags = []\n')
6363
fp.write(f'git_prevtaggedversion = {commitm1!r}\n')
64-
fp.write(f'git_prevtags = {tagsm1}\n')
64+
if tagsm1:
65+
fp.write(f'git_prevtags = {tagsm1}\n')
66+
else:
67+
fp.write(f'git_prevtags = []\n')
6568
# get the latest version number
6669
releases = [i for i in g2repo.tags if '.' in i.name]
6770
majors = [i.name.split('.')[0] for i in releases]

pixi/pixi.lock

Lines changed: 417 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi/pixi.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ build-and-go-win ={ depends_on= ["install-win", "ui"]}
2929

3030
test = {cmd = "python -m pytest ../" }
3131

32-
ui = "python -m GSASII"
32+
ui = 'GSASII_NOPATHHACKING="true" python -m GSASII'
3333

3434

3535
[dependencies]
@@ -58,6 +58,17 @@ clang = ">=17.0.6,<20"
5858
pycifrw = ">=4.4.0"
5959
pytest = ">=8.3.4,<9"
6060
gitpython = ">=3.1.44,<4"
61+
ipython = ">=8.32.0,<9"
62+
63+
# The list above contains a number of items that are needed only for
64+
# installation/development, not runtime:
65+
# cython, meson-python, gitpython
66+
# This is also likely true for these, but I am less sure:
67+
# tomli, wheel, python-build, compilers, clang, ninja, pkg-config, pyproject-metadata
68+
# Also, users probably do not need pytest or ipython, but these might be included only when
69+
# install-editable is used.
70+
#
71+
# TODO? separate runtime & build/install dependencies
6172

6273
[feature.py311.dependencies]
6374
python = "<3.12,>=3.11"

tests/test_lattice.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import sys
66
import numpy as np
77

8-
import importlib # fixup path if GSASII not installed into Python
9-
if importlib.util.find_spec('GSASII') is None:
10-
print('Beware: Path hacking in progress')
11-
os.environ["GSASII_YOLO_PATH"] = "True"
8+
import importlib
9+
if importlib.util.find_spec('GSASII') is None: # hack path if GSASII not installed into Python
1210
home = os.path.dirname(__file__)
1311
sys.path.append(os.path.dirname(home))
1412
import GSASII.GSASIIspc as G2spc

tests/test_scripting.py renamed to tests/test_scriptref.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,21 @@
88
home = os.path.dirname(__file__)
99
work = tempfile.gettempdir()
1010

11-
skip = False
12-
import importlib.util # fixup path if GSASII not installed into Python
11+
import importlib.util
1312
G2loc = None
1413
try:
1514
G2loc = importlib.util.find_spec('GSASII.GSASIIscriptable')
1615
except ModuleNotFoundError:
1716
print('ModuleNotFound for GSASII.GSASIIscriptable')
1817

19-
if G2loc is None:
20-
print('GSAS-II not installed in Python: Hacking sys.path')
21-
os.environ["GSASII_YOLO_PATH"] = "True"
18+
if G2loc is None: # fixup path if GSASII not installed into Python
19+
print('GSAS-II not installed in Python; Hacking sys.path')
2220
sys.path.append(os.path.dirname(home))
23-
else:
24-
# TODO: figure out why this fails with a "path hacking" error from
25-
# inside the testing suite; Would prefer to skip only from inside pytest
26-
if "pytest" in sys.modules:
27-
print("unable to run inside testing suite?!")
28-
skip = True
2921

3022
import GSASII
3123
import GSASII.GSASIIscriptable as G2sc
3224

3325
def test_refine():
34-
if skip:
35-
print('unable to test from pytest')
36-
return
37-
# this does not catch the PathHackingException when run from pytest
38-
try:
39-
refinetest()
40-
except GSASII.PathHackingException:
41-
print('PathHackingException')
42-
43-
def refinetest():
4426
def testR(msg,w1,w2):
4527
print(f"*** {msg}: Rwp(h1)={h1.residuals['wR']:.5f}, Rwp(h2)={h2.residuals['wR']:.5f}")
4628
npt.assert_allclose([h1.residuals['wR'],h2.residuals['wR']],

tests/test_spg.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
import testinp.spctestinp as spctestinp
1010
import testinp.sgtbxtestinp as sgtbxtestinp
1111

12-
import importlib # fixup path if GSASII not installed into Python
13-
if importlib.util.find_spec('GSASII') is None:
14-
print('Beware: Path hacking in progress')
15-
os.environ["GSASII_YOLO_PATH"] = "True"
12+
import importlib
13+
if importlib.util.find_spec('GSASII') is None: # hack path if GSASII not installed into Python
1614
home = os.path.dirname(__file__)
1715
sys.path.append(os.path.dirname(home))
16+
1817
from GSASII.GSASIIspc import MoveToUnitCell, SpcGroup, SytSym
1918

2019
# self-test materials follow. Requires files in directory testinp

0 commit comments

Comments
 (0)