-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19 add setup.py to distribute PyPI package
- Loading branch information
Showing
5 changed files
with
202 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include *.txt | ||
include *.rst | ||
include *.md | ||
include *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import os | ||
import inspect | ||
|
||
from setuptools.command.test import test as TestCommand | ||
from setuptools import setup | ||
|
||
__location__ = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe()))) | ||
|
||
|
||
def read_module(path): | ||
data = {} | ||
with open(path, 'r') as fd: | ||
exec(fd.read(), data) | ||
return data | ||
|
||
meta = read_module('pg_view.py') | ||
NAME = 'pg-view' | ||
MAIN_MODULE = 'pg_view' | ||
VERSION = meta['__version__'] | ||
DESCRIPTION = 'PostgreSQL Activity View Utility' | ||
LICENSE = 'Apache License 2.0' | ||
URL = 'https://github.com/zalando/pg_view' | ||
author, email = meta['__author__'].rsplit(None, 1) | ||
AUTHOR = author | ||
EMAIL = email.strip('<>') | ||
KEYWORDS = 'postgres postgresql pg database' | ||
|
||
# Add here all kinds of additional classifiers as defined under | ||
# https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
CLASSIFIERS = [ | ||
'Development Status :: 4 - Beta', | ||
'Environment :: Console', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Operating System :: POSIX :: Linux', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
] | ||
|
||
CONSOLE_SCRIPTS = ['pg_view = pg_view:main'] | ||
|
||
|
||
class PyTest(TestCommand): | ||
|
||
user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'), ('cov-html=', | ||
None, 'Generate junit html report'), ('junitxml=', None, 'Generate xml of test results')] | ||
|
||
def initialize_options(self): | ||
TestCommand.initialize_options(self) | ||
self.cov = None | ||
self.cov_xml = False | ||
self.cov_html = False | ||
self.junitxml = None | ||
|
||
def finalize_options(self): | ||
TestCommand.finalize_options(self) | ||
if self.cov is not None: | ||
self.cov = ['--cov', self.cov, '--cov-report', 'term-missing'] | ||
if self.cov_xml: | ||
self.cov.extend(['--cov-report', 'xml']) | ||
if self.cov_html: | ||
self.cov.extend(['--cov-report', 'html']) | ||
|
||
def run_tests(self): | ||
try: | ||
import pytest | ||
except: | ||
raise RuntimeError('py.test is not installed, run: pip install pytest') | ||
params = {'args': self.test_args} | ||
if self.cov: | ||
params['args'] += self.cov | ||
params['plugins'] = ['cov'] | ||
params['args'] += ['--doctest-modules', MAIN_MODULE + '.py', '-s', '-vv'] | ||
errno = pytest.main(**params) | ||
sys.exit(errno) | ||
|
||
|
||
def get_install_requirements(path): | ||
content = open(os.path.join(__location__, path)).read() | ||
return [req for req in content.split('\\n') if req != ''] | ||
|
||
|
||
def read(fname): | ||
return open(os.path.join(__location__, fname)).read() | ||
|
||
|
||
def setup_package(): | ||
# Assemble additional setup commands | ||
cmdclass = {} | ||
cmdclass['test'] = PyTest | ||
|
||
install_reqs = get_install_requirements('requirements.txt') | ||
|
||
command_options = {} | ||
|
||
setup( | ||
name=NAME, | ||
version=VERSION, | ||
url=URL, | ||
description=DESCRIPTION, | ||
author=AUTHOR, | ||
author_email=EMAIL, | ||
license=LICENSE, | ||
keywords=KEYWORDS, | ||
long_description=read('README.md'), | ||
classifiers=CLASSIFIERS, | ||
test_suite='tests', | ||
py_modules=['pg_view'], | ||
packages=[], | ||
install_requires=install_reqs, | ||
setup_requires=['flake8'], | ||
cmdclass=cmdclass, | ||
tests_require=['pytest-cov', 'pytest'], | ||
command_options=command_options, | ||
entry_points={'console_scripts': CONSOLE_SCRIPTS}, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
setup_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pg_view | ||
|
||
def test_dummy(): | ||
pass | ||
|