Last active
January 29, 2019 11:34
-
-
Save elena-roff/35ff2d45d16ff03ef1d9abcd9d18b6ed to your computer and use it in GitHub Desktop.
Sets up the project environment
This file contains hidden or 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
import os | |
import unittest | |
import shutil | |
from setuptools import setup | |
from setuptools import Command | |
from <module> import __version__ | |
try: | |
import coverage | |
except ImportError: | |
print("Coverage not found. It will be installed during the setup.") | |
PACKAGE_NAME = "your_module" | |
PACKAGE = PACKAGE_NAME | |
SOURCE_DIR = PACKAGE | |
TESTDIR = "test" | |
PATTERN = "*_test.py" | |
REQUIREMENTS = "python_requirements.txt" | |
def readme(): | |
with open("README.md") as fh: | |
return fh.read() | |
def my_test_suite(): | |
test_loader = unittest.TestLoader() | |
test_suite = test_loader.discover(os.path.join(SOURCE_DIR, TESTDIR), pattern=PATTERN) | |
return test_suite | |
def get_dependencies(REQ): | |
with open(REQ) as fh: | |
dependencies = fh.readlines() | |
return dependencies | |
#def get_version_and_ticket(sep="_"): | |
# folder = os.path.split(os.path.abspath(os.curdir))[-1] | |
# return folder.split(sep) | |
class CoverageCommand(Command): | |
""" | |
Test Coverage Analysis Command | |
""" | |
description = "Uses coverage.py as the coverage estimator." | |
user_options = [] | |
def initialize_options(self): | |
""" no options """ | |
pass | |
def finalize_options(self): | |
""" no options """ | |
def run(self): | |
""" Main command containing the logic.""" | |
# first delete the COVERAGE DIR | |
try: | |
shutil.rmtree(os.path.join(TESTDIR, "data")) | |
except: | |
pass | |
test_suite = my_test_suite() | |
runner = unittest.TextTestRunner() | |
cov = coverage.Coverage(branch=True, source=".") | |
cov.start() | |
runner.run(test_suite) | |
cov.stop() | |
cov.report(include=PACKAGE, show_missing=False) | |
setup( | |
name = PACKAGE_NAME, | |
version = __version__, | |
author = ["your name"], | |
author_email = ["[email protected]"], | |
packages = [PACKAGE], | |
install_requires = get_dependencies(REQUIREMENTS), | |
description = "project dev description", | |
long_description = readme(), | |
url = "", | |
test_suite = 'setup.my_test_suite', | |
include_package_data = True, | |
entry_points = {"distutils.commands": ["cover = setup:CoverageCommand"]} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment