diff --git a/.coveragerc b/.coveragerc index c051155b5..7d64384d9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,3 +3,4 @@ omit = test/integration/example_test.py test/integration/noise_realisation_test.py test/integration/other_test.py + bilby/_version.py diff --git a/.gitignore b/.gitignore index 887178188..48e4c01a1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ MANIFEST *.ipynb_checkpoints outdir/* .idea/* +bilby/_version.py diff --git a/MANIFEST.in b/MANIFEST.in index d6ac4a644..331a31917 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,4 +5,5 @@ include gw_requirements.txt include mcmc_requirements.txt include optional_requirements.txt include sampler_requirements.txt +include bilby/_version.py recursive-include test *.py *.prior diff --git a/bilby/__init__.py b/bilby/__init__.py index 04a29e1bc..092f05a1a 100644 --- a/bilby/__init__.py +++ b/bilby/__init__.py @@ -24,7 +24,10 @@ from .core.sampler import run_sampler from .core.likelihood import Likelihood -__version__ = utils.get_version_information() +try: + from ._version import version as __version__ +except ModuleNotFoundError: # development mode + __version__ = 'unknown' if sys.version_info < (3,): diff --git a/bilby/core/utils/log.py b/bilby/core/utils/log.py index d9db7581c..dd9bcfd95 100644 --- a/bilby/core/utils/log.py +++ b/bilby/core/utils/log.py @@ -1,5 +1,4 @@ import logging -import os from pathlib import Path import sys @@ -60,13 +59,8 @@ def setup_logger(outdir='.', label=None, log_level='INFO', print_version=False): def get_version_information(): - version_file = os.path.join( - os.path.dirname(os.path.dirname(os.path.dirname(__file__))), '.version') - try: - with open(version_file, 'r') as f: - return f.readline().rstrip() - except EnvironmentError: - print("No version information file '.version' found") + from bilby import __version__ + return __version__ def loaded_modules_dict(): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..41b21bf94 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = [ + "setuptools>=42", + "setuptools_scm[toml]>=3.4.3", + "wheel", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "bilby/_version.py" \ No newline at end of file diff --git a/setup.py b/setup.py index 57da57e2c..2d55f5d54 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ #!/usr/bin/env python from setuptools import setup -import subprocess import sys import os @@ -10,44 +9,6 @@ sys.exit("Python < 3.8 is not supported, aborting setup") -def write_version_file(version): - """Writes a file with version information to be used at run time - - Parameters - ---------- - version: str - A string containing the current version information - - Returns - ------- - version_file: str - A path to the version file - - """ - try: - git_log = subprocess.check_output( - ["git", "log", "-1", "--pretty=%h %ai"] - ).decode("utf-8") - git_diff = ( - subprocess.check_output(["git", "diff", "."]) - + subprocess.check_output(["git", "diff", "--cached", "."]) - ).decode("utf-8") - if git_diff == "": - git_status = "(CLEAN) " + git_log - else: - git_status = "(UNCLEAN) " + git_log - except Exception as e: - print("Unable to obtain git version information, exception: {}".format(e)) - git_status = "release" - - version_file = ".version" - if os.path.isfile(version_file) is False: - with open("bilby/" + version_file, "w+") as f: - f.write("{}: {}".format(version, git_status)) - - return version_file - - def get_long_description(): """Finds the README and reads in the description""" here = os.path.abspath(os.path.dirname(__file__)) @@ -73,8 +34,6 @@ def readfile(filename): return filecontents -VERSION = '1.2.0' -version_file = write_version_file(VERSION) long_description = get_long_description() setup( @@ -86,7 +45,6 @@ def readfile(filename): author="Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot", author_email="paul.lasky@monash.edu", license="MIT", - version=VERSION, packages=[ "bilby", "bilby.bilby_mcmc", @@ -107,7 +65,6 @@ def readfile(filename): "bilby.gw": ["prior_files/*"], "bilby.gw.detector": ["noise_curves/*.txt", "detectors/*"], "bilby.gw.eos": ["eos_tables/*.dat"], - "bilby": [version_file], }, python_requires=">=3.8", install_requires=get_requirements(),