-
Notifications
You must be signed in to change notification settings - Fork 45
Use setuptools_scm instead of custom version determination code #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
598b2cf
use setuptools_scm
bnavigator c0563fb
avoid slycot.version being the version function
bnavigator d51cbcf
Apply suggestions from code review
bnavigator 1da4cb8
setuptools_scm writes slycot/version.py
bnavigator c785268
move metadata to pyproject.toml
bnavigator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| source = slycot | ||
| omit = | ||
| */tests/* | ||
| */version.py | ||
|
|
||
|
|
||
| # please do not add any sections after this block | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "setuptools", | ||
bnavigator marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "setuptools_scm>=6.3", | ||
| "wheel", | ||
| "scikit-build>=0.14.1", | ||
| "cmake", | ||
| "numpy!=1.23.0"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [tool.setuptools_scm] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| # run the tests with compiled and installed package | ||
| addopts = "--pyargs slycot" | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,17 +12,18 @@ | |
| import subprocess | ||
| import re | ||
| import platform | ||
| try: | ||
| import configparser | ||
| except ImportError: | ||
| import ConfigParser as configparser | ||
|
|
||
| try: | ||
| from skbuild import setup | ||
| from skbuild.command.sdist import sdist | ||
| except ImportError: | ||
| raise ImportError('scikit-build must be installed before running setup.py') | ||
|
|
||
| try: | ||
| from setuptools_scm import get_version | ||
| except ImportError: | ||
| raise ImportError('setuptools_scm must be installed before running setup.py') | ||
|
|
||
| DOCLINES = __doc__.split("\n") | ||
|
|
||
| CLASSIFIERS = """\ | ||
|
|
@@ -46,144 +47,13 @@ | |
| Operating System :: MacOS | ||
| """ | ||
|
|
||
| # defaults | ||
| ISRELEASED = True | ||
| # assume a version set by conda, next update with git, | ||
| # otherwise count on default | ||
| VERSION = 'Unknown' | ||
|
|
||
|
|
||
| class GitError(RuntimeError): | ||
| """Exception for git errors occuring in in git_version""" | ||
| pass | ||
|
|
||
|
|
||
| def git_version(srcdir=None): | ||
| """Return the git version, revision and cycle | ||
|
|
||
| Uses rev-parse to get the revision tag to get the version number from the | ||
| latest tag and detects (approximate) revision cycles | ||
|
|
||
| """ | ||
| def _minimal_ext_cmd(cmd, srcdir): | ||
| # construct minimal environment | ||
| env = {} | ||
| for k in ['SYSTEMROOT', 'PATH']: | ||
| v = os.environ.get(k) | ||
| if v is not None: | ||
| env[k] = v | ||
| # LANGUAGE is used on win32 | ||
| env['LANGUAGE'] = 'C' | ||
| env['LANG'] = 'C' | ||
| env['LC_ALL'] = 'C' | ||
| proc = subprocess.Popen( | ||
| cmd, | ||
| cwd=srcdir, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| env=env) | ||
| out, err = proc.communicate() | ||
| if proc.returncode: | ||
| errmsg = err.decode('ascii', errors='ignore').strip() | ||
| raise GitError("git err; return code %d, error message:\n '%s'" | ||
| % (proc.returncode, errmsg)) | ||
| return out | ||
|
|
||
| try: | ||
| GIT_VERSION = VERSION | ||
| GIT_REVISION = 'Unknown' | ||
| GIT_CYCLE = 0 | ||
| out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'], srcdir) | ||
| GIT_REVISION = out.strip().decode('ascii') | ||
| out = _minimal_ext_cmd(['git', 'tag'], srcdir) | ||
| GIT_VERSION = out.strip().decode('ascii').split('\n')[-1][1:] | ||
| out = _minimal_ext_cmd(['git', 'describe', '--tags', | ||
| '--long', '--always'], srcdir) | ||
| try: | ||
| # don't get a good description with shallow clones | ||
| GIT_CYCLE = out.strip().decode('ascii').split('-')[1] | ||
| except IndexError: | ||
| pass | ||
| except OSError: | ||
| pass | ||
|
|
||
| return GIT_VERSION, GIT_REVISION, GIT_CYCLE | ||
|
|
||
| # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly | ||
| # update it when the contents of directories change. | ||
| if os.path.exists('MANIFEST'): | ||
| os.remove('MANIFEST') | ||
|
|
||
| # This is a bit hackish: we are setting a global variable so that the main | ||
| # slycot __init__ can detect if it is being loaded by the setup routine, to | ||
| # avoid attempting to load components that aren't built yet. While ugly, it's | ||
| # a lot more robust than what was previously being used. | ||
| builtins.__SLYCOT_SETUP__ = True | ||
|
|
||
|
|
||
| def rewrite_setup_cfg(version, gitrevision, release): | ||
| toreplace = dict(locals()) | ||
| data = ''.join(open('setup.cfg.in', 'r').readlines()).split('@') | ||
| for k, v in toreplace.items(): | ||
| idx = data.index(k) | ||
| data[idx] = v | ||
| cfg = open('setup.cfg', 'w') | ||
| cfg.write(''.join(data)) | ||
| cfg.close() | ||
|
|
||
|
|
||
| def get_version_info(srcdir=None): | ||
| global ISRELEASED | ||
| GIT_CYCLE = 0 | ||
|
|
||
| # Adding the git rev number needs to be done inside write_version_py(), | ||
| # otherwise the import of slycot.version messes up | ||
| # the build under Python 3. | ||
| if os.environ.get('CONDA_BUILD', False): | ||
| FULLVERSION = os.environ.get('PKG_VERSION', '???') | ||
| GIT_REVISION = os.environ.get('GIT_DESCRIBE_HASH', '') | ||
| ISRELEASED = True | ||
| rewrite_setup_cfg(FULLVERSION, GIT_REVISION, 'yes') | ||
| elif os.path.exists('.git'): | ||
| FULLVERSION, GIT_REVISION, GIT_CYCLE = git_version(srcdir) | ||
| ISRELEASED = (GIT_CYCLE == 0) | ||
| rewrite_setup_cfg(FULLVERSION, GIT_REVISION, | ||
| (ISRELEASED and 'yes') or 'no') | ||
| elif os.path.exists('setup.cfg'): | ||
| # valid distribution | ||
| setupcfg = configparser.ConfigParser(allow_no_value=True) | ||
| setupcfg.read('setup.cfg') | ||
|
|
||
| FULLVERSION = setupcfg.get(section='metadata', option='version') | ||
|
|
||
| if FULLVERSION is None: | ||
| FULLVERSION = "Unknown" | ||
|
|
||
| GIT_REVISION = setupcfg.get(section='metadata', option='gitrevision') | ||
|
|
||
| if GIT_REVISION is None: | ||
| GIT_REVISION = "" | ||
|
|
||
| return FULLVERSION, GIT_REVISION | ||
| else: | ||
|
|
||
| # try to find a version number from the dir name | ||
| dname = os.getcwd().split(os.sep)[-1] | ||
|
|
||
| m = re.search(r'[0-9.]+', dname) | ||
| if m: | ||
| FULLVERSION = m.group() | ||
| GIT_REVISION = '' | ||
|
|
||
| else: | ||
| FULLVERSION = VERSION | ||
| GIT_REVISION = "Unknown" | ||
|
|
||
| if not ISRELEASED: | ||
| FULLVERSION += '.' + str(GIT_CYCLE) | ||
|
|
||
| return FULLVERSION, GIT_REVISION | ||
|
|
||
| def check_submodules(): | ||
| """ verify that the submodules are checked out and clean | ||
| use `git submodule update --init`; on failure | ||
|
|
@@ -216,14 +86,12 @@ def setup_package(): | |
| src_path = os.path.dirname(os.path.abspath(__file__)) | ||
| sys.path.insert(0, src_path) | ||
|
|
||
| # Rewrite the version file everytime | ||
| VERSION, gitrevision = get_version_info(src_path) | ||
|
|
||
| metadata = dict( | ||
| name='slycot', | ||
| packages=['slycot', 'slycot.tests'], | ||
| cmake_languages=('C', 'Fortran'), | ||
| version=VERSION, | ||
| use_scm_version=True, | ||
| maintainer="Slycot developers", | ||
| maintainer_email="[email protected]", | ||
| description=DOCLINES[0], | ||
|
|
@@ -234,20 +102,16 @@ def setup_package(): | |
| classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], | ||
| platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], | ||
| cmdclass={"sdist": sdist_checked}, | ||
| cmake_args=['-DSLYCOT_VERSION:STRING=' + VERSION, | ||
| '-DGIT_REVISION:STRING=' + gitrevision, | ||
| '-DISRELEASE:STRING=' + str(ISRELEASED), | ||
| '-DFULL_VERSION=' + VERSION + '.git' + gitrevision[:7]], | ||
| zip_safe=False, | ||
| install_requires=['numpy'], | ||
| install_requires=["numpy", | ||
| "importlib-metadata; python_version < '3.8'"], | ||
| python_requires=">=3.7" | ||
| ) | ||
|
|
||
| try: | ||
| setup(**metadata) | ||
| finally: | ||
| del sys.path[0] | ||
| return | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.