plain 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plain/assets/README.md +62 -5
- plain/assets/compile.py +10 -0
- plain/assets/views.py +2 -2
- plain/cli/cli.py +8 -9
- plain/runtime/global_settings.py +0 -4
- {plain-0.2.0.dist-info → plain-0.2.2.dist-info}/METADATA +1 -1
- {plain-0.2.0.dist-info → plain-0.2.2.dist-info}/RECORD +10 -10
- {plain-0.2.0.dist-info → plain-0.2.2.dist-info}/LICENSE +0 -0
- {plain-0.2.0.dist-info → plain-0.2.2.dist-info}/WHEEL +0 -0
- {plain-0.2.0.dist-info → plain-0.2.2.dist-info}/entry_points.txt +0 -0
plain/assets/README.md
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
Serve static assets (CSS, JS, images, etc.) directly from your app.
|
4
4
|
|
5
|
-
The default behavior is for Plain to serve its own assets through a view. This behaves in a way similar to [Whitenoise](https://whitenoise.readthedocs.io/en/latest/).
|
6
5
|
|
7
6
|
## Usage
|
8
7
|
|
9
|
-
To
|
8
|
+
To serve assets, put them in `app/assets` or `app/{package}/assets`.
|
10
9
|
|
11
10
|
Then include the `plain.assets.urls` in your `urls.py`:
|
12
11
|
|
@@ -22,16 +21,74 @@ urlpatterns = [
|
|
22
21
|
]
|
23
22
|
```
|
24
23
|
|
25
|
-
|
24
|
+
Now in your template you can use the `asset()` function to get the URL:
|
26
25
|
|
27
26
|
```html
|
28
27
|
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
|
29
28
|
```
|
30
29
|
|
31
|
-
|
30
|
+
|
31
|
+
## Local development
|
32
|
+
|
33
|
+
When you're working with `settings.DEBUG = True`, the assets will be served directly from their original location. You don't need to run `plain compile` or configure anything else.
|
34
|
+
|
35
|
+
|
36
|
+
## Production deployment
|
37
|
+
|
38
|
+
In production, one of your deployment steps should be to compile the assets.
|
39
|
+
|
40
|
+
```bash
|
41
|
+
plain compile
|
42
|
+
```
|
43
|
+
|
44
|
+
By default, this generates "fingerprinted" and compressed versions of the assets, which are then served by your app. This means that a file like `main.css` will result in two new files, like `main.d0db67b.css` and `main.d0db67b.css.gz`.
|
45
|
+
|
46
|
+
The purpose of fingerprinting the assets is to allow the browser to cache them indefinitely. When the content of the file changes, the fingerprint will change, and the browser will use the newer file. This cuts down on the number of requests that your app has to handle related to assets.
|
47
|
+
|
48
|
+
|
49
|
+
## FAQs
|
50
|
+
|
51
|
+
### How do you reference assets in Python code?
|
32
52
|
|
33
53
|
```python
|
34
54
|
from plain.assets.urls import get_asset_url
|
35
55
|
|
36
|
-
|
56
|
+
url = get_asset_url("css/style.css")
|
57
|
+
```
|
58
|
+
|
59
|
+
### What if I need the files in a different location?
|
60
|
+
|
61
|
+
The generated/copied files are stored in `{repo}/.plain/assets/compiled`. If you need them to be somewhere else, try simply moving them after compilation.
|
62
|
+
|
63
|
+
```bash
|
64
|
+
plain compile
|
65
|
+
mv .plain/assets/compiled /path/to/your/static
|
37
66
|
```
|
67
|
+
|
68
|
+
### How do I upload the assets to a CDN?
|
69
|
+
|
70
|
+
The steps for this will vary, but the general idea is to compile them, and then upload the compiled assets.
|
71
|
+
|
72
|
+
```bash
|
73
|
+
plain compile
|
74
|
+
./example-upload-to-cdn-script
|
75
|
+
```
|
76
|
+
|
77
|
+
Use the `ASSETS_BASE_URL` setting to tell the `{{ asset() }}` template function where to point.
|
78
|
+
|
79
|
+
```python
|
80
|
+
# app/settings.py
|
81
|
+
ASSETS_BASE_URL = "https://cdn.example.com/"
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
### Why aren't the originals copied to the compiled directory?
|
86
|
+
|
87
|
+
The default behavior is to fingerprint assets, which is an exact copy of the original file but with a different filename. The originals aren't copied over because you should generally always use this fingerprinted path (that automatically uses longer-lived caching).
|
88
|
+
|
89
|
+
If you need the originals for any reason, you can use `plain compile --keep-original`, though this will typically be combined with `--no-fingerprint` otherwise the fingerprinted files will still get priority in `{{ asset() }}` template calls.
|
90
|
+
|
91
|
+
|
92
|
+
### What about source maps or imported css files?
|
93
|
+
|
94
|
+
TODO
|
plain/assets/compile.py
CHANGED
@@ -3,6 +3,8 @@ import hashlib
|
|
3
3
|
import os
|
4
4
|
import shutil
|
5
5
|
|
6
|
+
from plain.runtime import settings
|
7
|
+
|
6
8
|
from .finders import find_assets
|
7
9
|
from .fingerprints import AssetsFingerprintsManifest
|
8
10
|
|
@@ -41,6 +43,14 @@ SKIP_COMPRESS_EXTENSIONS = (
|
|
41
43
|
)
|
42
44
|
|
43
45
|
|
46
|
+
def get_compiled_path():
|
47
|
+
"""
|
48
|
+
Get the path at runtime to the compiled assets directory.
|
49
|
+
There's no reason currently for this to be a user-facing setting.
|
50
|
+
"""
|
51
|
+
return settings.PLAIN_TEMP_PATH / "assets" / "compiled"
|
52
|
+
|
53
|
+
|
44
54
|
def compile_assets(*, target_dir, keep_original, fingerprint, compress):
|
45
55
|
manifest = AssetsFingerprintsManifest()
|
46
56
|
|
plain/assets/views.py
CHANGED
@@ -15,7 +15,7 @@ from plain.runtime import settings
|
|
15
15
|
from plain.urls import reverse
|
16
16
|
from plain.views import View
|
17
17
|
|
18
|
-
from .compile import FINGERPRINT_LENGTH
|
18
|
+
from .compile import FINGERPRINT_LENGTH, get_compiled_path
|
19
19
|
from .finders import find_assets
|
20
20
|
from .fingerprints import get_fingerprinted_url_path
|
21
21
|
|
@@ -62,7 +62,7 @@ class AssetView(View):
|
|
62
62
|
|
63
63
|
def get_asset_path(self, path):
|
64
64
|
"""Get the path to the compiled asset"""
|
65
|
-
compiled_path = os.path.abspath(
|
65
|
+
compiled_path = os.path.abspath(get_compiled_path())
|
66
66
|
asset_path = os.path.join(compiled_path, path)
|
67
67
|
|
68
68
|
# Make sure we don't try to escape the compiled assests path
|
plain/cli/cli.py
CHANGED
@@ -13,9 +13,8 @@ from click.core import Command, Context
|
|
13
13
|
|
14
14
|
import plain.runtime
|
15
15
|
from plain import preflight
|
16
|
-
from plain.assets.compile import compile_assets
|
16
|
+
from plain.assets.compile import compile_assets, get_compiled_path
|
17
17
|
from plain.packages import packages
|
18
|
-
from plain.runtime import settings
|
19
18
|
|
20
19
|
from .formatting import PlainContext
|
21
20
|
from .packages import EntryPointGroup, InstalledPackagesGroup
|
@@ -336,18 +335,18 @@ def compile(keep_original, fingerprint, compress):
|
|
336
335
|
sys.exit(result.returncode)
|
337
336
|
|
338
337
|
# Compile our assets
|
339
|
-
|
340
|
-
click.secho(f"Compiling assets to {
|
341
|
-
if
|
338
|
+
target_dir = get_compiled_path()
|
339
|
+
click.secho(f"Compiling assets to {target_dir}", bold=True)
|
340
|
+
if target_dir.exists():
|
342
341
|
click.secho("(clearing previously compiled assets)")
|
343
|
-
shutil.rmtree(
|
344
|
-
|
342
|
+
shutil.rmtree(target_dir)
|
343
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
345
344
|
|
346
345
|
total_files = 0
|
347
346
|
total_compiled = 0
|
348
347
|
|
349
348
|
for url_path, resolved_url_path, compiled_paths in compile_assets(
|
350
|
-
target_dir=
|
349
|
+
target_dir=target_dir,
|
351
350
|
keep_original=keep_original,
|
352
351
|
fingerprint=fingerprint,
|
353
352
|
compress=compress,
|
@@ -365,7 +364,7 @@ def compile(keep_original, fingerprint, compress):
|
|
365
364
|
total_compiled += len(compiled_paths)
|
366
365
|
|
367
366
|
click.secho(
|
368
|
-
f"
|
367
|
+
f"\nCompiled {total_files} assets into {total_compiled} files", fg="green"
|
369
368
|
)
|
370
369
|
|
371
370
|
|
plain/runtime/global_settings.py
CHANGED
@@ -150,10 +150,6 @@ LOGGING = {}
|
|
150
150
|
# ASSETS #
|
151
151
|
###############
|
152
152
|
|
153
|
-
# Absolute path to the directory assets files should be collected to.
|
154
|
-
# Example: "/var/www/example.com/assets/"
|
155
|
-
ASSETS_COMPILED_PATH = PLAIN_TEMP_PATH / "assets" / "compiled"
|
156
|
-
|
157
153
|
# Whether to redirect the original asset path to the fingerprinted path.
|
158
154
|
ASSETS_REDIRECT_ORIGINAL = True
|
159
155
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
plain/README.md,sha256=mFsLBpqiHvuznV98eewupvo1JoQeQG0q87wNlXit21A,1695
|
2
2
|
plain/__main__.py,sha256=BiYbF-txGNbeRqp_CHQ9EZ_bCbbKq2iw51Z8RRUgIBY,105
|
3
|
-
plain/assets/README.md,sha256=
|
3
|
+
plain/assets/README.md,sha256=048BzyQ2-BcsRiv6NiuLHHijOw96RK-e6lJ_Eq7g2pc,2857
|
4
4
|
plain/assets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
plain/assets/compile.py,sha256=
|
5
|
+
plain/assets/compile.py,sha256=lsnciN85YjHe6d8VIKJi1L8r7NGHNzMOe9L87wObM5I,3287
|
6
6
|
plain/assets/finders.py,sha256=WEKAnXTmpuQ7UKLZz7vHPrKFdDOkuZSP6_JTKmIxrKg,1268
|
7
7
|
plain/assets/fingerprints.py,sha256=1NKAnnXVlncY5iimXztr0NL3RIjBKsNlZRIe6nmItJc,931
|
8
8
|
plain/assets/urls.py,sha256=ZTIoM1Zq35JaXZ3wFhXhfGa7VoITDNlH9i5RS0R5xow,933
|
9
|
-
plain/assets/views.py,sha256=
|
9
|
+
plain/assets/views.py,sha256=vcjDZYUC979rM03wlVHV19-6afgeFd3ldTEfZUs0kw0,8836
|
10
10
|
plain/cli/README.md,sha256=bEp9B9C92YEa44wN2IywTmNZsYBv_uGq9AS_bBiAGdY,2580
|
11
11
|
plain/cli/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
|
12
|
-
plain/cli/cli.py,sha256=
|
12
|
+
plain/cli/cli.py,sha256=JyPNQGlczqCyLxZq5Jh_591rKpBMN91JHGXdaTuPWJ0,14841
|
13
13
|
plain/cli/formatting.py,sha256=1hZH13y1qwHcU2K2_Na388nw9uvoeQH8LrWL-O9h8Yc,2207
|
14
14
|
plain/cli/packages.py,sha256=69VH1bIi1-5N5l2jlBcR5EP0pt-v16sPar9arO3gCSE,2052
|
15
15
|
plain/cli/print.py,sha256=XraUYrgODOJquIiEv78wSCYGRBplHXtXSS9QtFG5hqY,217
|
@@ -82,7 +82,7 @@ plain/preflight/security/csrf.py,sha256=EZy_DkVqc1kUmBA-UbNmhVsKhRINfmqgWSRlatKy
|
|
82
82
|
plain/preflight/urls.py,sha256=O4PQ_v205VA2872fQlhPfxaihDDRCsVp0ZVKQ92aX4k,3019
|
83
83
|
plain/runtime/README.md,sha256=F5USETg445RX1RxC13y_1NrbOs3GHQI2Jl9idGdVFnk,2270
|
84
84
|
plain/runtime/__init__.py,sha256=jKak9tK8MfcGNYOzqCOEmwSRAGOoji8r7e2IAwOymzE,1392
|
85
|
-
plain/runtime/global_settings.py,sha256=
|
85
|
+
plain/runtime/global_settings.py,sha256=PrJ5IAPk1nEr8U_XM3gLrItIVA4v2ig1t1bx_fV0NPE,6118
|
86
86
|
plain/runtime/user_settings.py,sha256=3016w7YiOkG85L1Y5BsobgxgCOAaRbZzFaBadzmHSZg,11315
|
87
87
|
plain/signals/README.md,sha256=cd3tKEgH-xc88CUWyDxl4-qv-HBXx8VT32BXVwA5azA,230
|
88
88
|
plain/signals/__init__.py,sha256=eAs0kLqptuP6I31dWXeAqRNji3svplpAV4Ez6ktjwXM,131
|
@@ -152,8 +152,8 @@ plain/views/objects.py,sha256=9QBYyb8PgkRirXCQ8-Pms4_yMzP37dfeL30hWRYmtZg,7909
|
|
152
152
|
plain/views/redirect.py,sha256=KLnlktzK6ZNMTlaEiZpMKQMEP5zeTgGLJ9BIkIJfwBo,1733
|
153
153
|
plain/views/templates.py,sha256=nF9CcdhhjAyp3LB0RrSYnBaHpHzMfPSw719RCdcXk7o,2007
|
154
154
|
plain/wsgi.py,sha256=R6k5FiAElvGDApEbMPTT0MPqSD7n2e2Az5chQqJZU0I,236
|
155
|
-
plain-0.2.
|
156
|
-
plain-0.2.
|
157
|
-
plain-0.2.
|
158
|
-
plain-0.2.
|
159
|
-
plain-0.2.
|
155
|
+
plain-0.2.2.dist-info/LICENSE,sha256=m0D5O7QoH9l5Vz_rrX_9r-C8d9UNr_ciK6Qwac7o6yo,3175
|
156
|
+
plain-0.2.2.dist-info/METADATA,sha256=sYL_lmFR9UJE-JZY1IdPvynfYqcGsX_CAG33gryHqOQ,2716
|
157
|
+
plain-0.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
158
|
+
plain-0.2.2.dist-info/entry_points.txt,sha256=7O1RZTmMasKYB73bfqQcTwIhsXo7RjEIKv2WbtTtOIM,39
|
159
|
+
plain-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|