Skip to content

Commit f61482b

Browse files
committed
PB-1968: Add pipenv and makefile
1 parent a74730f commit f61482b

File tree

13 files changed

+571
-84
lines changed

13 files changed

+571
-84
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ target/
6464

6565
# Vim temporary files
6666
*.swp
67+
68+
# test report
69+
nose2-junit.xml

.pylintrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[MAIN]
2+
ignore=.venv
3+
4+
[MESSAGES CONTROL]
5+
disable=
6+
# no convention and refactor rules
7+
C,
8+
R,
9+
# allow some unconventional stuff (assuming the library already works as intended)
10+
unused-variable,
11+
attribute-defined-outside-init,
12+
unused-import,
13+
possibly-used-before-assignment
14+
15+
generated-members=
16+
# added via mixins
17+
gatilegrid.tilegrids._TileGrid.MINX
18+
gatilegrid.tilegrids._TileGrid.MAXX
19+
gatilegrid.tilegrids._TileGrid.MINY
20+
gatilegrid.tilegrids._TileGrid.MAXY
21+
gatilegrid.tilegrids._TileGrid.RESOLUTIONS
22+
gatilegrid.tilegrids._TileGrid.spatialReference
23+
gatilegrid.tilegrids._TileGrid.tileAddressTemplate
24+
gatilegrid.tilegrids._TileGrid.unit
25+
gatilegrid.tilegrids._TileGrid.metersPerUnit
26+
gatilegrid.tilegrids._TileGrid.
27+
28+
[REPORTS]
29+
score = no

.style.yapf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[style]
2+
based_on_style=google
3+
# Put closing brackets on a separate line, dedented, if the bracketed
4+
# expression can't fit in a single line. Applies to all kinds of brackets,
5+
# including function definitions and calls. For example:
6+
#
7+
# config = {
8+
# 'key1': 'value1',
9+
# 'key2': 'value2',
10+
# } # <--- this bracket is dedented and on a separate line
11+
#
12+
# time_series = self.remote_client.query_entity_counters(
13+
# entity='dev3246.region1',
14+
# key='dns.query_latency_tcp',
15+
# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
16+
# start_ts=now()-timedelta(days=3),
17+
# end_ts=now(),
18+
# ) # <--- this bracket is dedented and on a separate line
19+
dedent_closing_brackets=True
20+
coalesce_brackets=True
21+
22+
# This avoid issues with complex dictionary
23+
# see https://github.com/google/yapf/issues/392#issuecomment-407958737
24+
indent_dictionary_value=True
25+
allow_split_before_dict_value=False
26+
27+
# Split before arguments, but do not split all sub expressions recursively
28+
# (unless needed).
29+
split_all_top_level_comma_separated_values=True
30+
31+
# Split lines longer than 100 characters (this only applies to code not to
32+
# comment and docstring)
33+
column_limit=100

Makefile

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
SHELL = /bin/bash
2+
3+
.DEFAULT_GOAL := help
4+
5+
6+
CURRENT_DIR := $(shell pwd)
7+
8+
# Test reports configuration
9+
TEST_REPORT_DIR ?= $(CURRENT_DIR)/tests/report
10+
TEST_REPORT_FILE ?= nose2-junit.xml
11+
12+
# general targets timestamps
13+
TIMESTAMPS = .timestamps
14+
REQUIREMENTS := $(TIMESTAMPS) $(PIP_FILE) $(PIP_FILE_LOCK)
15+
16+
# Find all python files that are not inside a hidden directory (directory starting with .)
17+
PYTHON_FILES := $(shell find ./* -type d \( -path ./build -o -path ./dist \) -prune -false -o -type f -name "*.py" -print)
18+
19+
# PIPENV files
20+
PIP_FILE = Pipfile
21+
PIP_FILE_LOCK = Pipfile.lock
22+
23+
# default configuration
24+
ENV_FILE ?= .env.local
25+
26+
# Commands
27+
PIPENV_RUN := pipenv run
28+
PYTHON := $(PIPENV_RUN) python3
29+
PIP := $(PIPENV_RUN) pip3
30+
YAPF := $(PIPENV_RUN) yapf
31+
ISORT := $(PIPENV_RUN) isort
32+
NOSE := $(PIPENV_RUN) nose2
33+
PYLINT := $(PIPENV_RUN) pylint
34+
35+
PACKAGE_VERSION = $(shell awk '/^Version:/ {print $$2}' gatilegrid.egg-info/PKG-INFO)
36+
37+
38+
all: help
39+
40+
41+
.PHONY: help
42+
help:
43+
@echo "Usage: make <target>"
44+
@echo
45+
@echo "Possible targets:"
46+
@echo -e " \033[1mSetup TARGETS\033[0m "
47+
@echo "- setup Create the python virtual environment with developper tools"
48+
@echo -e " \033[1mFORMATING, LINTING AND TESTING TOOLS TARGETS\033[0m "
49+
@echo "- format Format the python source code"
50+
@echo "- lint Lint the python source code"
51+
@echo "- format-lint Format and lint the python source code"
52+
@echo "- test Run the tests"
53+
@echo -e " \033[1mPACKAGING TARGETS\033[0m "
54+
@echo "- package Create package"
55+
@echo "- publish Tag and publish package to PyPI"
56+
@echo -e " \033[1mCLEANING TARGETS\033[0m "
57+
@echo "- clean Clean generated files"
58+
@echo "- clean-venv Clean python venv"
59+
@echo "- clean-all Clean everything"
60+
61+
62+
# Build targets. Calling setup is all that is needed for the local files to be installed as needed.
63+
64+
.PHONY: setup
65+
setup: $(REQUIREMENTS)
66+
pipenv install --dev
67+
68+
# linting target, calls upon yapf to make sure your code is easier to read and respects some conventions.
69+
70+
.PHONY: format
71+
format: $(REQUIREMENTS)
72+
$(YAPF) -p -i --style .style.yapf $(PYTHON_FILES)
73+
$(ISORT) $(PYTHON_FILES)
74+
75+
76+
.PHONY: ci-check-format
77+
ci-check-format: format
78+
@if [[ -n `git status --porcelain` ]]; then \
79+
>&2 echo "ERROR: the following files are not formatted correctly:"; \
80+
>&2 git status --porcelain; \
81+
exit 1; \
82+
fi
83+
84+
85+
.PHONY: lint
86+
lint: $(REQUIREMENTS)
87+
$(PYLINT) $(PYTHON_FILES)
88+
89+
90+
.PHONY: format-lint
91+
format-lint: format lint
92+
93+
94+
# Test target
95+
96+
.PHONY: test
97+
test: $(DEV_REQUIREMENTS_TIMESTAMP)
98+
mkdir -p $(TEST_REPORT_DIR)
99+
$(NOSE) -v -c tests/unittest.cfg --junit-xml-path $(TEST_REPORT_DIR)/$(TEST_REPORT_FILE) -s tests/
100+
101+
102+
# Packaging target
103+
104+
.PHONY: package
105+
package: $(DEV_REQUIREMENTS_TIMESTAMP)
106+
$(PYTHON) -m build
107+
108+
109+
.PHONY: publish
110+
publish: publish-check package
111+
@echo "Upload package version=$(PACKAGE_VERSION)"
112+
$(PYTHON) -m twine upload dist/*
113+
114+
115+
# Clean targets
116+
117+
.PHONY: clean-venv
118+
clean-venv:
119+
pipenv --rm
120+
121+
.PHONY: clean
122+
clean: clean-venv
123+
@# clean python cache files
124+
find . -name __pycache__ -type d -print0 | xargs -I {} -0 rm -rf "{}"
125+
rm -rf $(TEST_REPORT_DIR)
126+
rm -rf $(TIMESTAMPS)
127+
rm -rf dist
128+
rm -rf build
129+
rm -rf *.egg-info
130+
rm -f .coverage
131+
132+
.PHONY: clean-all
133+
clean-all: clean
134+
135+
# Actual builds targets with dependencies
136+
137+
$(TIMESTAMPS):
138+
mkdir -p $(TIMESTAMPS)
139+
140+
141+
$(VENV_TIMESTAMP):
142+
test -d $(VENV) || $(SYSTEM_PYTHON) -m venv $(VENV) && $(PIP) install --upgrade pip setuptools
143+
@touch $(VENV_TIMESTAMP)
144+
145+
146+
$(DEV_REQUIREMENTS_TIMESTAMP): $(VENV_TIMESTAMP) $(DEV_REQUIREMENTS)
147+
$(PIP) install -r $(DEV_REQUIREMENTS)
148+
@touch $(DEV_REQUIREMENTS_TIMESTAMP)
149+
150+
151+
publish-check:
152+
@echo "Check if publish is allowed"
153+
@if [ -n "`git status --porcelain`" ]; then echo "ERROR: Repo is dirty !" >&2; exit 1; fi

Pipfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[dev-packages]
7+
flake8 = "*"
8+
nose2 = { version = "*", extras = ["coverage_plugin"] }
9+
yapf = "*"
10+
pylint = "*"
11+
isort = "*"
12+
setuptools = "*"
13+
build = "*"

0 commit comments

Comments
 (0)