forked from man-group/pytest-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_setup.py
65 lines (52 loc) · 2.13 KB
/
common_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Common setup.py code shared between all the projects in this repository
import sys
import os
import logging
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
pytest_args = []
src_dir = None
def initialize_options(self):
TestCommand.initialize_options(self)
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
global pytest_args
logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s', level='DEBUG')
# import here, cause outside the eggs aren't loaded
import pytest
self.pytest_args.extend(['--junitxml', 'junit.xml'])
errno = pytest.main(self.pytest_args)
sys.exit(errno)
def common_setup(src_dir):
this_dir = os.path.dirname(__file__)
readme_file = os.path.join(this_dir, 'README.md')
changelog_file = os.path.join(this_dir, 'CHANGES.md')
version_file = os.path.join(this_dir, 'VERSION')
# Convert Markdown to RST for PyPI
try:
import pypandoc
long_description = pypandoc.convert(readme_file, 'rst')
changelog = pypandoc.convert(changelog_file, 'rst')
except (IOError, ImportError, OSError):
long_description = open(readme_file).read()
changelog = open(changelog_file).read()
# Gather trailing arguments for pytest, this can't be done using setuptools' api
if 'test' in sys.argv:
PyTest.pytest_args = sys.argv[sys.argv.index('test') + 1:]
if PyTest.pytest_args:
sys.argv = sys.argv[:-len(PyTest.pytest_args)]
PyTest.src_dir = src_dir
return dict(
# Version is shared between all the projects in this repo
version=open(version_file).read().strip(),
long_description='\n'.join((long_description, changelog)),
url='https://github.com/manahl/pytest-plugins',
license='MIT license',
platforms=['unix', 'linux'],
cmdclass={'test': PyTest},
setup_requires=['setuptools-git'],
include_package_data=True
)