Skip to content

Commit eb8e887

Browse files
authored
Merge pull request #4 from t-strings/add-playground
Add playground
2 parents 4a25536 + 2c3a704 commit eb8e887

File tree

89 files changed

+9787
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+9787
-112
lines changed

.github/workflows/build-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install the project
3737
run: uv sync --locked --all-extras --dev
3838
- name: Build sphinx site
39-
run: uv run make html
39+
run: uv run make playground
4040
- name: Copy CNAME from root into build
4141
run: |
4242
if [ -f CNAME ]; then

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,32 @@ help:
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
2020
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
21+
22+
23+
.PHONY: build-playground
24+
build-playground: check-jq
25+
@echo "Building playground..."
26+
rm -rf public/lite
27+
jupyter lite build
28+
python tools/patch_jlite_json.py \
29+
public/lite/jupyter-lite.json && \
30+
cp -frpv pyodide public/lite/
31+
32+
33+
34+
.PHONY: wheel
35+
wheel: clean-wheel
36+
$(VENV_PATH)/bin/python -m build
37+
38+
39+
.PHONY: clean-wheel
40+
clean-wheel:
41+
rm -rf public/lite
42+
43+
.PHONY: clean-playground
44+
clean-playground:
45+
rm -rf public/lite
46+
47+
.PHONY: check-jq
48+
check-jq:
49+
which jq || (echo "jq is not installed. Please install jq to continue." && exit 1)

content/hello.ipynb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {
5+
"jupyter": {
6+
"is_executing": true
7+
}
8+
},
9+
"cell_type": "code",
10+
"source": [
11+
"name = \"World\"\n",
12+
"message = t\"Hello {name}\"\n",
13+
"print(message)\n"
14+
],
15+
"id": "1673818a171b3b31",
16+
"outputs": [],
17+
"execution_count": null
18+
}
19+
],
20+
"metadata": {},
21+
"nbformat": 4,
22+
"nbformat_minor": 5
23+
}

jupyter-lite.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"litePluginSettings": {
3+
"@jupyterlite/pyodide-kernel-extension:kernel": {
4+
"pyodideUrl": "./pyodide/pyodide.js",
5+
"loadPyodideOptions": {
6+
"indexURL": "./pyodide/"
7+
}
8+
}
9+
}
10+
}

jupyter_lite_config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"LiteBuildConfig": {
3+
"contents": [
4+
"./content"
5+
],
6+
"output_dir": "public/lite"
7+
}
8+
}

public/playground.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
transition: color 0.2s;
4343
}
4444

45+
.text-xxs {
46+
font-size: 0.7em;
47+
}
48+
49+
nav > a {
50+
color: var(--color-gray-500);
51+
}
52+
4553
strong {
4654
color: #333;
4755
}
@@ -70,7 +78,18 @@
7078
class="flex flex-col items-center min-h-screen bg-lightest-wash py-8 bg-light-cloudbank text-treeline"
7179
>
7280
<div class="mx-3 md:mx-auto max-w-sm pb-4 space-y-4">
73-
<p>Put your playground here!</p>
81+
<nav class="text-xxs flex flex-row gap-x-4">
82+
<a href="/">home</a>
83+
<a href="/introduction.html">brief intro</a>
84+
<a href="/playground.html">playground</a>
85+
</nav>
86+
<h1 class="font-serif font-bold text-cloudbank text-3xl">
87+
T-strings playground!
88+
</h1>
89+
<p>
90+
<strong>Let's try t-strings now!!</strong>
91+
</p>
92+
<iframe src="./lite/tree/../notebooks/index.html?path=hello.ipynb" width="100%" height="1000px" ></iframe>
7493
</div>
7594
</div>
7695
</body>
130 KB
Binary file not shown.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Metadata-Version: 2.1
2+
Name: Jinja2
3+
Version: 3.1.3
4+
Summary: A very fast and expressive template engine.
5+
Home-page: https://palletsprojects.com/p/jinja/
6+
Maintainer: Pallets
7+
Maintainer-email: [email protected]
8+
License: BSD-3-Clause
9+
Project-URL: Donate, https://palletsprojects.com/donate
10+
Project-URL: Documentation, https://jinja.palletsprojects.com/
11+
Project-URL: Changes, https://jinja.palletsprojects.com/changes/
12+
Project-URL: Source Code, https://github.com/pallets/jinja/
13+
Project-URL: Issue Tracker, https://github.com/pallets/jinja/issues/
14+
Project-URL: Chat, https://discord.gg/pallets
15+
Classifier: Development Status :: 5 - Production/Stable
16+
Classifier: Environment :: Web Environment
17+
Classifier: Intended Audience :: Developers
18+
Classifier: License :: OSI Approved :: BSD License
19+
Classifier: Operating System :: OS Independent
20+
Classifier: Programming Language :: Python
21+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22+
Classifier: Topic :: Text Processing :: Markup :: HTML
23+
Requires-Python: >=3.7
24+
Description-Content-Type: text/x-rst
25+
License-File: LICENSE.rst
26+
Requires-Dist: MarkupSafe >=2.0
27+
Provides-Extra: i18n
28+
Requires-Dist: Babel >=2.7 ; extra == 'i18n'
29+
30+
Jinja
31+
=====
32+
33+
Jinja is a fast, expressive, extensible templating engine. Special
34+
placeholders in the template allow writing code similar to Python
35+
syntax. Then the template is passed data to render the final document.
36+
37+
It includes:
38+
39+
- Template inheritance and inclusion.
40+
- Define and import macros within templates.
41+
- HTML templates can use autoescaping to prevent XSS from untrusted
42+
user input.
43+
- A sandboxed environment can safely render untrusted templates.
44+
- AsyncIO support for generating templates and calling async
45+
functions.
46+
- I18N support with Babel.
47+
- Templates are compiled to optimized Python code just-in-time and
48+
cached, or can be compiled ahead-of-time.
49+
- Exceptions point to the correct line in templates to make debugging
50+
easier.
51+
- Extensible filters, tests, functions, and even syntax.
52+
53+
Jinja's philosophy is that while application logic belongs in Python if
54+
possible, it shouldn't make the template designer's job difficult by
55+
restricting functionality too much.
56+
57+
58+
Installing
59+
----------
60+
61+
Install and update using `pip`_:
62+
63+
.. code-block:: text
64+
65+
$ pip install -U Jinja2
66+
67+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
68+
69+
70+
In A Nutshell
71+
-------------
72+
73+
.. code-block:: jinja
74+
75+
{% extends "base.html" %}
76+
{% block title %}Members{% endblock %}
77+
{% block content %}
78+
<ul>
79+
{% for user in users %}
80+
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
81+
{% endfor %}
82+
</ul>
83+
{% endblock %}
84+
85+
86+
Donate
87+
------
88+
89+
The Pallets organization develops and supports Jinja and other popular
90+
packages. In order to grow the community of contributors and users, and
91+
allow the maintainers to devote more time to the projects, `please
92+
donate today`_.
93+
94+
.. _please donate today: https://palletsprojects.com/donate
95+
96+
97+
Links
98+
-----
99+
100+
- Documentation: https://jinja.palletsprojects.com/
101+
- Changes: https://jinja.palletsprojects.com/changes/
102+
- PyPI Releases: https://pypi.org/project/Jinja2/
103+
- Source Code: https://github.com/pallets/jinja/
104+
- Issue Tracker: https://github.com/pallets/jinja/issues/
105+
- Chat: https://discord.gg/pallets
6.85 KB
Binary file not shown.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
Metadata-Version: 2.4
2+
Name: atomicwrites
3+
Version: 1.4.1
4+
Summary: Atomic file writes.
5+
Home-page: https://github.com/untitaker/python-atomicwrites
6+
Author: Markus Unterwaditzer
7+
Author-email: [email protected]
8+
License: MIT
9+
Classifier: License :: OSI Approved :: MIT License
10+
Classifier: Programming Language :: Python :: 2
11+
Classifier: Programming Language :: Python :: 2.7
12+
Classifier: Programming Language :: Python :: 3
13+
Classifier: Programming Language :: Python :: 3.4
14+
Classifier: Programming Language :: Python :: 3.5
15+
Classifier: Programming Language :: Python :: 3.6
16+
Classifier: Programming Language :: Python :: 3.7
17+
Classifier: Programming Language :: Python :: 3.8
18+
Classifier: Programming Language :: Python :: Implementation :: CPython
19+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
20+
License-File: LICENSE
21+
Dynamic: author
22+
Dynamic: author-email
23+
Dynamic: classifier
24+
Dynamic: description
25+
Dynamic: home-page
26+
Dynamic: license
27+
Dynamic: license-file
28+
Dynamic: requires-python
29+
Dynamic: summary
30+
31+
===================
32+
python-atomicwrites
33+
===================
34+
35+
.. image:: https://travis-ci.com/untitaker/python-atomicwrites.svg?branch=master
36+
:target: https://travis-ci.com/untitaker/python-atomicwrites
37+
.. image:: https://ci.appveyor.com/api/projects/status/vadc4le3c27to59x/branch/master?svg=true
38+
:target: https://ci.appveyor.com/project/untitaker/python-atomicwrites/branch/master
39+
.. image:: https://readthedocs.org/projects/python-atomicwrites/badge/?version=latest
40+
:target: https://python-atomicwrites.readthedocs.io/en/latest/?badge=latest
41+
:alt: Documentation Status
42+
43+
**Atomic file writes.**
44+
45+
.. code-block:: python
46+
47+
from atomicwrites import atomic_write
48+
49+
with atomic_write('foo.txt', overwrite=True) as f:
50+
f.write('Hello world.')
51+
# "foo.txt" doesn't exist yet.
52+
53+
# Now it does.
54+
55+
See `API documentation <https://python-atomicwrites.readthedocs.io/en/latest/#api>`_ for more
56+
low-level interfaces.
57+
58+
Features that distinguish it from other similar libraries (see `Alternatives and Credit`_):
59+
60+
- Race-free assertion that the target file doesn't yet exist. This can be
61+
controlled with the ``overwrite`` parameter.
62+
63+
- Windows support, although not well-tested. The MSDN resources are not very
64+
explicit about which operations are atomic. I'm basing my assumptions off `a
65+
comment
66+
<https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/449bb49d-8acc-48dc-a46f-0760ceddbfc3/movefileexmovefilereplaceexisting-ntfs-same-volume-atomic?forum=windowssdk#a239bc26-eaf0-4920-9f21-440bd2be9cc8>`_
67+
by `Doug Cook
68+
<https://social.msdn.microsoft.com/Profile/doug%20e.%20cook>`_, who appears
69+
to be a Microsoft employee:
70+
71+
Question: Is MoveFileEx atomic if the existing and new
72+
files are both on the same drive?
73+
74+
The simple answer is "usually, but in some cases it will silently fall-back
75+
to a non-atomic method, so don't count on it".
76+
77+
The implementation of MoveFileEx looks something like this: [...]
78+
79+
The problem is if the rename fails, you might end up with a CopyFile, which
80+
is definitely not atomic.
81+
82+
If you really need atomic-or-nothing, you can try calling
83+
NtSetInformationFile, which is unsupported but is much more likely to be
84+
atomic.
85+
86+
- Simple high-level API that wraps a very flexible class-based API.
87+
88+
- Consistent error handling across platforms.
89+
90+
91+
How it works
92+
============
93+
94+
It uses a temporary file in the same directory as the given path. This ensures
95+
that the temporary file resides on the same filesystem.
96+
97+
The temporary file will then be atomically moved to the target location: On
98+
POSIX, it will use ``rename`` if files should be overwritten, otherwise a
99+
combination of ``link`` and ``unlink``. On Windows, it uses MoveFileEx_ through
100+
stdlib's ``ctypes`` with the appropriate flags.
101+
102+
Note that with ``link`` and ``unlink``, there's a timewindow where the file
103+
might be available under two entries in the filesystem: The name of the
104+
temporary file, and the name of the target file.
105+
106+
Also note that the permissions of the target file may change this way. In some
107+
situations a ``chmod`` can be issued without any concurrency problems, but
108+
since that is not always the case, this library doesn't do it by itself.
109+
110+
.. _MoveFileEx: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx
111+
112+
fsync
113+
-----
114+
115+
On POSIX, ``fsync`` is invoked on the temporary file after it is written (to
116+
flush file content and metadata), and on the parent directory after the file is
117+
moved (to flush filename).
118+
119+
``fsync`` does not take care of disks' internal buffers, but there don't seem
120+
to be any standard POSIX APIs for that. On OS X, ``fcntl`` is used with
121+
``F_FULLFSYNC`` instead of ``fsync`` for that reason.
122+
123+
On Windows, `_commit <https://msdn.microsoft.com/en-us/library/17618685.aspx>`_
124+
is used, but there are no guarantees about disk internal buffers.
125+
126+
Alternatives and Credit
127+
=======================
128+
129+
Atomicwrites is directly inspired by the following libraries (and shares a
130+
minimal amount of code):
131+
132+
- The Trac project's `utility functions
133+
<http://www.edgewall.org/docs/tags-trac-0.11.7/epydoc/trac.util-pysrc.html>`_,
134+
also used in `Werkzeug <http://werkzeug.pocoo.org/>`_ and
135+
`mitsuhiko/python-atomicfile
136+
<https://github.com/mitsuhiko/python-atomicfile>`_. The idea to use
137+
``ctypes`` instead of ``PyWin32`` originated there.
138+
139+
- `abarnert/fatomic <https://github.com/abarnert/fatomic>`_. Windows support
140+
(based on ``PyWin32``) was originally taken from there.
141+
142+
Other alternatives to atomicwrites include:
143+
144+
- `sashka/atomicfile <https://github.com/sashka/atomicfile>`_. Originally I
145+
considered using that, but at the time it was lacking a lot of features I
146+
needed (Windows support, overwrite-parameter, overriding behavior through
147+
subclassing).
148+
149+
- The `Boltons library collection <https://github.com/mahmoud/boltons>`_
150+
features a class for atomic file writes, which seems to have a very similar
151+
``overwrite`` parameter. It is lacking Windows support though.
152+
153+
License
154+
=======
155+
156+
Licensed under the MIT, see ``LICENSE``.

0 commit comments

Comments
 (0)