Skip to content

Commit

Permalink
Merge pull request #42 from jennyfothergill/add/git-version-tracking
Browse files Browse the repository at this point in the history
Add version tracking through git
  • Loading branch information
jennyfothergill committed May 5, 2022
2 parents 6c012a1 + eddeb3d commit f4c844b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# When using setuptools_scm don't track __version__.py
__version__.py

# scratch dir
scratch

Expand Down
9 changes: 8 additions & 1 deletion grits/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""GRiTS: A coarse-grain toolkit using chemical grammars."""
from importlib.metadata import PackageNotFoundError, version

from . import utils
from .__version__ import __version__
from .coarsegrain import Bead, CG_Compound, CG_System
from .finegrain import backmap

try:
__version__ = version("grits")
except PackageNotFoundError:
# package is not installed
pass

__all__ = [
"__version__",
"CG_Compound",
Expand Down
2 changes: 0 additions & 2 deletions grits/__version__.py

This file was deleted.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "grits/__version__.py"
94 changes: 22 additions & 72 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,109 +1,59 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from codecs import open
from os import path

# Example copied with love from:
# https://github.com/kennethreitz/setup.py/blob/master/setup.py

# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine

import io
import os
import sys
from shutil import rmtree

from setuptools import Command, find_packages, setup
from setuptools import find_packages, setup

# Package meta-data.
NAME = "grits"
DESCRIPTION = "A toolkit for working with coarse-grained systems"
URL = "https://github.com/cmelab/grits"
EMAIL = "[email protected]"
AUTHOR = "Jenny Fothergill"
REQUIRES_PYTHON = ">=3.7.0"
REQUIRES_PYTHON = ">=3.8"

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

# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
# If you do change the License, remember to change the Trove Classifier!

here = os.path.abspath(os.path.dirname(__file__))

# Load the package's __version__.py module as a dictionary.
about = {}
with open(os.path.join(here, NAME, "__version__.py")) as f:
exec(f.read(), about)


class UploadCommand(Command):
"""Support setup.py upload."""

description = "Build and publish the package."
user_options = []
here = path.abspath(path.dirname(__file__))

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

def initialize_options(self):
pass

def finalize_options(self):
pass
def myversion():
from setuptools_scm.version import get_local_dirty_tag

def run(self):
try:
self.status("Removing previous builds…")
rmtree(os.path.join(here, "dist"))
except OSError:
pass
def clean_scheme(version):
return get_local_dirty_tag(version) if version.dirty else "+clean"

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

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

self.status("Pushing git tags…")
os.system(f"git tag v{about['__version__']}")
os.system("git push --tags")

sys.exit()


# Where the magic happens:
setup(
name=NAME,
version=about["__version__"],
description=DESCRIPTION,
use_scm_version=myversion,
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type="text/markdown",
url=URL,
license="GPLv3",
project_urls={
"Bug Tracker": f"{URL}/issues",
},
python_requires=REQUIRES_PYTHON,
packages=find_packages(exclude=("tests", "docs", "examples")),
# If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'],
# entry_points={
# 'console_scripts': ['mycli=mymodule:cli'],
# },
package_data={"grits": ["compounds/*"]},
install_requires=REQUIRED,
include_package_data=True,
license="MIT",
classifiers=[
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3.8",
],
# $ setup.py publish support.
cmdclass={"upload": UploadCommand},
)

0 comments on commit f4c844b

Please sign in to comment.