Skip to content

Commit c9b2ecb

Browse files
committed
Replace buildstatic.sh with yarn scripts and update README.
Installing JavaScript dependencies is now an explicit step that must be done after cloning or pulling Votr, same as Python dependencies, not something that happens automatically. watchstatic.py was fully replaced by webpack --watch. By default, only development mode is built. Votr.setDebug() can still switch between production and development if Votr was built with "yarn buildboth".
1 parent f635547 commit c9b2ecb

File tree

6 files changed

+48
-146
lines changed

6 files changed

+48
-146
lines changed

README.md

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,49 @@ based on). **Fladgejt** contains the business logic for various AIS2 tasks and
2121
knows where to find which buttons and tables. And **Votrfront** is the web app
2222
that Votr's users interact with.
2323

24-
Running Votr
25-
------------
24+
Installing and running Votr
25+
---------------------------
2626

27-
1. Install Python 3.4+ and virtualenv. On recent Ubuntu or Debian, use:
27+
System requirements:
2828

29-
sudo apt install virtualenv
29+
* Install Python 3.4+ and virtualenv. E.g. on Ubuntu 18.04: `sudo apt install
30+
virtualenv`
31+
* Install [node.js 8+][1]. E.g. on Ubuntu 18.04: `sudo apt install nodejs` \
32+
If your distro doesn't have node.js >= 8, or if don't want to install
33+
node.js system-wide, you can use nvm or nodeenv. [Read more.][2]
34+
* [Install Yarn.][3]
3035

31-
2. Install node.js and npm. (Some Linux distributions bundle them together in
32-
one package.) Check the version: npm 1 and 2 are too old. npm 3 and 4 are
33-
probably OK. npm 5+ is ideal, but most Linux distributions don't have it yet
34-
(including current Ubuntu and Debian). In that case, you can either:
36+
[1]: https://nodejs.org/en/download/package-manager/
37+
[2]: https://github.com/fmfi-svt/votr/wiki/Installation-alternatives
38+
[3]: https://yarnpkg.com/en/docs/install
3539

36-
* Install npm 3 despite its age and hope for the best. E.g. on Ubuntu:
37-
`sudo apt install nodejs-legacy npm`.
38-
* Use the unofficial up to date repositories from
39-
https://nodejs.org/en/download/package-manager/, and install `nodejs`
40-
(not `nodejs-legacy` and `npm`).
40+
Download and set up Votr:
4141

42-
3. [Install Yarn.](https://yarnpkg.com/en/docs/install)
42+
```shell
43+
git clone https://github.com/fmfi-svt/votr.git
44+
cd votr
45+
virtualenv -p python3 venv
46+
```
4347

44-
4. Create a virtualenv directory. A virtualenv is an isolated environment that
45-
contains Python libraries, so that you don't have to install them
46-
system-wide, and each project can use different versions without conflicts.
48+
Install Votr's dependencies in `votr/venv` and `votr/node_modules`: \
49+
(Note: Repeat this step every time you pull a new version of Votr, in case they
50+
were updated.)
4751

48-
virtualenv -p python3 venv
52+
```shell
53+
venv/bin/pip install -r requirements.txt
54+
yarn install
55+
```
4956

50-
5. Activate the virtualenv. (Basically, this just adds `venv/bin` to your
51-
current shell's `$PATH`. Instead, you could just use `venv/bin/python`
52-
instead of `python`, `venv/bin/pip` instead of `pip`, etc.)
57+
Run Votr by starting these two commands in separate terminals (they are Votr's
58+
Python web server and Votr's JavaScript build system):
5359

54-
source venv/bin/activate
60+
```shell
61+
venv/bin/python console.py serve --debug
62+
```
5563

56-
6. Install the latest version of `pip` (earlier versions don't support wheels),
57-
and then use it to install Python dependencies.
58-
59-
pip install -U pip
60-
pip install -r requirements.txt
61-
62-
7. Start Votr. Remember to activate the virtualenv first if you haven't done it
63-
yet in this terminal.
64-
65-
./console.py serve --debug
64+
```shell
65+
yarn watch
66+
```
6667

6768
Contributing to Votr
6869
--------------------

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
"webpack": "^4.18.0",
3030
"webpack-cli": "^3.1.0"
3131
},
32+
"scripts": {
33+
"builddev": "webpack --mode=development --progress --display=minimal",
34+
"buildprod": "webpack --mode=production --progress --display=minimal",
35+
"watch": "webpack --mode=development --progress --display=minimal --watch",
36+
"buildboth": "$npm_execpath run builddev && $npm_execpath run buildprod && echo ok_both > votrfront/static/status",
37+
"clean": "rm -rf votrfront/static",
38+
"distclean": "rm -rf votrfront/static node_modules"
39+
},
3240
"browserslist": "defaults, not dead",
3341
"babel": {
3442
"presets": [

votrfront/buildstatic.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

votrfront/front.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ def app_response(request, **my_data):
8080
else:
8181
return Response('Timed out waiting for webpack.', status=500)
8282

83+
debug = request.cookies.get('votr_debug')
8384
if status == 'failed':
8485
return Response('Webpack build failed.', status=500)
85-
86-
if not os.path.exists(static_path + 'ok'):
87-
return Response('buildstatic failed!', status=500)
88-
89-
debug = request.cookies.get('votr_debug')
90-
with open(static_path + ('jsdeps-dev' if debug else 'jsdeps-prod')) as f:
91-
scripts = f.read().split()
86+
elif status == 'ok_dev' or (status == 'ok_both' and debug):
87+
scripts = ['prologue.dev.js', 'votr.dev.js', 'vendors_votr.dev.js']
88+
elif status == 'ok_prod' or (status == 'ok_both' and not debug):
89+
scripts = ['prologue.min.js', 'votr.min.js', 'vendors_votr.min.js']
90+
else:
91+
return Response('Unexpected webpack status.', status=500)
9292

9393
content = template % dict(
9494
init_json=json.dumps({ 'settings': my_data }).replace('</', '<\\/'),

votrfront/serve.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
import os
33
from werkzeug.serving import run_simple
4-
from .watchstatic import watch_in_background
54

65

76
def serve(app, *args):
@@ -17,9 +16,6 @@ def serve(app, *args):
1716
os.makedirs(app.var_path('oldlogs'), exist_ok=True)
1817
os.makedirs(app.var_path('sessions'), exist_ok=True)
1918

20-
if os.getenv('WERKZEUG_RUN_MAIN'):
21-
watch_in_background()
22-
2319
app.wrap_static()
2420
run_simple('127.0.0.1', int(os.getenv('PORT') or 5000), app,
2521
use_debugger=debug, use_reloader=True, threaded=True)

votrfront/watchstatic.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)