Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[report]
show_missing = True
13 changes: 13 additions & 0 deletions .github/workflows/pr-auto-semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: on-pr

on:
pull_request:
types:
- opened
- reopened
- synchronize
- edited

jobs:
pr-edit:
uses: geoadmin/.github/.github/workflows/pr-auto-semver.yml@master
11 changes: 11 additions & 0 deletions .github/workflows/semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: on-push

on:
push:
branches:
- master
- develop

jobs:
release:
uses: geoadmin/.github/.github/workflows/semver-release.yml@master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/

# Vim temporary files
*.swp

# test report
nose2-junit.xml
7 changes: 7 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[settings]
known_third_party=pytest
known_django=django
known_flask=flask
known_gatilegrid=gatilegrid
force_single_line=True
sections=FUTURE,STDLIB,THIRDPARTY,DJANGO,FLASK,GATILEGRID,FIRSTPARTY,LOCALFOLDER
29 changes: 29 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[MAIN]
ignore=.venv

[MESSAGES CONTROL]
disable=
# no convention and refactor rules
C,
R,
# allow some unconventional stuff (assuming the library already works as intended)
unused-variable,
attribute-defined-outside-init,
unused-import,
possibly-used-before-assignment

generated-members=
# added via mixins
gatilegrid.tilegrids._TileGrid.MINX
gatilegrid.tilegrids._TileGrid.MAXX
gatilegrid.tilegrids._TileGrid.MINY
gatilegrid.tilegrids._TileGrid.MAXY
gatilegrid.tilegrids._TileGrid.RESOLUTIONS
gatilegrid.tilegrids._TileGrid.spatialReference
gatilegrid.tilegrids._TileGrid.tileAddressTemplate
gatilegrid.tilegrids._TileGrid.unit
gatilegrid.tilegrids._TileGrid.metersPerUnit
gatilegrid.tilegrids._TileGrid.

[REPORTS]
score = no
33 changes: 33 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[style]
based_on_style=google
# Put closing brackets on a separate line, dedented, if the bracketed
# expression can't fit in a single line. Applies to all kinds of brackets,
# including function definitions and calls. For example:
#
# config = {
# 'key1': 'value1',
# 'key2': 'value2',
# } # <--- this bracket is dedented and on a separate line
#
# time_series = self.remote_client.query_entity_counters(
# entity='dev3246.region1',
# key='dns.query_latency_tcp',
# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
# start_ts=now()-timedelta(days=3),
# end_ts=now(),
# ) # <--- this bracket is dedented and on a separate line
dedent_closing_brackets=True
coalesce_brackets=True

# This avoid issues with complex dictionary
# see https://github.com/google/yapf/issues/392#issuecomment-407958737
indent_dictionary_value=True
allow_split_before_dict_value=False

# Split before arguments, but do not split all sub expressions recursively
# (unless needed).
split_all_top_level_comma_separated_values=True

# Split lines longer than 100 characters (this only applies to code not to
# comment and docstring)
column_limit=100
153 changes: 153 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
SHELL = /bin/bash

.DEFAULT_GOAL := help


CURRENT_DIR := $(shell pwd)

# Test reports configuration
TEST_REPORT_DIR ?= $(CURRENT_DIR)/tests/report
TEST_REPORT_FILE ?= nose2-junit.xml

# general targets timestamps
TIMESTAMPS = .timestamps
REQUIREMENTS := $(TIMESTAMPS) $(PIP_FILE) $(PIP_FILE_LOCK)

# Find all python files that are not inside a hidden directory (directory starting with .)
PYTHON_FILES := $(shell find ./* -type d \( -path ./build -o -path ./dist \) -prune -false -o -type f -name "*.py" -print)

# PIPENV files
PIP_FILE = Pipfile
PIP_FILE_LOCK = Pipfile.lock

# default configuration
ENV_FILE ?= .env.local

# Commands
PIPENV_RUN := pipenv run
PYTHON := $(PIPENV_RUN) python3
PIP := $(PIPENV_RUN) pip3
YAPF := $(PIPENV_RUN) yapf
ISORT := $(PIPENV_RUN) isort
NOSE := $(PIPENV_RUN) nose2
PYLINT := $(PIPENV_RUN) pylint

PACKAGE_VERSION = $(shell awk '/^Version:/ {print $$2}' gatilegrid.egg-info/PKG-INFO)


all: help


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I like the way service-control implemented the help part:
https://github.com/geoadmin/service-control/blob/develop/Makefile#L178

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know this was even possible! I've changed it accordingly...

.PHONY: help
help:
@echo "Usage: make <target>"
@echo
@echo "Possible targets:"
@echo -e " \033[1mSetup TARGETS\033[0m "
@echo "- setup Create the python virtual environment with developper tools"
@echo -e " \033[1mFORMATING, LINTING AND TESTING TOOLS TARGETS\033[0m "
@echo "- format Format the python source code"
@echo "- lint Lint the python source code"
@echo "- format-lint Format and lint the python source code"
@echo "- test Run the tests"
@echo -e " \033[1mPACKAGING TARGETS\033[0m "
@echo "- package Create package"
@echo "- publish Tag and publish package to PyPI"
@echo -e " \033[1mCLEANING TARGETS\033[0m "
@echo "- clean Clean generated files"
@echo "- clean-venv Clean python venv"
@echo "- clean-all Clean everything"


# Build targets. Calling setup is all that is needed for the local files to be installed as needed.

.PHONY: setup
setup: $(REQUIREMENTS)
pipenv install --dev

# linting target, calls upon yapf to make sure your code is easier to read and respects some conventions.

.PHONY: format
format: $(REQUIREMENTS)
$(YAPF) -p -i --style .style.yapf $(PYTHON_FILES)
$(ISORT) $(PYTHON_FILES)


.PHONY: ci-check-format
ci-check-format: format
@if [[ -n `git status --porcelain` ]]; then \
>&2 echo "ERROR: the following files are not formatted correctly:"; \
>&2 git status --porcelain; \
exit 1; \
fi


.PHONY: lint
lint: $(REQUIREMENTS)
$(PYLINT) $(PYTHON_FILES)


.PHONY: format-lint
format-lint: format lint


# Test target

.PHONY: test
test: $(DEV_REQUIREMENTS_TIMESTAMP)
mkdir -p $(TEST_REPORT_DIR)
$(NOSE) -v -c tests/unittest.cfg --junit-xml-path $(TEST_REPORT_DIR)/$(TEST_REPORT_FILE) -s tests/


# Packaging target

.PHONY: package
package: $(DEV_REQUIREMENTS_TIMESTAMP)
$(PYTHON) -m build


.PHONY: publish
publish: publish-check package
@echo "Upload package version=$(PACKAGE_VERSION)"
$(PYTHON) -m twine upload dist/*


# Clean targets

.PHONY: clean-venv
clean-venv:
pipenv --rm

.PHONY: clean
clean: clean-venv
@# clean python cache files
find . -name __pycache__ -type d -print0 | xargs -I {} -0 rm -rf "{}"
rm -rf $(TEST_REPORT_DIR)
rm -rf $(TIMESTAMPS)
rm -rf dist
rm -rf build
rm -rf *.egg-info
rm -f .coverage

.PHONY: clean-all
clean-all: clean

# Actual builds targets with dependencies

$(TIMESTAMPS):
mkdir -p $(TIMESTAMPS)


$(VENV_TIMESTAMP):
test -d $(VENV) || $(SYSTEM_PYTHON) -m venv $(VENV) && $(PIP) install --upgrade pip setuptools
@touch $(VENV_TIMESTAMP)


$(DEV_REQUIREMENTS_TIMESTAMP): $(VENV_TIMESTAMP) $(DEV_REQUIREMENTS)
$(PIP) install -r $(DEV_REQUIREMENTS)
@touch $(DEV_REQUIREMENTS_TIMESTAMP)


publish-check:
@echo "Check if publish is allowed"
@if [ -n "`git status --porcelain`" ]; then echo "ERROR: Repo is dirty !" >&2; exit 1; fi
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[dev-packages]
flake8 = "*"
nose2 = { version = "*", extras = ["coverage_plugin"] }
yapf = "*"
pylint = "*"
isort = "*"
setuptools = "*"
build = "*"
Loading
Loading