Skip to content

Commit

Permalink
MAINT: Switch to using setuptools_scm for versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-will authored and ColmTalbot committed Sep 5, 2022
1 parent 9c89194 commit df9acd1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 52 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ omit =
test/integration/example_test.py
test/integration/noise_realisation_test.py
test/integration/other_test.py
bilby/_version.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ MANIFEST
*.ipynb_checkpoints
outdir/*
.idea/*
bilby/_version.py
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion bilby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,):
Expand Down
10 changes: 2 additions & 8 deletions bilby/core/utils/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
from pathlib import Path
import sys

Expand Down Expand Up @@ -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():
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 0 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

from setuptools import setup
import subprocess
import sys
import os

Expand All @@ -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__))
Expand All @@ -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(
Expand All @@ -86,7 +45,6 @@ def readfile(filename):
author="Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot",
author_email="[email protected]",
license="MIT",
version=VERSION,
packages=[
"bilby",
"bilby.bilby_mcmc",
Expand All @@ -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(),
Expand Down

0 comments on commit df9acd1

Please sign in to comment.