Skip to content

Commit

Permalink
Extract setup.py tasks in methods, generify Makefile, use package for…
Browse files Browse the repository at this point in the history
… version number
  • Loading branch information
ylogx committed Jun 12, 2015
1 parent 95cceed commit 2052d59
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
35 changes: 22 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
PACKAGE="Universal"
PACKAGE_LOWER=$(shell echo $(PACKAGE) | sed 's/.*/\L&/')
PIP_EXEC=pip
PYTHON_EXEC=python3
PYTHON2_EXEC=python2.7
PYTHON3_EXEC=python3
NOSETESTS_EXEC=$(shell which nosetests)
VERSION = $(shell python -c 'import $(PACKAGE_LOWER); print($(PACKAGE_LOWER).__version__)')
TEST_FILES = $(wildcard tests/test_*.py)
TESTS = $(subst .py,,$(subst /,.,$(TEST_FILES)))
VERSION = $(shell cat setup.py | grep version | sed -e "s/version=//" -e "s/'//g" -e "s/,//" -e 's/^[ \t]*//')

all.PHONY: nosetests_2_3
all.PHONY: nosetests_3 nosetests_2

nosetests_2_3:
@echo "Running python2 tests"
@python2.7 `which nosetests`
@echo "Running python3 tests"
@python3 `which nosetests`
nosetests_2:
@echo "Running $(PYTHON2_EXEC) tests"
@$(PYTHON2_EXEC) $(NOSETESTS_EXEC)

nosetests_3:
@echo "Running $(PYTHON3_EXEC) tests"
@$(PYTHON3_EXEC) $(NOSETESTS_EXEC)

install:
@echo "Creating distribution package for version $(VERSION)"
@echo "-----------------------------------------------"
python setup.py sdist
@echo "Installing package using pip"
$(PYTHON_EXEC) setup.py sdist
@echo "Installing package using $(PIP_EXEC)"
@echo "----------------------------"
pip install --upgrade dist/Universal-$(VERSION).tar.gz
$(PIP_EXEC) install --upgrade dist/$(PACKAGE)-$(VERSION).tar.gz

coverage:
@coverage run `which nosetests`
@coverage run $(NOSETESTS_EXEC)
@coverage report

test:
@- $(foreach TEST,$(TESTS), \
echo === Running test: $(TEST); \
python -m $(TEST) $(PYFLAGS); \
$(PYTHON_EXEC) -m $(TEST) $(PYFLAGS); \
)

test3:
@- $(foreach TEST,$(TESTS), \
echo === Running python3 test: $(TEST); \
python3 -m $(TEST) $(PYFLAGS); \
$(PYTHON3_EXEC) -m $(TEST) $(PYFLAGS); \
)

clean:
Expand Down
36 changes: 22 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
from distutils.core import setup
from setuptools import find_packages

def get_version():
import universal
return universal.__version__

def get_requirements():
with open('requirements.txt', 'rU') as fhan:
requires = [line.strip() for line in fhan.readlines()]
return requires

def get_long_description():
try:
import pypandoc
long_description = pypandoc.convert('README.md', 'rst')
except (IOError, ImportError):
with open('README.txt') as fhan:
long_description = fhan.read()


add_keywords = dict(
entry_points={
'console_scripts': ['universal = universal.main:main'],
}, )

fhan = open('requirements.txt', 'rU')
requires = [line.strip() for line in fhan.readlines()]
fhan.close()
try:
import pypandoc
long_description = pypandoc.convert('README.md', 'rst')
except (IOError, ImportError):
fhan = open('README.txt')
long_description = fhan.read()
fhan.close()

setup(
name='Universal',
description='Universal Competitive Programming Suite helps you work'
' faster in programming competitions',
version='2.0.1',
version=get_version(),
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*",
"tests"]),
license='GPLv3+',
author='Shubham Chaudhary',
author_email='me@shubhamchaudhary.in',
url='https://github.com/shubhamchaudhary/universal',
long_description=long_description,
install_requires=requires, **add_keywords)
long_description=get_long_description(),
install_requires=get_requirements(),
**add_keywords)

0 comments on commit 2052d59

Please sign in to comment.