This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
167 lines (129 loc) · 5.94 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
156
157
158
159
160
161
162
163
164
165
166
167
PACKAGE_NAME := unstructured_api_tools
PIP_VERSION := 22.2.1
CURRENT_DIR := $(shell pwd)
.PHONY: help
help: Makefile
@sed -n 's/^\(## \)\([a-zA-Z]\)/\2/p' $<
###########
# Install #
###########
## install: installs all base and test requirements
.PHONY: install
install: install-base install-test
.PHONY: install-ci
install-ci: install
.PHONY: install-base
install-base:
python3 -m pip install pip==${PIP_VERSION}
pip install -r requirements/base.txt
.PHONY: install-test
install-test:
pip install -r requirements/test.txt
## pip-compile: compiles all base and test requirements
.PHONY: pip-compile
pip-compile:
# NOTE(crag): you have to manually install pip-tools for now to run this.
# There is a better way to do this with a pinned pip-compile version and a venv.
bash -c "pip-compile -h >/dev/null || { echo please run \'pip install pip-tools\' and then rerun this command; exit 1; }"
pip-compile --upgrade -o requirements/base.txt
pip-compile --upgrade -o requirements/test.txt requirements/base.txt requirements/test.in
## install-project-local: install unstructured_api_tools into your local python environment
.PHONY: install-project-local
install-project-local: install
# MAYBE TODO: fail if already exists?
pip install -e .
## uninstall-project-local: uninstall unstructured_api_tools from your local python environment
.PHONY: uninstall-project-local
uninstall-project-local:
pip uninstall ${PACKAGE_NAME}
#################
# Test and Lint #
#################
## run-jupyter-test-notebooks: starts jupyter, allows execution of test notebooks
.PHONY: run-jupyter-test-notebooks
run-jupyter-test-notebooks:
PYTHONPATH=$(realpath .)/test_unstructured_api_tools/pipeline-test-project/ JUPYTER_PATH=$(realpath .)/test_unstructured_api_tools/pipeline-test-project/ jupyter-notebook --NotebookApp.token='' --NotebookApp.password=''
## tidy-test-notebooks: execute notebooks and remove metadata
.PHONY: tidy-test-notebooks
tidy-test-notebooks:
PYTHONPATH=. ./test_unstructured_api_tools/pipeline-test-project/scripts/check-and-format-notebooks.py
## generate-test-api: generates FastAPIs under ./test_unstructured_api_tools/pipeline-test-project
.PHONY: generate-test-api
generate-test-api:
# generates FastAPI API's from notebooks in the test project ./test_unstructured_api_tools/pipeline-test-project
PYTHONPATH=. PIPELINE_FAMILY_CONFIG=test_unstructured_api_tools/pipeline-test-project/preprocessing-pipeline-family.yaml \
python3 ./unstructured_api_tools/cli.py convert-pipeline-notebooks \
--input-directory ./test_unstructured_api_tools/pipeline-test-project/pipeline-notebooks \
--output-directory ./test_unstructured_api_tools/pipeline-test-project/prepline_test_project/api
## api-check-test: verifies auto-generated pipeline APIs match the existing ones
.PHONY: api-check-test
api-check-test:
PYTHONPATH=. PACKAGE_NAME=prepline_test_project ./test_unstructured_api_tools/pipeline-test-project/scripts/test-doc-pipeline-apis-consistent.sh
## test: runs all unittests
.PHONY: test
test:
PYTHONPATH=.:./test_unstructured_api_tools/pipeline-test-project pytest test_${PACKAGE_NAME} --cov=${PACKAGE_NAME} --cov=prepline_test_project --cov-report term-missing -vvv
## check: runs linters (includes tests)
.PHONY: check
check: check-src check-tests check-version
## check-src: runs linters (source only, no tests)
.PHONY: check-src
check-src:
black --line-length 100 ${PACKAGE_NAME} --check
flake8 ${PACKAGE_NAME}
mypy ${PACKAGE_NAME} --ignore-missing-imports --install-types --non-interactive
autoflake --remove-unused-variables --remove-duplicate-keys --expand-star-imports \
--remove-all-unused-imports -cd -r ${PACKAGE_NAME} test_${PACKAGE_NAME} \
--exclude test_${PACKAGE_NAME}/pipeline-test-project
.PHONY: check-tests
check-tests:
black --line-length 100 test_${PACKAGE_NAME} --check --exclude test_${PACKAGE_NAME}/pipeline-test-project
flake8 test_${PACKAGE_NAME} --exclude test_${PACKAGE_NAME}/pipeline-test-project/prepline_test_project/api
## check-scripts: run shellcheck
.PHONY: check-scripts
check-scripts:
# Fail if any of these files have warnings
scripts/shellcheck.sh
## check-version: run check to ensure version in CHANGELOG.md matches version in package
.PHONY: check-version
check-version:
# Fail if syncing version would produce changes
scripts/version-sync.sh -c \
-f ${PACKAGE_NAME}/__version__.py semver
## tidy: run black
.PHONY: tidy
tidy: tidy-black tidy-autoflake
tidy-autoflake:
autoflake --remove-unused-variables --remove-duplicate-keys --expand-star-imports \
--remove-all-unused-imports -i -r ${PACKAGE_NAME} test_${PACKAGE_NAME} \
--exclude test_${PACKAGE_NAME}/pipeline-test-project
tidy-black:
black --line-length 100 ${PACKAGE_NAME}
black --line-length 100 test_${PACKAGE_NAME} --exclude test_${PACKAGE_NAME}/pipeline-test-project
## version-sync: update __version__.py with most recent version from CHANGELOG.md
.PHONY: version-sync
version-sync:
scripts/version-sync.sh \
-f ${PACKAGE_NAME}/__version__.py semver
.PHONY: check-coverage
check-coverage:
# TODO(crag): add coverage check for test_unstructured_api_tools/pipeline-test-project/prepline_test_project/api/
coverage report --fail-under=95
##########
# Docker #
##########
# Docker targets are provided for convenience only and are not required in a standard development environment
DOCKER_IMAGE ?= unstructured-api-tools:dev
.PHONY: docker-build
docker-build:
PIP_VERSION=${PIP_VERSION} DOCKER_IMAGE_NAME=${DOCKER_IMAGE} ./scripts/docker-build.sh
.PHONY: docker-start-bash
docker-start-bash:
docker run -ti --rm ${DOCKER_IMAGE}
.PHONY: docker-test
docker-test: docker-build
docker run --rm \
-v ${CURRENT_DIR}/test_unstructured_api_tools:/home/test_unstructured_api_tools \
-v ${CURRENT_DIR}/unstructured_api_tools:/home/unstructured_api_tools \
$(DOCKER_IMAGE) \
bash -c "make test"