acceptable-night-23367
05/14/2022, 9:30 PMapp.py
module, plus some static assets), I've gone through the getting started docs, but can't get it to run the app. It looks like it's starting the initial process correctly, flask (werkzeug) comes up and says it's going to listen on whatever port, and tries to start the child serving process, but that one fails to import flask. It seems like the child process created by werkzeug isn't running with the same environment the parent process is using?happy-kitchen-89482
05/14/2022, 9:38 PM./pants run
?acceptable-night-23367
05/14/2022, 9:39 PMhappy-kitchen-89482
05/14/2022, 9:39 PMacceptable-night-23367
05/14/2022, 9:39 PMBUILD
pex_binary(
name="app",
entry_point="app.py",
)
python_requirements(
name="requirements.txt0",
)
python_sources(
name="root",
)
happy-kitchen-89482
05/14/2022, 9:39 PMacceptable-night-23367
05/14/2022, 9:40 PMhappy-kitchen-89482
05/14/2022, 9:40 PM./pants run path/to/package:app
?acceptable-night-23367
05/14/2022, 9:40 PMacceptable-night-23367
05/14/2022, 9:41 PM% ./pants run :app
happy-kitchen-89482
05/14/2022, 9:41 PMacceptable-night-23367
05/14/2022, 9:42 PMhappy-kitchen-89482
05/14/2022, 9:42 PMacceptable-night-23367
05/14/2022, 9:42 PM./pants run app.py
also workshappy-kitchen-89482
05/14/2022, 9:42 PMacceptable-night-23367
05/14/2022, 9:42 PMhappy-kitchen-89482
05/14/2022, 9:42 PMacceptable-night-23367
05/14/2022, 9:42 PMacceptable-night-23367
05/14/2022, 9:44 PM% ./pants run :app
17:35:07.95 [INFO] Completed: Building 2 requirements for app.pex from the 3rdparty/python/default.lock resolve: flask, flask-assets
17:35:08.58 [INFO] Completed: Building local_dists.pex
* Serving Flask app 'demo' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses (0.0.0.0)
WARNING: This is a development server. Do not use it in a production deployment.
* Running on <http://127.0.0.1:5001>
* Running on <http://192.168.69.100:5001> (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/leif/git/demo/app.py", line 8, in <module>
from flask import Flask, render_template
ModuleNotFoundError: No module named 'flask'
acceptable-night-23367
05/14/2022, 9:44 PMhappy-kitchen-89482
05/14/2022, 9:45 PMhappy-kitchen-89482
05/14/2022, 9:45 PMacceptable-night-23367
05/14/2022, 9:45 PMacceptable-night-23367
05/14/2022, 9:46 PMhappy-kitchen-89482
05/14/2022, 9:46 PMrestartable=True
on the pex_binary
and then the server will reload automatically on editshappy-kitchen-89482
05/14/2022, 9:46 PMacceptable-night-23367
05/14/2022, 9:47 PMhappy-kitchen-89482
05/14/2022, 9:48 PMRestarting with stat
line looks suspicious, is that what Flask prints when the server restarts due to its own change detection?happy-kitchen-89482
05/14/2022, 9:48 PMacceptable-night-23367
05/14/2022, 9:49 PMhappy-kitchen-89482
05/14/2022, 9:49 PMacceptable-night-23367
05/14/2022, 9:49 PMhappy-kitchen-89482
05/14/2022, 9:50 PMrestartable=True
Pants will do its own hot reloading, which is more robust than Flask/Django's alone can be, because it knows about all your deps and how to build them from the original sources. E.g., tailwind css in your caseacceptable-night-23367
05/14/2022, 9:50 PMhappy-kitchen-89482
05/14/2022, 9:51 PMhappy-kitchen-89482
05/14/2022, 9:51 PMhappy-kitchen-89482
05/14/2022, 9:51 PMacceptable-night-23367
05/14/2022, 9:51 PMacceptable-night-23367
05/14/2022, 9:51 PMhappy-kitchen-89482
05/14/2022, 9:51 PMhundreds-father-404
05/14/2022, 9:53 PMresources
targethappy-kitchen-89482
05/14/2022, 9:53 PMacceptable-night-23367
05/14/2022, 9:53 PMacceptable-night-23367
05/14/2022, 9:54 PMhappy-kitchen-89482
05/14/2022, 9:55 PMhappy-kitchen-89482
05/14/2022, 9:56 PMacceptable-night-23367
05/14/2022, 9:56 PMtext-white
font-bold
bg-blue-500
so that instead of writing css files, you just do everything in html, and apply the classes you want
but there's a build step that takes a bit of tailwind config, plus a simple css template-ish file, and generates a plain css file to bundle in assetsacceptable-night-23367
05/14/2022, 9:56 PMhappy-kitchen-89482
05/14/2022, 9:56 PMhundreds-father-404
05/14/2022, 9:56 PM(I suggest ignoring that at first and just assuming it's available on the PATH, then tackling it later)Specifically, use an absolute path like
/usr/bin/tailwind
in the argv=
for a Process()
happy-kitchen-89482
05/14/2022, 9:57 PMacceptable-night-23367
05/14/2022, 9:57 PMhappy-kitchen-89482
05/14/2022, 9:57 PMhappy-kitchen-89482
05/14/2022, 9:57 PMacceptable-night-23367
05/14/2022, 9:57 PMhappy-kitchen-89482
05/14/2022, 9:57 PMacceptable-night-23367
05/14/2022, 9:57 PMacceptable-night-23367
05/14/2022, 10:25 PMacceptable-night-23367
05/14/2022, 10:25 PMacceptable-night-23367
05/14/2022, 11:03 PMacceptable-night-23367
05/14/2022, 11:04 PMrequest.protocol_target
comes from
⢠what digests are at all, or what a snapshot ishundreds-father-404
05/14/2022, 11:06 PMProcess
isacceptable-night-23367
05/14/2022, 11:06 PMacceptable-night-23367
05/14/2022, 11:06 PMhundreds-father-404
05/14/2022, 11:06 PMacceptable-night-23367
05/14/2022, 11:07 PMacceptable-night-23367
05/14/2022, 11:47 PMacceptable-night-23367
05/14/2022, 11:47 PMtailwind.config.js
, mine looks like this
module.exports = {
content: [
'./templates/**/*.html',
],
theme: {
colors: {
running: {
500: '#9C59D1',
700: '#A773D1',
},
stopped: {
500: '#FCF434',
700: '#FCF897',
},
},
extend: {},
},
plugins: [],
}
acceptable-night-23367
05/14/2022, 11:48 PMcontent
array is interesting: it scans all your html to figure out which class names you're actually using, to make sure it only omits the definitions you're going to use, to reduce asset sizeacceptable-night-23367
05/14/2022, 11:48 PMtailwind.config.js
, and all the files matching that glob pattern, need to be inputs to the ruleacceptable-night-23367
05/14/2022, 11:49 PMmodule.exports =
, try to parse the rest as json (I guess hope there aren't any comments), and find the other files to include that way; at worst, you might have to evaluate the config with a javascript interpreter to figure it outacceptable-night-23367
05/14/2022, 11:51 PMclass TailwindCSS(ExternalTool):
name = "tailwindcss"
options = {
"tailwindcss": ("binary", "TAILWINDCSS_BIN"),
"minify": "TAILWINDCSS_MINIFY",
}
def input(self, in_, out, source_path, output_path, **kwargs):
command = self.parse_binary(self.tailwindcss or "tailwindcss")
command.extend(["--input", "{input}"])
command.extend(["--output", "{output}"])
if self.minify:
command.append("--minify")
self.subprocess(command, out, in_)
def output(self, in_, out, **kwargs):
out.write(in_.read())
register_filter(TailwindCSS)
app = Flask("demo")
assets = Environment(app)
assets.config["tailwindcss_minify"] = True
css = Bundle(
"src/main.css",
filters="tailwindcss",
depends=["tailwind.config.js", "templates/**/*.html"],
output="dist/main.css",
)
acceptable-night-23367
05/14/2022, 11:51 PMacceptable-night-23367
05/14/2022, 11:52 PMacceptable-night-23367
05/14/2022, 11:52 PMhappy-kitchen-89482
05/15/2022, 3:34 PMhappy-kitchen-89482
05/15/2022, 3:36 PMhappy-kitchen-89482
05/15/2022, 3:37 PMcontent
array could be used to do dependency inferencehappy-kitchen-89482
05/15/2022, 3:55 PM