Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
133 changes: 133 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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)

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

.PHONY: setup
setup: $(REQUIREMENTS) ## Create the python virtual environment with developper tools
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) ## Format the python source code
$(YAPF) -p -i --style .style.yapf $(PYTHON_FILES)
$(ISORT) $(PYTHON_FILES)


.PHONY: ci-check-format
ci-check-format: format ## Check if formatting python source code is required
@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) ## Lint the python source code
$(PYLINT) $(PYTHON_FILES)


.PHONY: format-lint
format-lint: format lint ## Format and lint the python source code


# Test target

.PHONY: test
test: $(DEV_REQUIREMENTS_TIMESTAMP) ## Run the tests
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) ## Create package
$(PYTHON) -m build


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


# Clean targets

.PHONY: clean-venv
clean-venv: ## Clean python venv
pipenv --rm

.PHONY: clean
clean: clean-venv ## Clean generated files
@# 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 ## Clean everything

# 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: ## Check if publish is allowed
@if [ -n "`git status --porcelain`" ]; then echo "ERROR: Repo is dirty !" >&2; exit 1; fi

.PHONY: help
help: ## Display this help
# automatically generate the help page based on the documentation after each make target
# from https://gist.github.com/prwhite/8168133
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Copy link
Contributor

Choose a reason for hiding this comment

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

awk is great 👍

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