forked from python-openapi/openapi-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
55 lines (43 loc) · 1.39 KB
/
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
#!/usr/bin/env python
"""OpenAPI core setup module"""
import os
import re
import sys
try:
from setuptools import setup
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup
finally:
from setuptools.command.test import test as TestCommand
def read_file(filename):
"""Open and a file, read it and return its contents."""
path = os.path.join(os.path.dirname(__file__), filename)
with open(path) as f:
return f.read()
def get_metadata(init_file):
"""Read metadata from a given file and return a dictionary of them"""
return dict(re.findall("__([a-z]+)__ = '([^']+)'", init_file))
class PyTest(TestCommand):
"""Command to run unit tests after in-place build."""
def finalize_options(self):
TestCommand.finalize_options(self)
self.pytest_args = []
def run_tests(self):
# Importing here, `cause outside the eggs aren't loaded.
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
init_path = os.path.join('openapi_core', '__init__.py')
init_py = read_file(init_path)
metadata = get_metadata(init_py)
if __name__ == '__main__':
setup(
version=metadata['version'],
author=metadata['author'],
author_email=metadata['email'],
url=metadata['url'],
cmdclass={'test': PyTest},
setup_cfg=True,
)