docs: add clearer automagic-snippet

This commit is contained in:
Daylin Morgan 2024-07-19 14:40:14 -05:00
parent 4f0c3c7da0
commit 28480919f7
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -16,15 +16,12 @@
```python ```python
# https://github.com/daylinmorgan/swydd?tab=readme-ov-file#automagic-snippet # https://github.com/daylinmorgan/swydd?tab=readme-ov-file#automagic-snippet
# fmt: off _src = (_i := __import__)("pathlib").Path(__file__).parent / "swydd/__init__.py"
if not (src := __import__("pathlib").Path(__file__).parent / "swydd/__init__.py").is_file(): # noqa if not (_i("importlib.util").util.find_spec("sywdd") or _src.is_file()):
try: __import__("swydd") # noqa _i("sys").stderr.write(f"installing swydd to {_src}\n")
except ImportError: _r= _i("urllib.request").request.urlopen("https://swydd.dayl.in/swydd.py")
import sys; from urllib.request import urlopen; from urllib.error import URLError # noqa _src.parent.mkdir(exist_ok=True)
try: r = urlopen("https://raw.githubusercontent.com/daylinmorgan/swydd/main/src/swydd/__init__.py") # noqa _src.write_text(_r.read().decode("utf-8"))
except URLError as e: sys.exit(f"{e}\n") # noqa
src.parent.mkdir(exist_ok=True); src.write_text(r.read().decode("utf-8")); # noqa
# fmt: on
``` ```
## Alternatives ## Alternatives