Skip to content

Commit 333ad4d

Browse files
authored
Merge pull request #221 from ICAMS/resolve_user
Resolve user
2 parents c047df7 + b790bf8 commit 333ad4d

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.6.0
2+
current_version = 1.6.1
33
commit = True
44
tag = True
55

calphy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from calphy.alchemy import Alchemy
55
from calphy.routines import MeltingTemp
66

7-
__version__ = "1.6.0"
7+
__version__ = "1.6.1"
88

99
def addtest(a,b):
1010
return a+b

calphy/input.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from ase.io import read, write
5050
import shutil
5151

52-
__version__ = "1.6.0"
52+
__version__ = "1.6.1"
5353

5454

5555
def _check_equal(val):
@@ -759,16 +759,29 @@ def _validate_all(self) -> "Input":
759759

760760
def fix_paths(self, potlist):
761761
"""
762-
Fix paths for potential files to complete ones
762+
Fix paths for potential files to complete ones.
763+
764+
Also expands environment variables (e.g. ``$USER``, ``${USER}``) and
765+
the home-directory shortcut ``~`` in potential file paths before
766+
resolving them to absolute paths. This allows input files to contain
767+
portable paths such as ``/home/$USER/potentials/Cu.eam``.
763768
"""
764769
fixedpots = []
765770
for pot in potlist:
766771
pcraw = pot.split()
767772
if len(pcraw) >= 3:
768-
filename = pcraw[2]
769-
filename = os.path.abspath(filename)
770-
if os.path.exists(filename):
771-
pcnew = " ".join([*pcraw[:2], filename, *pcraw[3:]])
773+
raw_filename = pcraw[2]
774+
# Expand environment variables ($USER, ${USER}, $HOME, …) and ~
775+
expanded = os.path.expandvars(os.path.expanduser(raw_filename))
776+
abs_filename = os.path.abspath(expanded)
777+
if os.path.exists(abs_filename):
778+
pcnew = " ".join([*pcraw[:2], abs_filename, *pcraw[3:]])
779+
fixedpots.append(pcnew)
780+
elif expanded != raw_filename:
781+
# A variable was expanded even though the file was not found
782+
# at that location yet – still substitute so LAMMPS receives
783+
# the resolved path rather than a literal "$USER" string.
784+
pcnew = " ".join([*pcraw[:2], expanded, *pcraw[3:]])
772785
fixedpots.append(pcnew)
773786
else:
774787
fixedpots.append(pot)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "calphy"
7-
version = "1.6.0"
7+
version = "1.6.1"
88
description = "free energy calculation for python"
99
readme = "README.md"
1010
license = "GPL-3.0-only"

0 commit comments

Comments
 (0)