Skip to content

Commit

Permalink
Update Flask
Browse files Browse the repository at this point in the history
* Remove deprecated `FLASK_APP` env var (and hence `.flaskenv`) and pass
  app name in via command line instead.
* Remove deprecated `FLASK_ENV` env var and pass `--debug` instead.
* Remove now-unneeded `@with_appcontext` decorator from `init_db cli
  command.
* Import `Markup` from `markupsafe` instead of `Flask`.
  • Loading branch information
cu committed Jul 15, 2023
1 parent 09ae416 commit 4c59406
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 279 deletions.
1 change: 0 additions & 1 deletion .flaskenv

This file was deleted.

18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,16 @@ Use poetry to create a virtual environment and install the dependencies:
poetry install
```

Flask is configured via environment variables. There is a file called
`.flaskenv` which sets the name of the app. If you want to run `flask` from
somewhere else, you will need to set:

```sh
FLASK_APP=silicon
```

All other settings can either be set as environment variables or written to a
Some settings can either be set as environment variables or written to a
file named `.env` in the project root. For development, this will suffice:

```sh
FLASK_ENV=development
WERKZEUG_DEBUG_PIN=off
```

You can set any environment variables mentioned in the Flask or Werkzeug
docs, but these are some you might care to know about:

* `FLASK_ENV`: `production` (default), or `development`
* `FLASK_RUN_HOST`: defaults to `127.0.0.1`
* `FLASK_RUN_PORT`: defaults to `5000`
* `INSTANCE_PATH`: where the silicon data (in particular the database) is stored
Expand All @@ -167,15 +157,15 @@ run the following command. It will create an `instance` directory in the root
of the project and initialize the SQLite database from `schema.sql`.

```sh
poetry run flask init-db
poetry run flask --app silicon init-db
```

## Running Silicon

Run the project via the `flask` development server:

```sh
poetry run flask run
poetry run flask --app silicon run --debug
```

Unless you changed the defaults, you should be able to access the UI on
Expand Down Expand Up @@ -267,7 +257,7 @@ In the event that a database migration is needed, follow these steps:
To import the data:

4. Move or rename the old `instance/silicon.sqlite`, if it exists.
5. Run `poetry run flask init-db`.
5. Run `poetry run flask --app silicon init-db`.
6. Run `sqlite3 instance/silicon.sqlite < silicon_data.sql`.
7. Start the Silicon instance.

Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -e

export PATH="/$APP_NAME/bin:$PATH"

flask init-db
flask --app $APP_NAME init-db

eval "exec $@"
532 changes: 273 additions & 259 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.9"
Flask = "^2.0.2"
Flask = "^2.1.3"
mistune = "^2.0.2"
Pygments = "2.6.1"
python-slugify = "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion silicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_app(test_config=None):
# ensure the instance folder exists
os.makedirs(app.instance_path, exist_ok=True)

if app.config['ENV'] == 'development':
if app.debug:
print(sys.version)
print(f"Instance path: {app.instance_path}")

Expand Down
1 change: 0 additions & 1 deletion silicon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


@click.command('init-db')
@with_appcontext
def init_db_command():
"""Create new tables."""

Expand Down
2 changes: 1 addition & 1 deletion silicon/j2_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from html import escape
import re

from flask import Markup
from markupsafe import Markup


def human_timestamp(timestamp):
Expand Down

0 comments on commit 4c59406

Please sign in to comment.