Normalize usage of GMXTOOLCHAINDIR in gmxapi setup.py
authorM. Eric Irrgang <ericirrgang@gmail.com>
Thu, 12 Sep 2019 15:59:58 +0000 (18:59 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 13 Sep 2019 08:35:04 +0000 (10:35 +0200)
GMXRC references the tool chain just by its directory using the
environment variable GMXTOOLCHAINDIR. Assuming that the toolchain
directory name has the same suffix as the toolchain file, it is
sufficient and more consistent for the gmxapi setup.py to use
GMXTOOLCHAINDIR as its hint. Also, doing so allows additional
convenience to users who have already sourced their GMXRC.

Change-Id: I433cdb1215e5fcb1ae893e2f29cb23c4c59f7727

python_packaging/docker/ci.dockerfile
python_packaging/src/setup.py

index f7e30bac751990d07af2c802391b6b004d9f4d80..1751907f11f65a37d5240144822c33d0cf7f8702 100644 (file)
@@ -68,7 +68,7 @@ ADD --chown=testing:testing src/gmxapi /home/testing/gmxapi/src/gmxapi
 # have installed the dependencies.
 RUN . $VENV/bin/activate && \
     (cd $HOME/gmxapi/src && \
-     GROMACS_TOOLCHAIN=/usr/local/gromacs/share/cmake/gromacs/gromacs-toolchain.cmake \
+     GMXTOOLCHAINDIR=/usr/local/gromacs/share/cmake/gromacs \
       pip install --no-cache-dir --no-deps --no-index --no-build-isolation . \
     )
 
index bb837fb6c4d7a2935ca0a79b7a998203c291b23d..4f354669774781a10a42decac015636611b00b2f 100644 (file)
@@ -56,33 +56,38 @@ import cmake
 
 usage = """
 The `gmxapi` package requires an existing GROMACS installation, version 2020 or higher.
-To specify the GROMACS installation to use, provide a GROMACS_TOOLCHAIN
+To specify the GROMACS installation to use, provide a GMXTOOLCHAINDIR
 environment variable when running setup.py or `pip`.
 
 Example:
+    GMXTOOLCHAINDIR=/path/to/gromacs/share/cmake/gromacs pip install gmxapi
 
-    GROMACS_TOOLCHAIN=/path/to/gromacs/share/cmake/gromacs/gromacs-toolchain.cmake pip install gmxapi
+If you have multiple builds of GROMACS, distinguished by a suffix `$SUFFIX`, the
+tool chain directory will use that suffix.
+
+Example:
+    GMXTOOLCHAINDIR=/path/to/gromacs/share/cmake/gromacs$SUFFIX pip install gmxapi
 
 In the example, `gmxapi` is downloaded automatically from pypi.org. You can
 replace `gmxapi` with a local directory or archive file to build from a source
 distribution.
 
-setup.py will use the location of the GROMACS_TOOLCHAIN file to locate the
+setup.py will use the location of GMXTOOLCHAINDIR to locate the
 gmxapi library configured during GROMACS installation. Alternatively, if
 gmxapi_DIR is provided, or if GMXRC has been "sourced", the toolchain file
 location may be deduced. Note, though, that if multiple GROMACS installations
 exist in the same location (with different suffixes) only the first one will be
-used when guessing a toolchain because setup.py does not know which corresponds
+used when guessing a toolchain, because setup.py does not know which corresponds
 to the gmxapi support library.
 
-If specifying GROMACS_TOOLCHAIN and gmxapi_DIR, the tool chain file must be 
+If specifying GMXTOOLCHAINDIR and gmxapi_DIR, the tool chain directory must be 
 located within a subdirectory of gmxapi_DIR.
 
 NOTE TO OS X USERS:
 Refer to https://redmine.gromacs.org/issues/3085 for the status of a bug with
 the toolchain file on OS X. Until the bug is resolved, OS X users are advised
 to manually specify (via the CXX environment variable) the C++ compiler used
-when building GROMACS, and to set gmxapi_DIR instead of GROMACS_TOOLCHAIN.
+when building GROMACS, and to set gmxapi_DIR instead of GMXTOOLCHAINDIR.
 
 Example:
 
@@ -97,7 +102,7 @@ class GmxapiInstallError(Exception):
     """Error processing setup.py for gmxapi Python package."""
 
 
-gmx_toolchain = os.getenv('GROMACS_TOOLCHAIN')
+gmx_toolchain_dir = os.getenv('GMXTOOLCHAINDIR')
 gmxapi_DIR = os.getenv('gmxapi_DIR')
 if gmxapi_DIR is None:
     # Infer from GMXRC exports, if available.
@@ -109,22 +114,21 @@ def _find_first_gromacs_suffix(directory):
         if entry.startswith('gromacs'):
             return entry.strip('gromacs')
 
-if gmx_toolchain is None:
+if gmx_toolchain_dir is None:
     # Try to guess from standard GMXRC environment variables.
     if gmxapi_DIR is not None:
         if os.path.exists(gmxapi_DIR) and os.path.isdir(gmxapi_DIR):
             share_cmake = os.path.join(gmxapi_DIR, 'share', 'cmake')
             suffix = _find_first_gromacs_suffix(share_cmake)
             if suffix is not None:
-                gmx_toolchain = os.path.join(share_cmake,
-                                             'gromacs' + suffix,
-                                             'gromacs-toolchain' + suffix + '.cmake')
+                gmx_toolchain_dir = os.path.join(share_cmake, 'gromacs' + suffix)
 
-if gmx_toolchain is None:
+if gmx_toolchain_dir is None:
     print(usage)
-    raise GmxapiInstallError('Could not configure for GROMACS installation. Provide GROMACS_TOOLCHAIN.')
-else:
-    gmx_toolchain = os.path.abspath(gmx_toolchain)
+    raise GmxapiInstallError('Could not configure for GROMACS installation. Provide GMXTOOLCHAINDIR.')
+
+suffix = os.path.basename(gmx_toolchain_dir).strip('gromacs')
+gmx_toolchain = os.path.abspath(os.path.join(gmx_toolchain_dir, 'gromacs-toolchain' + suffix + '.cmake'))
 
 if gmxapi_DIR is None:
     # Example: given /usr/local/gromacs/share/cmake/gromacs/gromacs-toolchain.cmake,