Finalize gmxapi 0.1
[gromacs.git] / python_packaging / src / gmxapi / version.py
blob2f1582b7cc5277f336eebc0d8b351314a2842e83
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 """
36 Provide version and release information.
38 Attributes:
39 major (int): gmxapi major version number.
40 minor (int): gmxapi minor version number.
41 patch (int): gmxapi patch level number.
42 release (bool): True if imported gmx module is an officially tagged release, else False.
44 """
45 import warnings
47 __version__ = "0.1.0"
49 # TODO: (pending infrastructure and further discussion) Configure with CMake.
50 # __version__ = "@PROJECT_VERSION@"
51 # major = @PROJECT_VERSION_MAJOR@
52 # minor = @PROJECT_VERSION_MINOR@
53 # patch = @PROJECT_VERSION_PATCH@
55 from gmxapi.exceptions import FeatureNotAvailableError
57 major = 0
58 minor = 1
59 patch = 0
61 # Note: this is not automatically updated. See RELEASE.txt and https://github.com/kassonlab/gmxapi/issues/152
62 release = True
64 # Features added since the initial gmxapi prototype, targeted for version 0.1.
65 _named_features_0_0 = ['fr1', 'fr3', 'fr7', 'fr15']
66 # Features named since the finalization of the 0.1 specification with GROMACS 2020.
67 _named_features_0_1 = []
68 # Named features describe functionality or behavior introduced since the last
69 # major release, and should be described in gmxapi documentation or issue
70 # tracking system. Note that, as features become part of the specification,
71 # conditionals depending on them should be phased out of the package source. At
72 # major releases, the named feature list should be reset to empty. Optionally,
73 # we could raise a DeprecationWarning for calls to has_feature() for features
74 # that have become part of the specification, at least for a few minor release or
75 # a few years, to avoid introducing errors to client code.
77 # Bugs and bug fixes may be indicated with names consisting of tracked issue URLs.
79 # Features consisting of 'fr' and a numeric suffix are the functional requirements
80 # described in roadmap.rst, as described at https://redmine.gromacs.org/issues/2893
82 # fr1: wrap importable Python code.
83 # fr2: output proxy establishes execution dependency (superseded by fr3)
84 # fr3: output proxy can be used as input
85 # fr4: dimensionality and typing of named data causes generation of correct work topologies
86 # fr5: explicit many-to-one or many-to-many data flow
87 # fr7: Python bindings for launching simulations
88 # fr8: gmx.mdrun understands ensemble work
89 # fr9: MD plugins
90 # fr10: fused operations for use in looping constructs
91 # fr11: Python access to TPR file contents
92 # fr12: Simulation checkpoint handling
93 # fr13: ``run`` module function simplifies user experience
94 # fr14: Easy access to GROMACS run time parameters
95 # fr15: Simulation input modification
96 # fr16: Create simulation input from simulation output
97 # fr17: Prepare simulation input from multiple sources
98 # fr18: GROMACS CLI tools receive improved Python-level support over generic commandline_operations
99 # fr19: GROMACS CLI tools receive improved C++-level support over generic commandline_operations
100 # fr20: Python bindings use C++ API for expressing user interface
101 # fr21 User insulated from filesystem paths
102 # fr22 MPI-based ensemble management from Python
103 # fr23 Ensemble simulations can themselves use MPI
106 def api_is_at_least(major_version, minor_version=0, patch_version=0):
107 """Allow client to check whether installed module supports the requested API level.
109 Arguments:
110 major_version (int): gmxapi major version number.
111 minor_version (int): optional gmxapi minor version number (default: 0).
112 patch_version (int): optional gmxapi patch level number (default: 0).
114 Returns:
115 True if installed gmx package is greater than or equal to the input level
117 Note that if gmxapi.version.release is False, the package is not guaranteed to correctly or
118 fully support the reported API level.
120 if not isinstance(major_version, int) or not isinstance(minor_version, int) or not isinstance(patch_version, int):
121 raise TypeError('Version levels must be provided as integers.')
122 if major > major_version:
123 return True
124 elif major == major_version and minor >= minor_version:
125 return True
126 elif major == major_version and minor == minor_version and patch >= patch_version:
127 return True
128 else:
129 return False
132 def has_feature(name='', enable_exception=False):
133 """Query whether a named feature is available in the installed package.
135 Between updates to the API specification, new features or experimental aspects
136 may be introduced into the package and need to be detectable. This function
137 is intended to facilitate code testing and resolving differences between
138 development branches. Users should refer to the documentation for the package
139 modules and API level.
141 The primary use case is, in conjunction with api_is_at_least(), to allow
142 client code to robustly identify expected behavior and API support through
143 conditional execution and branching. Note that behavior is strongly
144 specified by the API major version number. Features that have become part of
145 the specification and bug-fixes referring to previous major versions should
146 not be checked with *has_feature()*. Using *has_feature()* with old feature
147 names will produce a DeprecationWarning for at least one major version, and
148 client code should be updated to avoid logic errors in future versions.
150 For convenience, setting *enable_exception=True* causes the function to
151 instead raise a gmxapi.exceptions.FeatureNotAvailableError for unrecognized feature names.
152 This allows extension code to cleanly produce a gmxapi exception instead of
153 first performing a boolean check. Also, some code may be unexecutable for
154 more than one reason, and sometimes it is cleaner to catch all
155 gmxapi.exceptions.Error exceptions for a code block, rather than to
156 construct complex conditionals.
158 Returns:
159 True if named feature is recognized by the installed package, else False.
161 Raises:
162 gmxapi.exceptions.FeatureNotAvailableError if `enable_exception == True` and feature is not found.
165 # First, issue a warning if the feature name is subject to removal because
166 # of the history of the API specification.
167 if api_is_at_least(0, 2):
168 # For sufficiently advanced API versions, we want to warn that old
169 # feature checks lose meaning and should no longer be checked.
170 # We provide a suggestion with the API version that absorbed their
171 # specification.
172 if name in _named_features_0_0:
173 warnings.warn(
174 'Old feature name. Use `api_is_at_least(0, 1)` instead of `has_feature({})`.'.format(name),
175 category=DeprecationWarning
178 # Check whether the feature is listed in the API specification amendments.
179 if name in _named_features_0_0 + _named_features_0_1:
180 return True
181 else:
182 if enable_exception:
183 raise FeatureNotAvailableError('Feature {} not available.'.format(str(name)))
184 return False