Dependencies ready to go

master
Drew Bednar 1 year ago
parent 5e3661dc2c
commit 28c6a9ac43

3
.gitignore vendored

@ -60,3 +60,6 @@ target/
# Pycharm
.idea
# Project Specific
.webassets-cache/

@ -2,25 +2,13 @@
Learning HTMX
## First time setup
Following https://testdriven.io/blog/flask-htmx-tailwind/
Create a virtual environment and activate it. Now from the root project directory run `./scripts/bootstrap`. This will install `pip-tools` and sync any dependencies for the first time.
## Dependency management
## Vendoring HTMX
Dependencies are managed via [pip-tools].
Since this project doesn't use Node and npm we will vendor the version of htmx we want to ship
### Adding a dependency
To add a dependency, edit `requirements.in` (or `dev-requirements.in`
for dev dependencies) and add your dependency then run `pip-compile
requirements.in`.
### Syncing dependencies
Run `pip-sync requirements.txt dev_requirements.txt`.
## Testing
Run the tests by invoking `py.test` in the project root. Make sure you
run any pending migrations beforehand.
```
wget https://unpkg.com/htmx.org@1.9.4/dist/htmx.js -P ./learn_htmx/static/src/
```

@ -3,6 +3,7 @@ invoke
isort
pip-tools
pre-commit
pytailwindcss==0.2.0
pytest
pytest-cov
shellcheck-py==0.9.0.5

@ -1,73 +0,0 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile dev-requirements.in
#
black==23.7.0
# via -r dev-requirements.in
build==0.10.0
# via pip-tools
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via
# black
# pip-tools
coverage[toml]==7.3.0
# via pytest-cov
distlib==0.3.7
# via virtualenv
filelock==3.12.2
# via virtualenv
identify==2.5.26
# via pre-commit
iniconfig==2.0.0
# via pytest
invoke==2.2.0
# via -r dev-requirements.in
isort==5.12.0
# via -r dev-requirements.in
mypy-extensions==1.0.0
# via black
nodeenv==1.8.0
# via pre-commit
packaging==23.1
# via
# black
# build
# pytest
pathspec==0.11.2
# via black
pip-tools==7.3.0
# via -r dev-requirements.in
platformdirs==3.10.0
# via
# black
# virtualenv
pluggy==1.2.0
# via pytest
pre-commit==3.3.3
# via -r dev-requirements.in
pyproject-hooks==1.0.0
# via build
pytest==7.4.0
# via
# -r dev-requirements.in
# pytest-cov
pytest-cov==4.1.0
# via -r dev-requirements.in
pyyaml==6.0.1
# via pre-commit
ruff==0.0.285
# via -r dev-requirements.in
shellcheck-py==0.9.0.5
# via -r dev-requirements.in
virtualenv==20.24.3
# via pre-commit
wheel==0.41.1
# via pip-tools
# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools

@ -0,0 +1,26 @@
# app.py
from flask import Flask
from flask import render_template
from flask_assets import Bundle
from flask_assets import Environment
app = Flask(__name__)
assets = Environment(app)
css = Bundle("src/main.css", output="dist/main.css")
js = Bundle("src/*.js", output="dist/main.js") # new
assets.register("css", css)
assets.register("js", js) # new
css.build()
js.build()
@app.route("/")
def homepage():
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,5 @@
/* static/src/main.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

@ -0,0 +1,20 @@
{# templates/base.html -#}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% assets 'css' -%}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets -%}
{% assets 'js' -%}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets-%}
<title>Flask + htmlx + Tailwind CSS</title>
</head>
<body class="bg-blue-100">
{% block content -%}
{% endblock content -%}
</body>
</html>

@ -0,0 +1,5 @@
{# templates/index.html -#}
{% extends "base.html" -%}
{% block content -%}
<h1>Hello Dirp</h1>
{% endblock content %}

@ -8,3 +8,30 @@ filter_files = true
line-length = 120
skip-string-normalization = true
exclude = "(^/\\.git|^/env/|^/venv/|^/node_modules/)"
[tool.ruff]
line-length = 120
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

@ -0,0 +1,10 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./learn_htmx/templates/**/*.html',
],
theme: {
extend: {},
},
plugins: [],
}

@ -0,0 +1,14 @@
from invoke import task
@task
def tailwind(c, watch=False):
tailwind_cmd = "tailwindcss -i ./learn_htmx/static/src/main.css -o ./learn_htmx/static/dist/main.css --minify"
if watch:
tailwind_cmd = tailwind_cmd + "--watch"
c.run(tailwind_cmd)
@task
def serve_dev(c, host="0.0.0.0", port=8000):
c.run(f"FLASK_APP=./learn_htmx/app.py flask run --host {host} --port {port} --debug")
Loading…
Cancel
Save