Skip to content

Commit

Permalink
Further setup.py utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarans committed May 22, 2019
1 parent 2e8d736 commit 6d84afa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup, find_packages

sys.path.append('src') # Only needed for this project
from hdx.utilities import CleanMore
from hdx.utilities import CleanCommand, PackageCommand, PublishCommand
from hdx.utilities.loader import load_file_to_str

requirements = ['basicauth',
Expand All @@ -17,7 +17,7 @@
'pyaml',
'six>=1.12.0',
'sshtunnel',
'tabulator>=1.19.0',
'tabulator>=1.20.0',
'typing',
'yamlloader'
]
Expand Down Expand Up @@ -52,5 +52,5 @@
zip_safe=True,
classifiers=classifiers,
install_requires=requirements,
cmdclass={'clean': CleanMore}
cmdclass={'clean': CleanCommand, 'package': PackageCommand, 'publish': PublishCommand},
)
49 changes: 47 additions & 2 deletions src/hdx/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from distutils import log
from distutils.command.clean import clean
Expand All @@ -7,6 +8,9 @@
from uuid import UUID

import six
from setuptools import Command

from hdx.utilities.version import get_utils_version


def raisefrom(exc_type, message, exc):
Expand Down Expand Up @@ -47,18 +51,59 @@ def is_valid_uuid(uuid_to_test, version=4):
return str(uuid_obj) == uuid_to_test


class CleanMore(clean):
class CleanCommand(clean):
"""
Custom implementation of ``clean`` setuptools command."""

def run(self): # pragma: no cover
"""After calling the super class implementation, this function removes
the dist directory if it exists."""
self.all = True # --all by default when cleaning
super(CleanMore, self).run()
super(CleanCommand, self).run()
dir_ = 'dist'
if exists(dir_):
log.info("removing '%s' (and everything under it)", dir_)
rmtree(dir_)
else:
log.info("'%s' does not exist -- can't clean it", dir_)


class PackageCommand(Command):
"""Package command for setup.py that creates source and wheel packages."""

description = 'Build the packages.'
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
log.info('Building Source and Wheel (universal) Packages...')
os.system('{0} setup.py clean sdist bdist_wheel --universal'.format(sys.executable))
sys.exit()


class PublishCommand(Command):
"""Publish command for setup.py that creates git tags and publishes to pypi.
Requires that twine and git be installed."""

description = 'Publish the packages.'
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
log.info('Uploading the package to PyPI using twine...')
os.system('twine upload dist/*')

log.info('Pushing git tags...')
os.system('git tag v{0}'.format(get_utils_version()))
os.system('git push --tags')
sys.exit()
2 changes: 1 addition & 1 deletion src/hdx/utilities/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.7.1

0 comments on commit 6d84afa

Please sign in to comment.