-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
63 lines (44 loc) · 1.89 KB
/
Makefile
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
.PHONY: bootstrap install test lint _lintblack _lintflake8 build clean assert_new_pypi_version assert_clean_git
SHELL := /bin/bash
bootstrap:
pip install flake8 tox requests
pip install black || echo "Error installing black"
build:
python setup.py sdist bdist_wheel
install:
python setup.py install
clean:
rm -rf build dist pytest_it.egg-info
test:
tox
lint: _lintblack _lintflake8
_lintblack:
set -o pipefail && which black && black src --check 2>&1 | sed "s/^/[black] /"
_lintflake8:
set -o pipefail && flake8 src tests | sed "s/^/[flake8] /"
format:
black .
release: clean lint test build assert_clean_git assert_new_pypi_version
twine upload --repository pytest-it dist/"$$(python setup.py --name)"*
git tag "$$(python setup.py --version)"
echo "Release successful. You probably want to push the new git tag."
assert_new_pypi_version:
python3 -c "$$PYSCRIPT_ASSERT_NEW_VERSION"
assert_clean_git:
if [ "$$TRAVIS" = "true" ]; then exit 0; elif [ "$$(git status --porcelain)" != "" ]; then echo "Dirty git index, exiting." && exit 1; fi
# PYSCRIPT_ASSERT_NEW_VERSION ------------------------------
# Confirm that there isn't an existing PyPI build for this version.
define PYSCRIPT_ASSERT_NEW_VERSION
import subprocess, sys, requests
NAME = subprocess.check_output(['python', 'setup.py', '--name']).decode().strip()
LOCAL_VERSION = subprocess.check_output(['python', 'setup.py', '--version']).decode().strip()
pypi_data_url = 'https://pypi.python.org/pypi/{name}/json'.format(name=NAME)
pypi_resp = requests.get(pypi_data_url)
pypi_resp.raise_for_status() # If not registered this will raise
pypi_data = pypi_resp.json()
for pypi_version, upload_data in pypi_data['releases'].items():
if upload_data and LOCAL_VERSION == pypi_version:
print('Found existing PyPI release to match local version {}, exiting'.format(LOCAL_VERSION))
sys.exit(1)
endef
export PYSCRIPT_ASSERT_NEW_VERSION