Skip to content

Commit

Permalink
Inline setuputils.py to avoid issues with pip install from Homebrew (#30
Browse files Browse the repository at this point in the history
)

* Inline setuputils.py to avoid issues with pip install from Homebrew

(similar problem and solution as applied to https://github.com/bluelabsio/db-facts)

* Bump bugfix version

* Add quality-bigfiles target
  • Loading branch information
vinceatbluelabs authored Mar 8, 2020
1 parent 632726a commit baa5ab5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 97 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ quality-flake8:
quality-punchlist:
make QUALITY_TOOL=punchlist quality

quality-bigfiles:
make QUALITY_TOOL=bigfiles quality

quality-mdl:
make QUALITY_TOOL=mdl quality

Expand Down
2 changes: 1 addition & 1 deletion records_mover/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.0'
__version__ = '0.3.1'
106 changes: 96 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,110 @@

import os
from setuptools import setup, find_packages
from setuputils import TestCoverageRatchetCommand, MypyCoverageRatchetCommand, VerifyVersionCommand
from setuptools.command.install import install
from typing import Optional
from decimal import Decimal
from distutils.cmd import Command
import os.path
import sys

gsheet_dependencies = [
'google',
'google_auth_httplib2',
'google-api-python-client>=1.5.0,<1.6.0',
'oauth2client>=2.0.2,<2.1.0',
'PyOpenSSL'
]

__version__: str
__version__: Optional[str] = None
# Read in and set version variable without the overhead/requirements
# of the rest of the package.
#
# https://milkr.io/kfei/5-common-patterns-to-version-your-Python-package/5
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'records_mover', 'version.py')) as f:
exec(f.read())
assert __version__ is not None


# From https://circleci.com/blog/continuously-deploying-python-packages-to-pypi-with-circleci/
class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
description = 'verify that the git tag matches our version'

def run(self) -> None:
tag = os.getenv('CIRCLE_TAG')
tag_formatted_version = f'v{__version__}'

if tag != tag_formatted_version:
info = "Git tag: {0} does not match the version of this app: {1}".format(
tag, __version__
)
sys.exit(info)


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"


gsheet_dependencies = [
'google',
'google_auth_httplib2',
'google-api-python-client>=1.5.0,<1.6.0',
'oauth2client>=2.0.2,<2.1.0',
'PyOpenSSL'
]

this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
Expand Down
86 changes: 0 additions & 86 deletions setuputils.py

This file was deleted.

0 comments on commit baa5ab5

Please sign in to comment.