forked from ppldl/p_pl_dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (123 loc) · 4.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Adapted from https://github.com/Textualize/frogmouth/blob/main/Makefile
##############################################################################
# Path of every file type (. by default if you want it in the current directory)
SRC_DIR := src
TEST_DIR := tests
DOC_DIR := docs
# Common commands
RUN := poetry run
PYTHON := $(RUN) python
LINT := $(RUN) pylint
MYPY := $(RUN) mypy
BLACK := $(RUN) black
ISORT := $(RUN) isort
BANDIT := $(RUN) bandit
MONKEY := $(RUN) monkeytype
TEST := $(RUN) pytest
# Package Settings
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
# Calculate the initial package name from the directory name
initial_package := $(subst -,_,$(notdir $(patsubst %/,%,$(dir $(mkfile_path)))))
# Detect if src folder exists
src_folder_exists := $(wildcard $(SRC_DIR))
ifeq ($(src_folder_exists),)
# If src folder doesn't exist, use the initial package name
PACKAGE := $(initial_package)
else
# If src folder exists, use the initial package name with src/ prefix
PACKAGE := $(addprefix $(SRC_DIR)/,$(initial_package))
endif
MODULE := $(subst /,.,$(PACKAGE))
##############################################################################
# Methods of running the application.
.PHONY: run
run: # Run the application
$(RUN) $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
.PHONY: debug
debug: # Run the application in debug mode
TEXTUAL=devtools make run
##############################################################################
# Setup/update packages the system requires.
.PHONY: setup
setup: # Set up the development environment
poetry install
$(RUN) pre-commit install
.PHONY: update
update: # Update the development environment
poetry update
##############################################################################
# Package building and distribution.
.PHONY: build
build: # Build the package for distribution
poetry build
.PHONY: clean
clean: # Clean up the package builds
rm -rf dist
##############################################################################
# Package publishing.
.PHONY: publish
publish: # Publish the package to PyPI
poetry publish --build
.PHONY: publish-test
publish-test: # Publish the package to TestPyPI
poetry publish --build -r testpypi
##############################################################################
# Reformatting tools.
.PHONY: black
black: # Run black over the code
$(BLACK) $(PACKAGE)
.PHONY: isort
isort: # Run isort over the code
$(ISORT) $(PACKAGE)
.PHONY: reformat
reformat: isort black # Run all the formatting tools over the code
##############################################################################
# Documentation.
doc: # Build the documentation
sphinx-quickstart "$(DOC_DIR)"
apidoc: # Build the API documentation
sphinx-apidoc -o "$(DOCSRC)" .
html: # Build the HTML documentation
sphinx-build "$(DOCSRC)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
livehtml: # Run a live-updating HTML server for the documentation
sphinx-autobuild "$(DOCSRC)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
##############################################################################
# Checking/testing/linting/etc.
.PHONY: lint
lint: # Run Pylint over the library
$(LINT) $(PACKAGE)
.PHONY: typecheck
typecheck: # Perform static type checks with mypy
$(MYPY) --scripts-are-modules $(PACKAGE)
.PHONY: stricttypecheck
stricttypecheck: # Perform strict static type checks with mypy
$(MYPY) --scripts-are-modules --strict $(PACKAGE)
.PHONY: bandit
bandit: # Run bandit over the code
$(BANDIT) -r $(PACKAGE)
.PHONY: monkey
monkey: # Run monkeytype over the code
$(MONKEY) apply $(PACKAGE)
.PHONY: test
test: # Run the unit tests
$(TEST) $(TEST_DIR)
.PHONY: checkall
checkall: lint stricttypecheck bandit # Check all the things
##############################################################################
# Utility.
.PHONY: repl
repl: # Start a Python REPL
$(PYTHON)
.PHONY: shell
shell: # Create a shell within the virtual environment
poetry shell
.PHONY: help
help: # Display this help
@grep -Eh "^[a-z]+:.+# " $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.+# "}; {printf "%-20s %s\n", $$1, $$2}'
##############################################################################
# Housekeeping tasks.
.PHONY: housekeeping
housekeeping: # Perform some git housekeeping
git fsck
git gc --aggressive
git remote update --prune