forked from open-engines/fuzzy_dates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
151 lines (125 loc) · 5.67 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
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c
all: help
.PHONY: help ## Print this help
help: about
@printf '\n\033[1;36m%-12s\033[0m %s\n────────────────────────\n' "Command" "Description"
@awk 'BEGIN {FS = " *## |: "}; /^.PHONY: /{printf "\033[1;36m%-15s\033[0m %s\n", $$2, $$3}' $(MAKEFILE_LIST)
.PHONY: about ## Describe this tool
NAME = 'fuzzy_parser'
TITLE = 'Python Parser for Abbreviated Dates'
about:
@echo $(NAME) -- $(TITLE)
#
# Superuser rules
#
.PHONY: utilities ## Install utilities required for the tool (Run with sudo)
DISTRIBUTION_CODENAME := $(shell awk -F'=' '/UBUNTU_CODENAME/{print $$2}' /etc/os-release)
SUPPORTED_DISTRIBUTIONS := focal jammy
ifeq ($(filter $(DISTRIBUTION_CODENAME),$(SUPPORTED_DISTRIBUTIONS)),)
$(warning Terminating on detection of unsupported Ubuntu distribution: $(DISTRIBUTION_CODENAME). \
Supported distibutions are: $(SUPPORTED_DISTRIBUTIONS))
endif
utilities: packages /usr/bin/swipl
.PHONY: packages ## Install packages required for the tool (Run with sudo)
packages:
@sudo apt-get update
@apt-get -qqy install git bumpversion build-essential software-properties-common jq python3-venv python3-pip
PROLOG_LIST_FILE = /etc/apt/sources.list.d/swi-prolog-ubuntu-stable-$(DISTRIBUTION_CODENAME).list
/usr/bin/swipl: $(PROLOG_LIST_FILE)
@apt-get -qqy install swi-prolog-nox
@touch $@
$(PROLOG_LIST_FILE):
@apt-add-repository -y ppa:swi-prolog/stable
@touch $@
ARCH=$(shell dpkg --print-architecture)
GH_KEYRING = /usr/share/keyrings/githubcli-archive-keyring.gpg
GH_LIST = "deb [arch=$(ARCH) signed-by=$(GH_KEYRING)] https://cli.github.com/packages stable main"
GH_LIST_FILE = /etc/apt/sources.list.d/github-cli.list
/usr/bin/gh: $(GH_LIST_FILE)
@apt-get install $(notdir $@) -y
@touch $@
$(GH_LIST_FILE): $(GH_KEYRING)
@echo $(GH_LIST) | sudo tee $(GH_LIST_FILE) > /dev/null
@sudo apt-get update
@touch $@
$(GH_KEYRING):
@curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=$(GH_KEYRING)
@touch $@
/usr/bin/%: # Install packages from default repo
@apt-get -qqy install $(notdir $@)
@touch $@
.PHONY: clean-utilities ## Integration test with - sudo make clean-utilities utilities && make clean && make test
clean-utilities:
@apt-get --purge -qqy autoremove swi-prolog-nox bumpversion python3-venv python3-pip
@add-apt-repository --remove -y ppa:swi-prolog/stable
@rm -f /etc/apt/sources.list.d/swi-prolog-ubuntu-stable-$(DISTRIBUTION_CODENAME).list
@apt-get -y autoremove
#
# Unprivileged user rules
#
.PHONY: synchronize ## Synchronize the local repository: Switch to the main branch, fetch changes & delete merged branches
synchronize: /usr/bin/git
@git checkout master && git pull && git branch --merged | egrep -v "(^\*|master)" | xargs -r git branch -d || exit 0
.PHONY: test ## Run the test suite
VENV = venv
PYTHON_PATH = $(VENV)/bin
PYTHON = $(PYTHON_PATH)/python3
test: $(PYTHON_PATH)/pytest install parser
@$(PYTHON) -m pytest -p no:cacheprovider
$(PYTHON_PATH)/%: $(VENV)/bin/activate # Install packages from default repo
@$(PYTHON) -m pip install $(notdir $@)
$(VENV)/bin/activate:
@test -d $(VENV) || python3 -m venv $(VENV)
@$(PYTHON) -m pip install --upgrade pip
@touch $@
.PHONY: install ## Install this library
install: $(VENV)/bin/fuzzy_parser
$(VENV)/bin/fuzzy_parser:
@$(PYTHON) -m pip install --use-pep517 .
@touch $@
.PHONY: parser ## Install the latest parser release. Override parser version with make VERSION=v0.0.? parser
PACK_PATH = ${HOME}/.local/share/swi-prolog/pack
parser: $(PACK_PATH)/abbreviated_dates
$(PACK_PATH)/abbreviated_dates: $(PACK_PATH)/tap $(PACK_PATH)/date_time
@: $${VERSION:=$$(curl --silent 'https://api.github.com/repos/crgz/abbreviated_dates/releases/latest'|jq -r .tag_name)} ;\
REMOTE=https://github.com/crgz/abbreviated_dates/archive/$$VERSION.zip ;\
swipl -qg "pack_remove(abbreviated_dates),pack_install('$$REMOTE',[interactive(false)]),halt(0)" -t 'halt(1)'
@touch $@
$(PACK_PATH)/%:
@swipl -qg "pack_install('$(notdir $@)',[interactive(false)]),halt"
@touch $@
.PHONY: bump ## Increase the version number
bump: export GH_TOKEN ?= $(shell secret-tool lookup user ${USER} domain github.com) # Overridable
bump: /usr/bin/bumpversion committer
@git push -d origin release || true
@git checkout -b release
@bumpversion --allow-dirty --list patch
@git push origin release
@gh pr create -B main -H release --fill
@gh pr merge -m --auto --delete-branch
.PHONY: release ## Release a new version (Requires unprotected main branch or special token to be used from Github Actions)
TOKEN ?= $(shell secret-tool lookup user ${USER} domain pypi.org ) # Overridable
release: build
@$(PYTHON) -m twine upload --skip-existing -u "__token__" -p $(TOKEN) dist/*
.PHONY: build ## Build and check distribution packages
build: $(PYTHON_PATH)/build $(PYTHON_PATH)/twine
@$(PYTHON) -m build --sdist --wheel
@$(PYTHON) -m twine check dist/*
.PHONY: clean ## Remove debris from build target
clean: /usr/bin/swipl uninstall
@rm -rfd fuzzy_parser.egg-info/ dist/ .pytest_cache/ __pycache__
@rm -rfd $(VENV)
@swipl -g "(member(P,[date_time,tap]),pack_property(P,library(P)),pack_remove(P),fail);true,halt"
.PHONY: uninstall ## Uninstall the library
uninstall: $(PYTHON_PATH)/$(NAME)
$(PYTHON) -m pip uninstall -y $(NAME)
@swipl -g "(member(P,[abbreviated_dates]),pack_property(P,library(P)),pack_remove(P),fail);true,halt"
.PHONY: store-token ## Store the Github token
store-token:
@secret-tool store --label='github.com/crgz' user ${USER} domain github.com
.PHONY: committer ## config committer credentials
committer:
@git config --global user.email "conrado.rgz@gmail.com"
@git config --global user.name "Conrado Rodriguez"
@git config pull.ff only