This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
forked from njmei-brown/AFNI-Python-IO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
337 lines (298 loc) · 10 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# https://github.com/aclark4life/makefile
#
# The MIT License (MIT)
#
# Copyright (c) 2016–2020 Alex Clark
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#-------------------------------------------------------------------------------
# Default Goal
#
# https://www.gnu.org/software/make/manual/html_node/Goals.html
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
#
# By default, the goal is the first target in the makefile (not counting targets
# that start with a period). Therefore, makefiles are usually written so that the
# first target is for compiling the entire program or programs they describe. If
# the first rule in the makefile has several targets, only the first target in the
# rule becomes the default goal, not the whole list. You can manage the selection
# of the default goal from within your makefile using the .DEFAULT_GOAL variable
# (see Other Special Variables).
.DEFAULT_GOAL=usage
#-------------------------------------------------------------------------------
# Variables
# A variable is a name defined in a makefile to represent a string of text, called
# the variable's value. These values are substituted by explicit request into targets,
# prerequisites, recipes, and other parts of the makefile.
#
# https://www.gnu.org/software/make/manual/html_node/Using-Variables.html
# Flavors
# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors
COMMIT_MESSAGE = "Update"
PROJECT = project
APP = app
# https://stackoverflow.com/a/589260/185820
TMPDIR := $(shell mktemp -d)
RANDIR := $(shell openssl rand -base64 12 | sed 's/\///g')
UNAME := $(shell uname)
# http://unix.stackexchange.com/a/37316
REMOTE_BRANCHES = `git branch -a | grep remote | grep -v HEAD | grep -v master`
#-------------------------------------------------------------------------------
# Additional Concepts for this Makefile
#
# "Alias" - A new target definition that only exists to create a shorter target
# name for another target that already exists.
#
# "Multi-target Alias" - Like an "Alias", but with multiple targets.
#
# "BBB" - For backwards compatibility. Via
# https://docs.plone.org/appendices/glossary.html
#-------------------------------------------------------------------------------
# Rules
#
# A rule appears in the makefile and says when and how to remake certain files,
# called the rule's targets (most often only one per rule). It lists the other
# files that are the prerequisites of the target, and the recipe to use to
# create or update the target.
#
# https://www.gnu.org/software/make/manual/html_node/Rules.html
##########
# Django #
##########
django-init-app:
-mkdir -p $(PROJECT)/$(APP)/templates
-touch $(PROJECT)/$(APP)/templates/base.html
-django-admin startproject $(PROJECT) .
-django-admin startapp $(APP) $(PROJECT)/$(APP)
django-init-db: # PostgreSQL
-dropdb $(PROJECT)
-createdb $(PROJECT)
init-db: django-init-db # Alias
django-graph:
python manage.py graph_models $(APP) -o graph_models_$(PROJECT)_$(APP).png
django-init:
@$(MAKE) pip-install-django
@$(MAKE) django-init-db
@$(MAKE) django-init-app
@$(MAKE) django-up-settings
git add $(PROJECT)
git add manage.py
@$(MAKE) commit-push
django-migrate:
python manage.py migrate
django-migrations-default:
python manage.py makemigrations $(APP)
git add $(PROJECT)/$(APP)/migrations/*.py
django-serve-default:
python manage.py runserver 0.0.0.0:8000
django-test:
python manage.py test
django-up-settings:
echo "STATIC_ROOT = 'static'" >> $(PROJECT)/settings.py
echo "ALLOWED_HOSTS = ['*']" >> $(PROJECT)/settings.py
echo "AUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },]" >> $(PROJECT)/settings.py
echo "import dj_database_url; DATABASES = { 'default': dj_database_url.config(default=os.environ.get( 'DATABASE_URL', 'postgres://%s:%s@%s:%s/%s' % (os.environ.get('DB_USER', ''), os.environ.get('DB_PASS', ''), os.environ.get('DB_HOST', 'localhost'), os.environ.get('DB_PORT', '5432'), os.environ.get('DB_NAME', 'project_app'))))}" >> $(PROJECT)/settings.py
django-shell:
python manage.py shell
django-static:
python manage.py collectstatic --noinput
django-su:
python manage.py createsuperuser
django-loaddata-default:
python manage.py loaddata
django-yapf:
-yapf -i *.py
-yapf -i $(PROJECT)/*.py
-yapf -i $(PROJECT)/$(APP)/*.py
django-wc:
-wc -l *.py
-wc -l $(PROJECT)/*.py
-wc -l $(PROJECT)/$(APP)/*.py
graph: django-graph
migrate: django-migrate # Alias
migrations: django-migrations # Alias
static: django-static # Alias
su: django-su # Alias
test: django-test # Alias
loaddata: django-loaddata # Alias
##########
# Drupal #
##########
drupal-init-composer-8:
composer create-project drupal/recommended-project $(RANDIR) --no-interaction
drupal-init-docksal-7:
git clone https://github.com/docksal/boilerplate-drupal7.git d7
cd d7; fin init
drupal-init-docksal-8:
git clone https://github.com/docksal/boilerplate-drupal8.git d8
cd d8; fin init
d7: drupal-init-docksal-7 # Alias
d8: drupal-init-docksal-8 # Alias
#######
# Git #
#######
git-ignore:
echo ".Python\nbin/\ninclude/\nlib/\n.vagrant/\n" >> .gitignore
git add .gitignore
$(MAKE) commit-push
git-init:
git init
hub create $(RANDDIR)
hub browse
git-branches:
-for i in $(REMOTE_BRANCHES) ; do \
git checkout -t $$i ; done
git-prune:
git remote update origin --prune
git-commit:
git commit -a -m $(COMMIT_MESSAGE)
git-commit-edit:
git commit -a
git-push:
git push
git-push-up:
git push --set-upstream origin master
commit: git-commit # Alias
ce: commit-edit # Alias
cp: commit-push # Alias
push: git-push # Alias
p: push # Alias
commit-push: git-commit git-push # Multi-target Alias
commit-push-up: git-commit git-push-up # Multi-target Alias
commit-edit: git-commit-edit git-push # Multi-target Alias
git-commit-auto-push: commit-push # BBB
git-commit-edit-push: commit-edit-push # BBB
########
# Misc #
########
rand:
@openssl rand -base64 12 | sed 's/\///g'
r: rand # Alias
readme:
echo "Creating README.rst"
@echo $(PROJECT) > README.rst
@echo ================================================================================ >> README.rst
echo "Done."
git add README.rst
@$(MAKE) commit-push
review:
ifeq ($(UNAME), Darwin)
@open -a $(EDITOR) `find $(PROJECT) -name \*.py | grep -v __init__.py | grep -v migrations`\
`find $(PROJECT) -name \*.html` `find $(PROJECT) -name \*.js`
else
@echo "Unsupported"
endif
list-targets:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F:\
'/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}'\
| sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs | tr ' ' '\n' | awk\
'{print "make "$$0}' | less # http://stackoverflow.com/a/26339924
help: list-targets # Alias
h: list-targets # Alias
usage:
@echo "Project Makefile"
@echo "Usage:\n"
@echo "\tmake <target>\n"
@echo "Help:\n"
@echo "\tmake help"
make:
git add Makefile
@$(MAKE) commit-push-up
deploy-default:
eb deploy
d: deploy # Alias
#######
# Pip #
#######
pip-freeze-default:
pip freeze | sort > $(TMPDIR)/requirements.txt
mv -f $(TMPDIR)/requirements.txt .
pip-install:
pip install -r requirements.txt
pip-install-test:
pip install -r requirements-test.txt
pip-install-django:
@echo "Django\ndj-database-url\npsycopg2-binary\n" > requirements.txt
@$(MAKE) pip-install
@$(MAKE) freeze
-git add requirements.txt
-@$(MAKE) commit-push-up
pip-install-sphinx:
echo "Sphinx\n" > requirements.txt
$(MAKE) pip-install
pip-upgrade-default:
cat requirements.txt | awk -F \= '{print $1}' > $(TMPDIR)/requirements.txt
mv -f $(TMPDIR)/requirements.txt .
pip install -U -r requirements.txt
$(MAKE) pip-freeze
freeze: pip-freeze # Alias
##########
# Python #
##########
python-serve:
@echo "\n\tServing HTTP on http://0.0.0.0:8000\n"
python -m http.server
python-virtualenv-2-6:
virtualenv --python=python2.6 .
python-virtualenv-2-7:
virtualenv --python=python2.7 .
python-virtualenv-3-7:
virtualenv --python=python3.7 .
python-virtualenv: python-virtualenv-3-7 # Alias
virtualenv: python-virtualenv-3-7 # Alias
virtualenv-2: python-virtualenv-2-7 # Alias
serve: python-serve # Alias
##########
# Sphinx #
##########
sphinx-build:
sphinx-build -b html -d _build/doctrees . _build/html
sphinx-init:
$(MAKE) pip-install-sphinx
sphinx-quickstart -q -p $(PROJECT) -a $(USER) -v 0.0.1 $(RANDIR)
mv $(RANDIR)/* .
rmdir $(RANDIR)
sphinx-serve:
cd _build/html;python -m http.server
###########
# Vagrant #
###########
vagrant-init:
vagrant init ubuntu/trusty64
git add Vagrantfile
$(MAKE) git-push-up
$(MAKE) vagrant-up
vagrant-up:
vagrant up --provider virtualbox
vagrant: vagrant-init # Alias
vm: vagrant-init # Alias
#-------------------------------------------------------------------------------
# Overrides
#
# https://www.gnu.org/software/make/manual/html_node/Overriding-Makefiles.html
#
# https://stackoverflow.com/a/49804748
%: %-default
@ true
#PROJECT = project
#APP = app
.DEFAULT_GOAL=commit-push
install: pip-install
run:
python PLACE-2.6.py