-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
161 lines (136 loc) · 5.71 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
# This ensures that we can call `make <target>` even if `<target>` exists as a file or
# directory.
.PHONY: docs help
# Exports all variables defined in the makefile available to scripts
.EXPORT_ALL_VARIABLES:
# Create .env file if it does not already exist
ifeq (,$(wildcard .env))
$(shell touch .env)
endif
# Create poetry env file if it does not already exist
ifeq (,$(wildcard ${HOME}/.poetry/env))
$(shell mkdir ${HOME}/.poetry)
$(shell touch ${HOME}/.poetry/env)
endif
# Includes environment variables from the .env file
include .env
# Set gRPC environment variables, which prevents some errors with the `grpcio` package
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
# Ensure that `pipx` and `poetry` will be able to run, since `pip` and `brew` put these
# in the following folders on Unix systems
export PATH := ${HOME}/.local/bin:/opt/homebrew/bin:$(PATH)
# Prevent DBusErrorResponse during `poetry install`
#(see https://stackoverflow.com/a/75098703 for more information)
export PYTHON_KEYRING_BACKEND := keyring.backends.null.Keyring
help:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
install: ## Install dependencies
@echo "Installing the 'domsdatabasen' project..."
@$(MAKE) --quiet install-brew
@$(MAKE) --quiet install-gpg
@$(MAKE) --quiet generate-gpg-key
@$(MAKE) --quiet install-pipx
@$(MAKE) --quiet install-poetry
@$(MAKE) --quiet install-dependencies
@$(MAKE) --quiet setup-environment-variables
@$(MAKE) --quiet setup-git
@$(MAKE) --quiet add-repo-to-git
@echo "Installed the 'domsdatabasen' project. You can now activate your virtual environment with 'source .venv/bin/activate'."
@echo "Note that this is a Poetry project. Use 'poetry add <package>' to install new dependencies and 'poetry remove <package>' to remove them."
install-brew:
@if [ $$(uname) = "Darwin" ] && [ "$(shell which brew)" = "" ]; then \
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
echo "Installed Homebrew."; \
fi
install-gpg:
@if [ "$(shell which gpg)" = "" ] || [ "$(shell which gpg-agent)" = "" ]; then \
uname=$$(uname); \
case $${uname} in \
(*Linux*) distro=$$(lsb_release -i | sed 's/Distributor ID:\t//'); \
case $${distro} in \
(*Ubuntu*) installCmd='apt-get update && apt-get install -y gnupg gpg-agent'; ;; \
(*CentOS*) installCmd='yum install -y gnupg gpg-agent'; ;; \
(*) echo 'Could not automatically install gnupg for the $${distro} distribution. Please manually install gnupg and try again.'; exit 2; ;; \
esac; ;; \
(*Darwin*) installCmd='brew install gnupg pinentry-mac'; ;; \
(*) echo 'Could not automatically install gnupg. Please manually install gnupg and try again.'; exit 2; ;; \
esac; \
"$${installCmd}"; \
echo "Installed gnupg."; \
fi
generate-gpg-key:
@if [ "$(shell gpg --list-secret-keys --keyid-format=long | grep sec | sed -E 's/.*\/([^ ]+).*/\1/')" = "" ]; then \
echo "Generating a new GPG key - please follow the prompts."; \
gpg --full-generate-key; \
echo "Generated a new GPG key. Remember to register it to Github at https://github.com/settings/gpg/new, where you add the key generated by running 'gpg --armor --export <key>'"; \
fi
install-pipx:
@if [ "$(shell which pipx)" = "" ]; then \
uname=$$(uname); \
case $${uname} in \
(*Darwin*) installCmd='brew install pipx'; ;; \
(*CYGWIN*) installCmd='py -3 -m pip install --upgrade --user pipx'; ;; \
(*) installCmd='python3 -m pip install --upgrade --user pipx'; ;; \
esac; \
$${installCmd}; \
pipx ensurepath --force; \
echo "Installed pipx."; \
fi
install-poetry:
@if [ ! "$(shell poetry --version)" = "Poetry (version 1.7.1)" ]; then \
python3 -m pip uninstall -y poetry poetry-core poetry-plugin-export; \
pipx install --force poetry==1.7.1; \
echo "Installed Poetry."; \
fi
install-dependencies:
@poetry env use python3.10 && poetry install
setup-environment-variables:
@poetry run python src/scripts/fix_dot_env_file.py
setup-environment-variables-non-interactive:
@poetry run python src/scripts/fix_dot_env_file.py --non-interactive
setup-git:
@git config --global init.defaultBranch main
@git init
@git config --local user.name ${GIT_NAME}
@git config --local user.email ${GIT_EMAIL}
@if [ ${GPG_KEY_ID} = "" ]; then \
echo "No GPG key ID specified. Skipping GPG signing."; \
git config --local commit.gpgsign false; \
else \
git config --local commit.gpgsign true; \
git config --local user.signingkey ${GPG_KEY_ID}; \
echo "Signed with GPG key ID ${GPG_KEY_ID}."; \
fi
@poetry run pre-commit install
add-repo-to-git:
@export GPG_TTY=$(tty)
@gpgconf --kill gpg-agent
@if [ ! "$(shell git status --short)" = "" ] && [ "$(shell git log --all)" = "" ]; then \
git add .; \
git commit --quiet -m "Initial commit"; \
fi
@if [ "$(shell git remote)" = "" ]; then \
git remote add origin [email protected]:alexandrainst/domsdatabasen.git; \
fi
docs: ## Generate documentation
@poetry run pdoc --docformat google src/domsdatabasen -o docs
@echo "Saved documentation."
view-docs: ## View documentation
@echo "Viewing API documentation..."
@uname=$$(uname); \
case $${uname} in \
(*Linux*) openCmd='xdg-open'; ;; \
(*Darwin*) openCmd='open'; ;; \
(*CYGWIN*) openCmd='cygstart'; ;; \
(*) echo 'Error: Unsupported platform: $${uname}'; exit 2; ;; \
esac; \
"$${openCmd}" docs/domsdatabasen.html
test:
@poetry run pytest tests/scraper ; \
poetry run pytest tests/processor ; \
docker: ## Build Docker image and run container
@docker build -t domsdatabasen .
@docker run -it --rm domsdatabasen
tree: ## Print directory tree
@tree -a --gitignore -I .git .