Skip to content

Commit

Permalink
Add deploy command to setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wookayin committed Jul 22, 2019
1 parent 2a86bfe commit fc70fe2
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from setuptools import setup
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import re
from setuptools import setup, Command

__PATH__ = os.path.abspath(os.path.dirname(__file__))
IS_PY_2 = (sys.version_info[0] <= 2)


Expand All @@ -22,6 +26,56 @@ def read_version():
raise RuntimeError("Unable to find __version__ string")


__version__ = read_version()


# brought from https://github.com/kennethreitz/setup.py
class DeployCommand(Command):
description = 'Build and deploy the package to PyPI.'
user_options = []

def initialize_options(self): pass
def finalize_options(self): pass

@staticmethod
def status(s):
print(s)

def run(self):
import twine # we require twine locally # noqa

assert 'dev' not in __version__, (
"Only non-devel versions are allowed. "
"__version__ == {}".format(__version__))

with os.popen("git status --short") as fp:
git_status = fp.read().strip()
if git_status:
print("Error: git repository is not clean.\n")
os.system("git status --short")
sys.exit(1)

try:
from shutil import rmtree
self.status('Removing previous builds ...')
rmtree(os.path.join(__PATH__, 'dist'))
except OSError:
pass

self.status('Building Source and Wheel (universal) distribution ...')
os.system('{0} setup.py sdist'.format(sys.executable))

self.status('Uploading the package to PyPI via Twine ...')
ret = os.system('twine upload dist/*')
if ret != 0:
sys.exit(ret)

self.status('Creating git tags ...')
os.system('git tag v{0}'.format(read_version()))
os.system('git tag --list')
sys.exit()


install_requires = [
'six>=1.7',
'nvidia-ml-py>=7.352.0' if IS_PY_2 else 'nvidia-ml-py3>=7.352.0',
Expand All @@ -31,12 +85,12 @@ def read_version():

tests_requires = [
'mock>=2.0.0',
'pytest',
'pytest<5.0',
]

setup(
name='gpustat',
version=read_version(),
version=__version__,
license='MIT',
description='An utility to monitor NVIDIA GPU status and usage',
long_description=read_readme(),
Expand All @@ -62,6 +116,9 @@ def read_version():
entry_points={
'console_scripts': ['gpustat=gpustat:main'],
},
cmdclass={
'deploy': DeployCommand,
},
include_package_data=True,
zip_safe=False,
)

0 comments on commit fc70fe2

Please sign in to comment.