openapi-core/setup.py

56 lines
1.4 KiB
Python
Raw Normal View History

2019-09-28 20:52:03 +00:00
#!/usr/bin/env python
2017-09-21 11:51:37 +00:00
"""OpenAPI core setup module"""
import os
import re
import sys
2019-09-28 20:52:03 +00:00
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
2017-09-21 11:51:37 +00:00
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)
2019-09-28 20:52:03 +00:00
self.pytest_args = []
2017-09-21 11:51:37 +00:00
def run_tests(self):
# Importing here, `cause outside the eggs aren't loaded.
import pytest
2019-09-28 20:52:03 +00:00
errno = pytest.main(self.pytest_args)
2017-09-21 11:51:37 +00:00
sys.exit(errno)
init_path = os.path.join('openapi_core', '__init__.py')
init_py = read_file(init_path)
metadata = get_metadata(init_py)
2019-09-28 20:52:03 +00:00
if __name__ == '__main__':
setup(
version=metadata['version'],
author=metadata['author'],
author_email=metadata['email'],
url=metadata['url'],
cmdclass={'test': PyTest},
setup_cfg=True,
)