Skip to content

Commit

Permalink
Merge pull request #151 from Ouranosinc/esmpy-guess-esmfmk
Browse files Browse the repository at this point in the history
[ESMpy] Guess esmf.mk locations
Contribution authored by: aulemahal
  • Loading branch information
theurich authored Jul 19, 2023
2 parents fd9570b + 6e48665 commit 6191be3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/addon/esmpy/doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ Installing ESMPy from Source
----------------------------

When installing from source, ESMPy uses `pip <https://pypi.org/project/pip//>`_
to build and install the package. This requires setting an environment variable
pointing to a file named esmf.mk that is generated during an ESMF installation.
The path of this file is:

.. code::
<ESMF_INSTALL_DIR>/lib/lib<g<or>O>/<platform>/esmf.mk
An installation of ESMPy in the default location for Python packages can be done
to build and install the package. An installation of ESMPy in the default location for Python packages can be done
with the following command issued from the top level ESMPy directory (``src/addon/esmpy``):

.. code::
Expand All @@ -93,7 +85,8 @@ To use ESMPy in an external program, import it with:
import esmpy
The environment variable ``ESMFMKFILE`` must be set when using ESMPy.
The environment variable ``ESMFMKFILE`` should be set when using ESMPy. If it is not found, the package will
try to guess a few very common locations, but we recommend correctly setting the variable nonetheless.

.. Note::

Expand Down
14 changes: 12 additions & 2 deletions src/addon/esmpy/src/esmpy/interface/loadESMF.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@
esmfmk = None
try:
esmfmk = os.environ["ESMFMKFILE"]
except:
raise ImportError('The ESMFMKFILE environment variable is not available.')
except KeyError:
# Try to guess with very common paths in normal installs (especially conda)
guesses = [
os.path.join(sys.prefix, 'lib', 'esmf.mk'), # conda build of esmf
os.path.join(sys.prefix, 'Library', 'lib', 'esmf.mk')
]
for path in guesses:
if os.path.isfile(path):
esmfmk = path
break
else:
raise ImportError('The esmf.mk file cannot be found. Pass its path in the ESMFMKFILE environment variable.')

#### INVESTIGATE esmf.mk ######################################################

Expand Down

0 comments on commit 6191be3

Please sign in to comment.