11VIRTUAL_ENV ?= venv
2+ VIRTUAL_ENV_BIN = $(VIRTUAL_ENV ) /bin
3+ ifeq ($(OS ) , Windows_NT)
4+ VIRTUAL_ENV_BIN = $(VIRTUAL_ENV)/Scripts
5+ endif
26NODE_BIN = node_modules/.bin
37SOURCE_DIRS = adhocracy-plus apps tests
48ARGUMENTS =$(filter-out $(firstword $(MAKECMDGOALS ) ) , $(MAKECMDGOALS ) )
59
6- # for mac os gsed is needed (brew install gnu-sed and brew install gsed)
7- SED = sed
8- ifneq (, $(shell command -v gsed;) )
9- SED = gsed
10+ ifeq ($(OS ) , Windows_NT)
11+
12+ else
13+ # for mac os gsed is needed (brew install gnu-sed and brew install gsed)
14+ SED = sed
15+ ifneq (, $(shell command -v gsed;))
16+ SED = gsed
17+ endif
1018endif
1119
1220.PHONY : all
@@ -59,53 +67,102 @@ help:
5967install :
6068 npm install --no-save
6169 npm run build
62- if [ ! -f $( VIRTUAL_ENV) /bin/python3 ]; then python3 -m venv $( VIRTUAL_ENV) ; fi
63- $(VIRTUAL_ENV ) /bin/python -m pip install --upgrade -r requirements/dev.txt
64- $(VIRTUAL_ENV ) /bin/python manage.py migrate
70+ ifeq ($(OS ) , Windows_NT)
71+ @make copy-windows-specific-magic-files
72+ @make setup-windows-specific-local-config
73+ @make install-windows-specific-tools
74+ @powershell -Command "if (!(Test-Path $(VIRTUAL_ENV_BIN)/python.exe)) { python -m venv $(VIRTUAL_ENV) }"
75+ else
76+ if [ ! -f $(VIRTUAL_ENV_BIN)/python3 ]; then python3 -m venv $(VIRTUAL_ENV); fi
77+ endif
78+ $(VIRTUAL_ENV_BIN)/python -m pip install --upgrade pip
79+ $(VIRTUAL_ENV_BIN)/python -m pip install --upgrade -r requirements/dev.txt
80+ $(VIRTUAL_ENV_BIN)/python manage.py migrate
81+
82+ .PHONY : copy-windows-specific-magic-files
83+ copy-windows-specific-magic-files :
84+ ifeq ($(OS ) , Windows_NT)
85+ @powershell -Command " \
86+ $$files = @('magic1.dll', 'libgnurx-0.dll', 'magic.mgc'); \
87+ $$missing = $$files | Where-Object { !(Test-Path \"C:\Windows\System32\$$_\") }; \
88+ if ($$missing.Count -gt 0) { \
89+ Start-Process wt.exe -ArgumentList 'powershell -NoProfile -ExecutionPolicy Bypass -File \"$(CURDIR)\windows_specific\copy-files-to-system32.ps1\"' -Verb RunAs -Wait \
90+ } else { \
91+ Write-Host "`nAll magic files already exist. Skipping copy." -ForegroundColor Green \
92+ }"
93+ endif
94+
95+ .PHONY : setup-windows-specific-local-config
96+ setup-windows-specific-local-config :
97+ ifeq ($(OS ) , Windows_NT)
98+ @powershell -Command " \
99+ powershell -NoProfile -ExecutionPolicy Bypass -File \"$(CURDIR)\windows_specific\setup-local-config.ps1\" -Verb RunAs; \
100+ "
101+ endif
102+
103+ .PHONY : install-windows-specific-tools
104+ install-windows-specific-tools :
105+ ifeq ($(OS ) , Windows_NT)
106+ @powershell -Command " \
107+ powershell -NoProfile -ExecutionPolicy Bypass -File \"$(CURDIR)\windows_specific\install-tools.ps1\" -Verb RunAs; \
108+ "
109+ endif
65110
66111.PHONY : clean
67112clean :
113+ ifeq ($(OS ) , Windows_NT)
114+ @powershell -Command "if (Test-Path package-lock.json) { Remove-Item package-lock.json }"
115+ @powershell -Command "if (Test-Path node_modules) { Remove-Item node_modules -Recurse -Force }"
116+ @powershell -Command "if (Test-Path venv) { Remove-Item venv -Recurse -Force }"
117+ else
68118 if [ -f package-lock.json ]; then rm package-lock.json; fi
69119 if [ -d node_modules ]; then rm -rf node_modules; fi
70120 if [ -d venv ]; then rm -rf venv; fi
121+ endif
71122
72123.PHONY : fixtures
73124fixtures :
74- $(VIRTUAL_ENV ) /bin /python manage.py loaddata adhocracy-plus/fixtures/site-dev.json
75- $(VIRTUAL_ENV ) /bin /python manage.py loaddata adhocracy-plus/fixtures/users-dev.json
76- $(VIRTUAL_ENV ) /bin /python manage.py loaddata adhocracy-plus/fixtures/orga-dev.json
125+ $(VIRTUAL_ENV_BIN ) /python manage.py loaddata adhocracy-plus/fixtures/site-dev.json
126+ $(VIRTUAL_ENV_BIN ) /python manage.py loaddata adhocracy-plus/fixtures/users-dev.json
127+ $(VIRTUAL_ENV_BIN ) /python manage.py loaddata adhocracy-plus/fixtures/orga-dev.json
77128
78129.PHONY : server
79130server :
80- $(VIRTUAL_ENV ) /bin /python manage.py runserver 8004
131+ $(VIRTUAL_ENV_BIN ) /python manage.py runserver 8004
81132
82133.PHONY : watch
83134watch :
135+ ifeq ($(OS ) , Windows_NT)
136+ trap 'kill %1' KILL; \
137+ npm run watch & \
138+ $(VIRTUAL_ENV)\Scripts\python manage.py runserver 8004
139+ else
84140 trap 'kill %1' KILL; \
85141 npm run watch & \
86142 $(VIRTUAL_ENV)/bin/python manage.py runserver 8004
143+ endif
87144
88145.PHONY : background
89146background :
90- $(VIRTUAL_ENV ) /bin /python manage.py process_tasks
147+ $(VIRTUAL_ENV_BIN ) /python manage.py process_tasks
91148
92149.PHONY : test
93150test :
94- $(VIRTUAL_ENV ) /bin /py.test --reuse-db
151+ $(VIRTUAL_ENV_BIN ) /py.test --reuse-db
95152 npm run testNoCov
96153
97154.PHONY : pytest
98155pytest :
99- $(VIRTUAL_ENV ) /bin /py.test --reuse-db
156+ $(VIRTUAL_ENV_BIN ) /py.test --reuse-db
100157
101158.PHONY : pytest-lastfailed
102159pytest-lastfailed :
103- $(VIRTUAL_ENV ) /bin /py.test --reuse-db --last-failed
160+ $(VIRTUAL_ENV_BIN ) /py.test --reuse-db --last-failed
104161
105162.PHONY : pytest-clean
106163pytest-clean :
107164 if [ -f test_db.sqlite3 ]; then rm test_db.sqlite3; fi
108- $(VIRTUAL_ENV ) /bin /py.test
165+ $(VIRTUAL_ENV_BIN ) /py.test
109166
110167.PHONY : jstest
111168jstest :
@@ -125,55 +182,110 @@ jstest-updateSnapshots:
125182
126183.PHONY : coverage
127184coverage :
128- $(VIRTUAL_ENV ) /bin /py.test --reuse-db --cov --cov-report=html
185+ $(VIRTUAL_ENV_BIN ) /py.test --reuse-db --cov --cov-report=html
129186
130187.PHONY : lint
131188lint :
189+ ifeq ($(OS ) , Windows_NT)
190+ @powershell -Command "& { \
191+ $$EXIT_STATUS = 0; \
192+ & $(VIRTUAL_ENV_BIN)\isort.exe --diff -c $(SOURCE_DIRS); if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
193+ & $(VIRTUAL_ENV_BIN)\flake8.exe $(SOURCE_DIRS) --exclude migrations,settings; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
194+ npm run lint; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
195+ & $(VIRTUAL_ENV_BIN)\python.exe manage.py makemigrations --dry-run --check --noinput; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
196+ exit $$EXIT_STATUS; \
197+ }"
198+ else
132199 EXIT_STATUS=0; \
133- $(VIRTUAL_ENV ) /bin /isort --diff -c $(SOURCE_DIRS ) || EXIT_STATUS=$$? ; \
134- $(VIRTUAL_ENV ) /bin /flake8 $(SOURCE_DIRS ) --exclude migrations,settings || EXIT_STATUS=$$? ; \
200+ $(VIRTUAL_ENV_BIN) /isort --diff -c $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
201+ $(VIRTUAL_ENV_BIN) /flake8 $(SOURCE_DIRS) --exclude migrations,settings || EXIT_STATUS=$$?; \
135202 npm run lint || EXIT_STATUS=$$?; \
136- $(VIRTUAL_ENV ) /bin /python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$? ; \
203+ $(VIRTUAL_ENV_BIN) /python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
137204 exit $${EXIT_STATUS}
205+ endif
206+
138207
139208.PHONY : lint-quick
140209lint-quick :
210+ ifeq ($(OS ) , Windows_NT)
211+ @powershell -Command "& { \
212+ $$EXIT_STATUS=0; \
213+ npm run lint-staged; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
214+ & $(VIRTUAL_ENV_BIN)\python.exe manage.py makemigrations --dry-run --check --noinput; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
215+ exit $$EXIT_STATUS; \
216+ }"
217+ else
141218 EXIT_STATUS=0; \
142219 npm run lint-staged || EXIT_STATUS=$$?; \
143- $(VIRTUAL_ENV ) /bin /python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$? ; \
220+ $(VIRTUAL_ENV_BIN) /python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
144221 exit $${EXIT_STATUS}
222+ endif
145223
146224.PHONY : lint-js-fix
147225lint-js-fix :
226+ ifeq ($(OS ) , Windows_NT)
227+ @powershell -Command "& { \
228+ $$EXIT_STATUS=0; \
229+ npm run lint-fix; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
230+ exit $$EXIT_STATUS; \
231+ }"
232+ else
148233 EXIT_STATUS=0; \
149234 npm run lint-fix || EXIT_STATUS=$$?; \
150235 exit $${EXIT_STATUS}
236+ endif
151237
152238# Use with caution, the automatic fixing might produce bad results
153239.PHONY : lint-html-fix
154240lint-html-fix :
241+ ifeq ($(OS ) , Windows_NT)
242+ @powershell -Command "& { \
243+ $$EXIT_STATUS=0; \
244+ & $(VIRTUAL_ENV_BIN)\djlint.exe $(ARGUMENTS) --reformat --profile=django; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
245+ exit $$EXIT_STATUS; \
246+ }"
247+ else
155248 EXIT_STATUS=0; \
156- $(VIRTUAL_ENV ) /bin /djlint $(ARGUMENTS ) --reformat --profile=django || EXIT_STATUS=$$? ; \
249+ $(VIRTUAL_ENV_BIN) /djlint $(ARGUMENTS) --reformat --profile=django || EXIT_STATUS=$$?; \
157250 exit $${EXIT_STATUS}
251+ endif
158252
159253.PHONY : lint-html-files
160254lint-html-files :
255+ ifeq ($(OS ) , Windows_NT)
256+ @powershell -Command "& { \
257+ $$EXIT_STATUS=0; \
258+ & $(VIRTUAL_ENV_BIN)\djlint.exe $(ARGUMENTS) --profile=django --ignore=H006,H030,H031,H037,T002; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
259+ exit $$EXIT_STATUS; \
260+ }"
261+ else
161262 EXIT_STATUS=0; \
162- $(VIRTUAL_ENV ) /bin /djlint $(ARGUMENTS ) --profile=django --ignore=H006,H030,H031,H037,T002 || EXIT_STATUS=$$? ; \
263+ $(VIRTUAL_ENV_BIN) /djlint $(ARGUMENTS) --profile=django --ignore=H006,H030,H031,H037,T002 || EXIT_STATUS=$$?; \
163264 exit $${EXIT_STATUS}
265+ endif
164266
165267.PHONY : lint-python-files
166268lint-python-files :
269+ ifeq ($(OS ) , Windows_NT)
270+ @powershell -Command "& { \
271+ $$EXIT_STATUS=0; \
272+ & $(VIRTUAL_ENV_BIN)\black.exe $(ARGUMENTS); if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
273+ & $(VIRTUAL_ENV_BIN)\isort.exe $(ARGUMENTS) --filter-files; if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
274+ & $(VIRTUAL_ENV_BIN)\flake8.exe $(ARGUMENTS); if ($$LASTEXITCODE -ne 0) { $$EXIT_STATUS = $$LASTEXITCODE }; \
275+ exit $$EXIT_STATUS; \
276+ }"
277+ else
167278 EXIT_STATUS=0; \
168- $(VIRTUAL_ENV ) /bin /black $(ARGUMENTS ) || EXIT_STATUS=$$? ; \
169- $(VIRTUAL_ENV ) /bin /isort $(ARGUMENTS ) --filter-files || EXIT_STATUS=$$? ; \
170- $(VIRTUAL_ENV ) /bin /flake8 $(ARGUMENTS ) || EXIT_STATUS=$$? ; \
279+ $(VIRTUAL_ENV_BIN) /black $(ARGUMENTS) || EXIT_STATUS=$$?; \
280+ $(VIRTUAL_ENV_BIN) /isort $(ARGUMENTS) --filter-files || EXIT_STATUS=$$?; \
281+ $(VIRTUAL_ENV_BIN) /flake8 $(ARGUMENTS) || EXIT_STATUS=$$?; \
171282 exit $${EXIT_STATUS}
283+ endif
172284
173285.PHONY : po
174286po :
175- $(VIRTUAL_ENV ) /bin /python manage.py makemessages --all --no-obsolete -d django --extension html,email,py --ignore ' $(CURDIR)/node_modules/adhocracy4/adhocracy4/*'
176- $(VIRTUAL_ENV ) /bin /python manage.py makemessages --all --no-obsolete -d djangojs --ignore ' $(VIRTUAL_ENV)/*' --ignore ' $(CURDIR)/node_modules/dsgvo-video-embed/dist/*'
287+ $(VIRTUAL_ENV_BIN ) /python manage.py makemessages --all --no-obsolete -d django --extension html,email,py --ignore ' $(CURDIR)/node_modules/adhocracy4/adhocracy4/*'
288+ $(VIRTUAL_ENV_BIN ) /python manage.py makemessages --all --no-obsolete -d djangojs --ignore ' $(VIRTUAL_ENV)/*' --ignore ' $(CURDIR)/node_modules/dsgvo-video-embed/dist/*'
177289 $(foreach file, $(wildcard locale-* /locale/* /LC_MESSAGES/django* .po) , \
178290 $(SED ) -i ' s%#: .*/adhocracy4%#: adhocracy4%' $(file ) ; )
179291 $(foreach file, $(wildcard locale-* /locale/* /LC_MESSAGES/django* .po) , \
@@ -183,16 +295,16 @@ po:
183295
184296.PHONY : mo
185297mo :
186- $(VIRTUAL_ENV ) /bin /python manage.py compilemessages
298+ $(VIRTUAL_ENV_BIN ) /python manage.py compilemessages
187299
188300.PHONY : release
189301release : export DJANGO_SETTINGS_MODULE ?= adhocracy-plus.config.settings.build
190302release :
191303 npm install --silent
192304 npm run build:prod
193- $(VIRTUAL_ENV ) /bin /python -m pip install -r requirements.txt -q
194- $(VIRTUAL_ENV ) /bin /python manage.py compilemessages -v0
195- $(VIRTUAL_ENV ) /bin /python manage.py collectstatic --noinput -v0
305+ $(VIRTUAL_ENV_BIN ) /python -m pip install -r requirements.txt -q
306+ $(VIRTUAL_ENV_BIN ) /python manage.py compilemessages -v0
307+ $(VIRTUAL_ENV_BIN ) /python manage.py collectstatic --noinput -v0
196308
197309.PHONY : postgres-start
198310postgres-start :
@@ -217,23 +329,23 @@ postgres-create:
217329.PHONY : local-a4
218330local-a4 :
219331 if [ -d " ../adhocracy4" ]; then \
220- $(VIRTUAL_ENV ) /bin /python -m pip install --upgrade ../adhocracy4; \
221- $(VIRTUAL_ENV ) /bin /python manage.py migrate; \
332+ $(VIRTUAL_ENV_BIN ) /python -m pip install --upgrade ../adhocracy4; \
333+ $(VIRTUAL_ENV_BIN ) /python manage.py migrate; \
222334 npm link ../adhocracy4; \
223335 fi
224336
225337.PHONY : celery-worker-start
226338celery-worker-start :
227- $(VIRTUAL_ENV ) /bin /celery --app adhocracy-plus worker --loglevel INFO
339+ $(VIRTUAL_ENV_BIN ) /celery --app adhocracy-plus worker --loglevel INFO
228340
229341.PHONY : celery-worker-status
230342celery-worker-status :
231- $(VIRTUAL_ENV ) /bin /celery --app adhocracy-plus inspect registered
343+ $(VIRTUAL_ENV_BIN ) /celery --app adhocracy-plus inspect registered
232344
233345.PHONY : celery-worker-dummy-task
234346celery-worker-dummy-task :
235- $(VIRTUAL_ENV ) /bin /celery --app adhocracy-plus call dummy_task | awk ' {print "celery-task-meta-"$$0}' | xargs redis-cli get | python3 -m json.tool
347+ $(VIRTUAL_ENV_BIN ) /celery --app adhocracy-plus call dummy_task | awk ' {print "celery-task-meta-"$$0}' | xargs redis-cli get | python3 -m json.tool
236348
237349.PHONY : docs
238350docs :
239- $(VIRTUAL_ENV ) /bin /mkdocs serve
351+ $(VIRTUAL_ENV_BIN ) /mkdocs serve
0 commit comments