Skip to content

Commit f4c844b

Browse files
Merge pull request #42 from jennyfothergill/add/git-version-tracking
Add version tracking through git
2 parents 6c012a1 + eddeb3d commit f4c844b

File tree

5 files changed

+39
-75
lines changed

5 files changed

+39
-75
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# When using setuptools_scm don't track __version__.py
2+
__version__.py
3+
14
# scratch dir
25
scratch
36

grits/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"""GRiTS: A coarse-grain toolkit using chemical grammars."""
2+
from importlib.metadata import PackageNotFoundError, version
3+
24
from . import utils
3-
from .__version__ import __version__
45
from .coarsegrain import Bead, CG_Compound, CG_System
56
from .finegrain import backmap
67

8+
try:
9+
__version__ = version("grits")
10+
except PackageNotFoundError:
11+
# package is not installed
12+
pass
13+
714
__all__ = [
815
"__version__",
916
"CG_Compound",

grits/__version__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools_scm]
6+
write_to = "grits/__version__.py"

setup.py

Lines changed: 22 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,59 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
from codecs import open
2+
from os import path
33

4-
# Example copied with love from:
5-
# https://github.com/kennethreitz/setup.py/blob/master/setup.py
6-
7-
# Note: To use the 'upload' functionality of this file, you must:
8-
# $ pip install twine
9-
10-
import io
11-
import os
12-
import sys
13-
from shutil import rmtree
14-
15-
from setuptools import Command, find_packages, setup
4+
from setuptools import find_packages, setup
165

176
# Package meta-data.
187
NAME = "grits"
198
DESCRIPTION = "A toolkit for working with coarse-grained systems"
209
URL = "https://github.com/cmelab/grits"
2110
EMAIL = "jennyfothergill@boisestate.edu"
2211
AUTHOR = "Jenny Fothergill"
23-
REQUIRES_PYTHON = ">=3.7.0"
12+
REQUIRES_PYTHON = ">=3.8"
2413

2514
# What packages are required for this module to be executed?
2615
REQUIRED = ["mbuild", "numpy"]
2716

28-
# The rest you shouldn't have to touch too much :)
29-
# ------------------------------------------------
30-
# Except, perhaps the License and Trove Classifiers!
31-
# If you do change the License, remember to change the Trove Classifier!
32-
33-
here = os.path.abspath(os.path.dirname(__file__))
34-
35-
# Load the package's __version__.py module as a dictionary.
36-
about = {}
37-
with open(os.path.join(here, NAME, "__version__.py")) as f:
38-
exec(f.read(), about)
39-
40-
41-
class UploadCommand(Command):
42-
"""Support setup.py upload."""
4317

44-
description = "Build and publish the package."
45-
user_options = []
18+
here = path.abspath(path.dirname(__file__))
4619

47-
@staticmethod
48-
def status(s):
49-
"""Prints things in bold."""
50-
print("\033[1m{0}\033[0m".format(s))
20+
with open("README.md", "r", encoding="utf-8") as f:
21+
long_description = f.read()
5122

52-
def initialize_options(self):
53-
pass
5423

55-
def finalize_options(self):
56-
pass
24+
def myversion():
25+
from setuptools_scm.version import get_local_dirty_tag
5726

58-
def run(self):
59-
try:
60-
self.status("Removing previous builds…")
61-
rmtree(os.path.join(here, "dist"))
62-
except OSError:
63-
pass
27+
def clean_scheme(version):
28+
return get_local_dirty_tag(version) if version.dirty else "+clean"
6429

65-
self.status("Building Source and Wheel (universal) distribution…")
66-
os.system(f"{sys.executable} setup.py sdist bdist_wheel --universal")
30+
return {"local_scheme": clean_scheme}
6731

68-
self.status("Uploading the package to PyPi via Twine…")
69-
os.system("twine upload dist/*")
7032

71-
self.status("Pushing git tags…")
72-
os.system(f"git tag v{about['__version__']}")
73-
os.system("git push --tags")
74-
75-
sys.exit()
76-
77-
78-
# Where the magic happens:
7933
setup(
8034
name=NAME,
81-
version=about["__version__"],
82-
description=DESCRIPTION,
35+
use_scm_version=myversion,
8336
author=AUTHOR,
8437
author_email=EMAIL,
85-
python_requires=REQUIRES_PYTHON,
38+
description=DESCRIPTION,
39+
long_description=long_description,
40+
long_description_content_type="text/markdown",
8641
url=URL,
42+
license="GPLv3",
43+
project_urls={
44+
"Bug Tracker": f"{URL}/issues",
45+
},
46+
python_requires=REQUIRES_PYTHON,
8747
packages=find_packages(exclude=("tests", "docs", "examples")),
88-
# If your package is a single module, use this instead of 'packages':
89-
# py_modules=['mypackage'],
90-
# entry_points={
91-
# 'console_scripts': ['mycli=mymodule:cli'],
92-
# },
9348
package_data={"grits": ["compounds/*"]},
9449
install_requires=REQUIRED,
9550
include_package_data=True,
96-
license="MIT",
9751
classifiers=[
9852
# Trove classifiers
9953
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
10054
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
10155
"Programming Language :: Python",
10256
"Programming Language :: Python :: 3",
103-
"Programming Language :: Python :: 3.7",
104-
"Programming Language :: Python :: Implementation :: CPython",
105-
"Programming Language :: Python :: Implementation :: PyPy",
57+
"Programming Language :: Python :: 3.8",
10658
],
107-
# $ setup.py publish support.
108-
cmdclass={"upload": UploadCommand},
10959
)

0 commit comments

Comments
 (0)