Commit 3a94dfe1 authored by Yuanle Song's avatar Yuanle Song
Browse files

v1.11.2 minor, add PNAME, PKGNAME in Makefile;

- "make loc" now run cloc on $(PYTHON_MODULES) instead of just the main pkg.
- minor, "make full-clean" don't care about .venv-* wheelhouse-*. Those
  files are in global cache dir.
parent cd9bc017
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
(defproject python/lein-template "1.11.1"
(defproject python/lein-template "1.11.2"
  :description "lein template for a python project"
  :url "https://gitlab.emacsos.com/sylecn/python-project-template"
  :license {:name "Apache License 2.0"
+21 −19
Original line number Diff line number Diff line
PYTHON_MODULES := {{python-pkg-name}}
PNAME := {{name}}
PKGNAME := {{python-pkg-name}}
PYTHON_MODULES := $(PKGNAME)
PYTHONPATH := .
VENV := .venv
WHEELHOUSE := wheelhouse
@@ -17,7 +19,7 @@ VIRTUALENV := $(wildcard ./utils/virtualenv-*/virtualenv.py)
REQUIREMENTS := requirements.txt
REQUIREMENTS_DEV := requirements-dev.txt

VERSION := $(shell grep '__version__' {{python-pkg-name}}/__init__.py |cut -d'"' -f 2)
VERSION := $(shell grep '__version__' $(PKGNAME)/__init__.py |cut -d'"' -f 2)
# docker hub user name or private registry URL with username. do not end with /.
DOCKER_IMAGE_PREFIX ?= de02-reg.emacsos.com/sylecn
KUBECTL_CA_PATH ?= /etc/kubernetes/pki/ca.crt
@@ -49,11 +51,11 @@ build:
version:
	@echo $(VERSION)
debug:
	env DEBUG=1 $(PYTHON) {{python-pkg-name}}/main.py
	env DEBUG=1 $(PYTHON) $(PKGNAME)/main.py
run:
	$(PYTHON) {{python-pkg-name}}/main.py
	$(PYTHON) $(PKGNAME)/main.py
uwsgi:
	$(VENV)/bin/uwsgi --processes=2 --threads=4 --wsgi-file={{python-pkg-name}}/main.py --env=PYTHONPATH=. --http=localhost:8082 --disable-logging
	$(VENV)/bin/uwsgi --processes=2 --threads=4 --wsgi-file=$(PKGNAME)/main.py --env=PYTHONPATH=. --http=localhost:8082 --disable-logging
shell:
	$(PYTHON) -i

@@ -70,21 +72,21 @@ $(VENV)/dev-venv-ready: $(VENV)/runtime-venv-ready $(REQUIREMENTS_DEV)
	$(PIP) install -q -i $(PYPI_MIRROR) -r $(REQUIREMENTS_DEV)
	touch "$(VENV)/dev-venv-ready"
logdir:
	@if [ ! -d /var/log/{{name}} ]; then \
		sudo mkdir /var/log/{{name}}; \
		sudo chown -R ${USER} /var/log/{{name}}; \
	@if [ ! -d /var/log/$(PNAME) ]; then \
		sudo mkdir /var/log/$(PNAME); \
		sudo chown -R ${USER} /var/log/$(PNAME); \
	fi
bootstrap: $(VENV)/runtime-venv-ready
bootstrap-dev: $(VENV)/dev-venv-ready
install: bootstrap
	$(PIP) install -q --no-index .
uninstall: bootstrap
	$(PIP) uninstall -q -y {{python-pkg-name}}
docker: deb
	docker build -t $(DOCKER_IMAGE_PREFIX)/{{name}}:$(VERSION) .
	@echo "You may push it with: docker push $(DOCKER_IMAGE_PREFIX)/{{name}}:$(VERSION)"
	$(PIP) uninstall -q -y $(PKGNAME)
deb:
	utils/build-deb
docker: deb
	docker build -t $(DOCKER_IMAGE_PREFIX)/$(PNAME):$(VERSION) .
	@echo "You may push it with: docker push $(DOCKER_IMAGE_PREFIX)/$(PNAME):$(VERSION)"
pipfreeze:
	$(PIP) freeze
wheel: $(REQUIREMENTS)
@@ -97,11 +99,11 @@ wheel: $(REQUIREMENTS)
	fi
check: just-test
sanity-check: bootstrap
	$(PYTHON) {{python-pkg-name}}/sanity_check.py
	$(PYTHON) $(PKGNAME)/sanity_check.py
check-coding-style: bootstrap-dev
	$(PEP8) $(PYTHON_MODULES)
	$(PYLINT) -E $(PYTHON_MODULES)
	$(PYTHON) {{python-pkg-name}}/config.py
	$(PYTHON) $(PKGNAME)/config.py
pylint-full: check-coding-style
	$(PYLINT) $(PYTHON_MODULES)
test: check-coding-style
@@ -116,7 +118,7 @@ ci-build:
	mkdir -p $(pip_cache_dir) \
		$(host_venvs_dir)/$(venv_hash_dir) \
		$(host_wheelhouses_dir)/$(wheelhouse_hash_dir)
	docker run --rm --name {{ name }}-test \
	docker run --rm --name $(PNAME)-test \
		-v "$(CURDIR)":/app \
		-v "$(pip_cache_dir)":/.cache \
		-v "$(host_venvs_dir)/$(venv_hash_dir)":/app/$(VENV) \
@@ -124,8 +126,8 @@ ci-build:
		-u $(shell id -u):$(shell id -g) \
		$(BUILD_DOCKER_IMAGE) \
		make test deb -C /app
	docker build -t $(DOCKER_IMAGE_PREFIX)/{{ name }}:$(VERSION) .
	docker push $(DOCKER_IMAGE_PREFIX)/{{ name }}:$(VERSION)
	docker build -t $(DOCKER_IMAGE_PREFIX)/$(PNAME):$(VERSION) .
	docker push $(DOCKER_IMAGE_PREFIX)/$(PNAME):$(VERSION)
	@echo "removing obsolete .venv-<hash> and wheelhouse-<hash> dirs..."
	find $(CI_BUILD_GLOBAL_CACHE) -maxdepth 2 -type d \
		\( \( -name "venv-*" -a ! -name "$(venv_hash_dir)" \) -o \
@@ -141,7 +143,7 @@ clean:
	find . -name "__pycache__" -type d -exec rm -rf {} \; || true
	find . -name "*.pyc" -type f -exec rm -rf {} \; || true
full-clean:
	rm -rf "$(VENV)" build/ dist/ "$(WHEELHOUSE)" {{python-pkg-name}}.egg-info/ distribute-*.tar.gz .venv-* wheelhouse-*
	rm -rf "$(VENV)" build/ dist/ "$(WHEELHOUSE)" $(PKGNAME).egg-info/ distribute-*.tar.gz
	find . -name "__pycache__" -type d -exec rm -rf {} \; || true
	find . -name "*.pyc" -type f -exec rm -rf {} \; || true
todo:
@@ -155,5 +157,5 @@ install-git-hooks-force:
	./utils/install-git-hooks -f
loc:
	find . -regex '.*\.pyw?$$' -exec wc -l {} \+ | tail -n 1
	which cloc >/dev/null && cloc {{python-pkg-name}}/
	which cloc >/dev/null && cloc $(PYTHON_MODULES)
.PHONY: default build debug run uwsgi shell bootstrap bootstrap-dev install uninstall deb pipfreeze wheel check check-coding-style pylint-full test just-test test-prod clean full-clean todo TAGS update-git-hooks install-git-hooks install-git-hooks-force loc