This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·138 lines (113 loc) · 4.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""The setup script."""
from decimal import Decimal
import os
import os.path
from typing import List
# This must be above distutils, despite flake8's opinions. Otherwise,
# this diagnostic is emitted:
# UserWarning: Distutils was imported before Setuptools. This usage is
# discouraged and may exhibit undesirable behaviors or errors. Please
# use Setuptools' objects directly or at least import Setuptools
# first.
from setuptools import find_packages, setup
from distutils.cmd import Command # noqa: I100
with open('README.rst') as readme_file:
readme = readme_file.read()
with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements: List[str] = ['typing_extensions', 'PyYAML', 'pydantic>=1,<2']
test_requirements: List[str] = ['pytest>=3']
# From https://github.com/bluelabsio/records-mover/blob/master/setup.py
class CoverageRatchetCommand(Command):
description = 'Run coverage ratchet'
user_options = [] # type: ignore
coverage_file: str
coverage_source_file: str
coverage_url: str
type_of_coverage: str
def finalize_options(self) -> None:
pass
def run(self) -> None:
"""Run command."""
import xml.etree.ElementTree as ET
tree = ET.parse(self.coverage_source_file)
new_coverage = Decimal(tree.getroot().attrib["line-rate"]) * 100
if not os.path.exists(self.coverage_file):
with open(self.coverage_file, 'w') as f:
f.write('0')
with open(self.coverage_file, 'r') as f:
high_water_mark = Decimal(f.read())
if new_coverage < high_water_mark:
raise Exception(
f"{self.type_of_coverage} coverage used to be {high_water_mark}; "
f"down to {new_coverage}%. Fix by viewing '{self.coverage_url}'")
elif new_coverage > high_water_mark:
with open(self.coverage_file, 'w') as f:
f.write(str(new_coverage))
print(f"Just ratcheted coverage up to {new_coverage}%")
else:
print(f"Code coverage steady at {new_coverage}%")
class TestCoverageRatchetCommand(CoverageRatchetCommand):
def initialize_options(self) -> None:
"""Set default values for options."""
self.type_of_coverage = 'Test'
self.coverage_url = 'cover/index.html'
self.coverage_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'metrics',
'coverage_high_water_mark'
)
self.coverage_source_file = "coverage.xml"
class MypyCoverageRatchetCommand(CoverageRatchetCommand):
def initialize_options(self) -> None:
"""Set default values for options."""
self.type_of_coverage = 'Mypy'
self.coverage_url = 'typecover/index.html'
self.coverage_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'metrics',
'mypy_high_water_mark'
)
self.coverage_source_file = "typecover/cobertura.xml"
setup(
author="Vince Broz",
author_email='[email protected]',
python_requires='>=3.7',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
description="op-env allows you to use 1Password entries as environment variable-style secrets", # noqa: E501
entry_points={
'console_scripts': [
'op-env=op_env._cli:main',
],
},
cmdclass={
'coverage_ratchet': TestCoverageRatchetCommand,
'mypy_ratchet': MypyCoverageRatchetCommand,
},
install_requires=requirements,
license="MIT license",
long_description=readme + '\n\n' + history,
long_description_content_type='text/x-rst',
include_package_data=True,
keywords='op-env',
name='op-env',
packages=find_packages(include=['op_env',
'op_env.*']),
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/apiology/op-env',
version='0.9.0',
zip_safe=False,
)