regwright-kernel 0.1.0__tar.gz
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.
- regwright_kernel-0.1.0/LICENSE +25 -0
- regwright_kernel-0.1.0/PKG-INFO +89 -0
- regwright_kernel-0.1.0/README.md +71 -0
- regwright_kernel-0.1.0/_backend/regwright_build.py +191 -0
- regwright_kernel-0.1.0/pyproject.toml +27 -0
- regwright_kernel-0.1.0/regwright_kernel/__init__.py +3 -0
- regwright_kernel-0.1.0/regwright_kernel/__main__.py +19 -0
- regwright_kernel-0.1.0/regwright_kernel/install.py +75 -0
- regwright_kernel-0.1.0/regwright_kernel/kernel.py +301 -0
- regwright_kernel-0.1.0/regwright_kernel/logo-32x32.png +0 -0
- regwright_kernel-0.1.0/regwright_kernel/logo-64x64.png +0 -0
- regwright_kernel-0.1.0/regwright_kernel/logo-svg.svg +5 -0
- regwright_kernel-0.1.0/regwright_kernel/serve.py +199 -0
- regwright_kernel-0.1.0/regwright_kernel/words.json +982 -0
- regwright_kernel-0.1.0/tests/test_kernel.py +252 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ALGD LTD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
This licence covers the code of this Jupyter kernel only. The Regwright
|
|
24
|
+
engine (the `regwright` command-line tool) is separate, commercial software
|
|
25
|
+
with its own licence terms: https://regwright.com/legal
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: regwright-kernel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Jupyter kernel for Stata syntax, powered by the Regwright engine (no Stata required)
|
|
5
|
+
Author: ALGD LTD
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: jupyter,kernel,stata,do-file,econometrics,statistics
|
|
9
|
+
Classifier: Framework :: Jupyter
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
13
|
+
Project-URL: Homepage, https://regwright.com
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Requires-Dist: ipykernel>=6.0
|
|
16
|
+
Requires-Dist: jupyter_client>=7.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# regwright-kernel
|
|
20
|
+
|
|
21
|
+
A Jupyter kernel that runs Stata syntax in notebooks (JupyterLab, Notebook, VS Code and nbconvert)
|
|
22
|
+
using the [Regwright](https://regwright.com) engine. You don't need Stata.
|
|
23
|
+
|
|
24
|
+
```stata
|
|
25
|
+
sysuse wages, clear
|
|
26
|
+
regress wage educ exper
|
|
27
|
+
scatter wage educ
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
1. Install the `regwright` command-line tool from [regwright.com](https://regwright.com), and
|
|
33
|
+
check that `regwright --version` works.
|
|
34
|
+
2. Install the kernel:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pip install regwright-kernel
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The wheel installs the kernelspec into the environment (`share/jupyter/kernels/regwright`). If
|
|
41
|
+
Jupyter runs from a different environment, register the kernel there yourself:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
python -m regwright_kernel install --user # or --sys-prefix, or --prefix PATH
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. Choose **Regwright (Stata syntax)** as the notebook kernel.
|
|
48
|
+
|
|
49
|
+
## What it does
|
|
50
|
+
|
|
51
|
+
- Each kernel keeps one `regwright serve` session, so data, macros and estimates carry over from
|
|
52
|
+
cell to cell, as they do in a Stata session.
|
|
53
|
+
- Output goes to stdout. Error messages go to stderr, and a failed cell has status `error` with the
|
|
54
|
+
Stata return code as its name (for example `r(111)`). A notebook run with `nbconvert --execute`
|
|
55
|
+
therefore stops at the first error, just as a do-file does.
|
|
56
|
+
- Graphs (`scatter`, `twoway`, `histogram`, `graph bar`…) appear under the cell as SVG.
|
|
57
|
+
- <kbd>Tab</kbd> completes command names at the start of a statement and variable names elsewhere.
|
|
58
|
+
<kbd>Shift</kbd>+<kbd>Tab</kbd> shows a variable's type, format and label, or a one-line summary
|
|
59
|
+
of a command.
|
|
60
|
+
|
|
61
|
+
## Settings (environment variables)
|
|
62
|
+
|
|
63
|
+
| Variable | Meaning |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `REGWRIGHT_PATH` | Path to the `regwright` binary, if it isn't on `PATH` |
|
|
66
|
+
| `REGWRIGHT_DATA` | Extra folders for `sysuse`/`use`, separated by `:` (`;` on Windows) |
|
|
67
|
+
| `REGWRIGHT_KERNEL_ECHO=1` | Echo each command (`. regress …`) before its output, as in a log |
|
|
68
|
+
| `REGWRIGHT_LICENSE` | Licence key. You can also install it with `regwright licence install KEY` |
|
|
69
|
+
|
|
70
|
+
**Regwright Free** handles datasets of up to 1,000 observations. Licences that remove the limit
|
|
71
|
+
are listed at [regwright.com/pricing](https://regwright.com/pricing).
|
|
72
|
+
|
|
73
|
+
## Building from source
|
|
74
|
+
|
|
75
|
+
The package has its own small build backend (`_backend/`), so it builds with no build dependencies:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
python -m pip wheel --no-deps --no-build-isolation kernel/ -w dist
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To run the tests you need a `regwright` binary plus ipykernel, jupyter_client, nbclient and nbformat:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
REGWRIGHT_BIN=/path/to/regwright REGWRIGHT_TEST_DATA=/path/with/wages.dta python kernel/tests/test_kernel.py
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
"Stata" is a trademark of StataCorp LLC. Regwright is an independent product and is not
|
|
88
|
+
affiliated with StataCorp. The kernel is MIT-licensed. The Regwright engine is commercial
|
|
89
|
+
software with a free tier.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# regwright-kernel
|
|
2
|
+
|
|
3
|
+
A Jupyter kernel that runs Stata syntax in notebooks (JupyterLab, Notebook, VS Code and nbconvert)
|
|
4
|
+
using the [Regwright](https://regwright.com) engine. You don't need Stata.
|
|
5
|
+
|
|
6
|
+
```stata
|
|
7
|
+
sysuse wages, clear
|
|
8
|
+
regress wage educ exper
|
|
9
|
+
scatter wage educ
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
1. Install the `regwright` command-line tool from [regwright.com](https://regwright.com), and
|
|
15
|
+
check that `regwright --version` works.
|
|
16
|
+
2. Install the kernel:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pip install regwright-kernel
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The wheel installs the kernelspec into the environment (`share/jupyter/kernels/regwright`). If
|
|
23
|
+
Jupyter runs from a different environment, register the kernel there yourself:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
python -m regwright_kernel install --user # or --sys-prefix, or --prefix PATH
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
3. Choose **Regwright (Stata syntax)** as the notebook kernel.
|
|
30
|
+
|
|
31
|
+
## What it does
|
|
32
|
+
|
|
33
|
+
- Each kernel keeps one `regwright serve` session, so data, macros and estimates carry over from
|
|
34
|
+
cell to cell, as they do in a Stata session.
|
|
35
|
+
- Output goes to stdout. Error messages go to stderr, and a failed cell has status `error` with the
|
|
36
|
+
Stata return code as its name (for example `r(111)`). A notebook run with `nbconvert --execute`
|
|
37
|
+
therefore stops at the first error, just as a do-file does.
|
|
38
|
+
- Graphs (`scatter`, `twoway`, `histogram`, `graph bar`…) appear under the cell as SVG.
|
|
39
|
+
- <kbd>Tab</kbd> completes command names at the start of a statement and variable names elsewhere.
|
|
40
|
+
<kbd>Shift</kbd>+<kbd>Tab</kbd> shows a variable's type, format and label, or a one-line summary
|
|
41
|
+
of a command.
|
|
42
|
+
|
|
43
|
+
## Settings (environment variables)
|
|
44
|
+
|
|
45
|
+
| Variable | Meaning |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `REGWRIGHT_PATH` | Path to the `regwright` binary, if it isn't on `PATH` |
|
|
48
|
+
| `REGWRIGHT_DATA` | Extra folders for `sysuse`/`use`, separated by `:` (`;` on Windows) |
|
|
49
|
+
| `REGWRIGHT_KERNEL_ECHO=1` | Echo each command (`. regress …`) before its output, as in a log |
|
|
50
|
+
| `REGWRIGHT_LICENSE` | Licence key. You can also install it with `regwright licence install KEY` |
|
|
51
|
+
|
|
52
|
+
**Regwright Free** handles datasets of up to 1,000 observations. Licences that remove the limit
|
|
53
|
+
are listed at [regwright.com/pricing](https://regwright.com/pricing).
|
|
54
|
+
|
|
55
|
+
## Building from source
|
|
56
|
+
|
|
57
|
+
The package has its own small build backend (`_backend/`), so it builds with no build dependencies:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
python -m pip wheel --no-deps --no-build-isolation kernel/ -w dist
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To run the tests you need a `regwright` binary plus ipykernel, jupyter_client, nbclient and nbformat:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
REGWRIGHT_BIN=/path/to/regwright REGWRIGHT_TEST_DATA=/path/with/wages.dta python kernel/tests/test_kernel.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
"Stata" is a trademark of StataCorp LLC. Regwright is an independent product and is not
|
|
70
|
+
affiliated with StataCorp. The kernel is MIT-licensed. The Regwright engine is commercial
|
|
71
|
+
software with a free tier.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""A minimal PEP 517 build backend using only the standard library (Python 3.11+ to build).
|
|
2
|
+
|
|
3
|
+
It builds the pure-Python wheel for regwright-kernel, including the kernelspec as wheel data
|
|
4
|
+
(share/jupyter/kernels/regwright), and an sdist. Metadata comes from pyproject.toml.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import base64
|
|
10
|
+
import hashlib
|
|
11
|
+
import io
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import tarfile
|
|
15
|
+
import time
|
|
16
|
+
import tomllib
|
|
17
|
+
import zipfile
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
21
|
+
PKG = "regwright_kernel"
|
|
22
|
+
KERNEL_NAME = "regwright"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _project() -> dict:
|
|
26
|
+
with open(ROOT / "pyproject.toml", "rb") as f:
|
|
27
|
+
return tomllib.load(f)["project"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _dist_name(p: dict) -> str:
|
|
31
|
+
return p["name"].replace("-", "_")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _metadata(p: dict) -> str:
|
|
35
|
+
lines = [
|
|
36
|
+
"Metadata-Version: 2.4",
|
|
37
|
+
f"Name: {p['name']}",
|
|
38
|
+
f"Version: {p['version']}",
|
|
39
|
+
f"Summary: {p['description']}",
|
|
40
|
+
]
|
|
41
|
+
for a in p.get("authors", []):
|
|
42
|
+
if "name" in a:
|
|
43
|
+
lines.append(f"Author: {a['name']}")
|
|
44
|
+
if isinstance(p.get("license"), str):
|
|
45
|
+
lines.append(f"License-Expression: {p['license']}")
|
|
46
|
+
for lf in p.get("license-files", []):
|
|
47
|
+
lines.append(f"License-File: {lf}")
|
|
48
|
+
if p.get("keywords"):
|
|
49
|
+
lines.append("Keywords: " + ",".join(p["keywords"]))
|
|
50
|
+
for c in p.get("classifiers", []):
|
|
51
|
+
lines.append(f"Classifier: {c}")
|
|
52
|
+
for label, url in p.get("urls", {}).items():
|
|
53
|
+
lines.append(f"Project-URL: {label}, {url}")
|
|
54
|
+
if p.get("requires-python"):
|
|
55
|
+
lines.append(f"Requires-Python: {p['requires-python']}")
|
|
56
|
+
for d in p.get("dependencies", []):
|
|
57
|
+
lines.append(f"Requires-Dist: {d}")
|
|
58
|
+
readme = p.get("readme")
|
|
59
|
+
body = ""
|
|
60
|
+
if readme:
|
|
61
|
+
lines.append("Description-Content-Type: text/markdown")
|
|
62
|
+
body = (ROOT / readme).read_text(encoding="utf-8")
|
|
63
|
+
return "\n".join(lines) + "\n\n" + body
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _package_files() -> list[Path]:
|
|
67
|
+
out = []
|
|
68
|
+
for f in sorted((ROOT / PKG).rglob("*")):
|
|
69
|
+
if f.is_file() and "__pycache__" not in f.parts and f.suffix not in (".pyc", ".pyo"):
|
|
70
|
+
out.append(f)
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _kernel_json() -> str:
|
|
75
|
+
return json.dumps(
|
|
76
|
+
{
|
|
77
|
+
# jupyter_client swaps a bare "python" for the running interpreter
|
|
78
|
+
"argv": ["python", "-m", PKG, "-f", "{connection_file}"],
|
|
79
|
+
"display_name": "Regwright (Stata syntax)",
|
|
80
|
+
"language": "stata",
|
|
81
|
+
"interrupt_mode": "signal",
|
|
82
|
+
"metadata": {"debugger": False},
|
|
83
|
+
},
|
|
84
|
+
indent=1,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class _Wheel:
|
|
89
|
+
def __init__(self, path: Path):
|
|
90
|
+
self.zf = zipfile.ZipFile(path, "w", compression=zipfile.ZIP_DEFLATED)
|
|
91
|
+
self.records: list[tuple[str, str, int]] = []
|
|
92
|
+
|
|
93
|
+
def add(self, arcname: str, data: bytes) -> None:
|
|
94
|
+
zi = zipfile.ZipInfo(arcname, date_time=(2026, 1, 1, 0, 0, 0))
|
|
95
|
+
zi.external_attr = 0o644 << 16
|
|
96
|
+
zi.compress_type = zipfile.ZIP_DEFLATED
|
|
97
|
+
self.zf.writestr(zi, data)
|
|
98
|
+
digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode()
|
|
99
|
+
self.records.append((arcname, f"sha256={digest}", len(data)))
|
|
100
|
+
|
|
101
|
+
def close(self, record_name: str) -> None:
|
|
102
|
+
rec = io.StringIO()
|
|
103
|
+
for name, h, n in self.records:
|
|
104
|
+
rec.write(f"{name},{h},{n}\n")
|
|
105
|
+
rec.write(f"{record_name},,\n")
|
|
106
|
+
zi = zipfile.ZipInfo(record_name, date_time=(2026, 1, 1, 0, 0, 0))
|
|
107
|
+
zi.external_attr = 0o644 << 16
|
|
108
|
+
self.zf.writestr(zi, rec.getvalue())
|
|
109
|
+
self.zf.close()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _write_wheel(wheel_directory: str, editable: bool = False) -> str:
|
|
113
|
+
p = _project()
|
|
114
|
+
dist = _dist_name(p)
|
|
115
|
+
ver = p["version"]
|
|
116
|
+
name = f"{dist}-{ver}-py3-none-any.whl"
|
|
117
|
+
distinfo = f"{dist}-{ver}.dist-info"
|
|
118
|
+
data = f"{dist}-{ver}.data/data/share/jupyter/kernels/{KERNEL_NAME}"
|
|
119
|
+
w = _Wheel(Path(wheel_directory) / name)
|
|
120
|
+
if editable:
|
|
121
|
+
w.add(f"__editable__.{dist}.pth", (str(ROOT) + "\n").encode())
|
|
122
|
+
else:
|
|
123
|
+
for f in _package_files():
|
|
124
|
+
w.add(f.relative_to(ROOT).as_posix(), f.read_bytes())
|
|
125
|
+
w.add(f"{data}/kernel.json", _kernel_json().encode())
|
|
126
|
+
for logo in ("logo-32x32.png", "logo-64x64.png", "logo-svg.svg"):
|
|
127
|
+
src = ROOT / PKG / logo
|
|
128
|
+
if src.exists():
|
|
129
|
+
w.add(f"{data}/{logo}", src.read_bytes())
|
|
130
|
+
w.add(f"{distinfo}/METADATA", _metadata(p).encode())
|
|
131
|
+
w.add(
|
|
132
|
+
f"{distinfo}/WHEEL",
|
|
133
|
+
b"Wheel-Version: 1.0\nGenerator: regwright_build 0.1\nRoot-Is-Purelib: true\nTag: py3-none-any\n",
|
|
134
|
+
)
|
|
135
|
+
for lf in p.get("license-files", []):
|
|
136
|
+
w.add(f"{distinfo}/licenses/{lf}", (ROOT / lf).read_bytes())
|
|
137
|
+
w.close(f"{distinfo}/RECORD")
|
|
138
|
+
return name
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# ----- PEP 517 hooks -----
|
|
142
|
+
|
|
143
|
+
def get_requires_for_build_wheel(config_settings=None):
|
|
144
|
+
return []
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def get_requires_for_build_sdist(config_settings=None):
|
|
148
|
+
return []
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def get_requires_for_build_editable(config_settings=None):
|
|
152
|
+
return []
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
|
|
156
|
+
return _write_wheel(wheel_directory)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
|
|
160
|
+
return _write_wheel(wheel_directory, editable=True)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def build_sdist(sdist_directory, config_settings=None):
|
|
164
|
+
p = _project()
|
|
165
|
+
base = f"{_dist_name(p)}-{p['version']}"
|
|
166
|
+
name = f"{base}.tar.gz"
|
|
167
|
+
files = [ROOT / "pyproject.toml", ROOT / "README.md", ROOT / "LICENSE", ROOT / "_backend" / "regwright_build.py"]
|
|
168
|
+
files += _package_files()
|
|
169
|
+
files += [f for f in sorted((ROOT / "tests").glob("*.py"))]
|
|
170
|
+
with tarfile.open(Path(sdist_directory) / name, "w:gz", format=tarfile.PAX_FORMAT) as tf:
|
|
171
|
+
def add_bytes(arc: str, data: bytes) -> None:
|
|
172
|
+
ti = tarfile.TarInfo(arc)
|
|
173
|
+
ti.size = len(data)
|
|
174
|
+
ti.mtime = int(time.time())
|
|
175
|
+
ti.mode = 0o644
|
|
176
|
+
tf.addfile(ti, io.BytesIO(data))
|
|
177
|
+
|
|
178
|
+
for f in files:
|
|
179
|
+
if f.exists():
|
|
180
|
+
add_bytes(f"{base}/{f.relative_to(ROOT).as_posix()}", f.read_bytes())
|
|
181
|
+
add_bytes(f"{base}/PKG-INFO", _metadata(p).encode())
|
|
182
|
+
return name
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
if __name__ == "__main__": # manual build: python _backend/regwright_build.py OUTDIR
|
|
186
|
+
import sys
|
|
187
|
+
|
|
188
|
+
out = sys.argv[1] if len(sys.argv) > 1 else str(ROOT / "dist")
|
|
189
|
+
os.makedirs(out, exist_ok=True)
|
|
190
|
+
print(build_wheel(out))
|
|
191
|
+
print(build_sdist(out))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# A small standard-library build backend lives in _backend/, so the wheel builds offline with no
|
|
3
|
+
# build dependencies: python -m pip wheel --no-deps --no-build-isolation kernel/ -w dist
|
|
4
|
+
requires = []
|
|
5
|
+
build-backend = "regwright_build"
|
|
6
|
+
backend-path = ["_backend"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "regwright-kernel"
|
|
10
|
+
version = "0.1.0"
|
|
11
|
+
description = "Jupyter kernel for Stata syntax, powered by the Regwright engine (no Stata required)"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.9"
|
|
16
|
+
authors = [{ name = "ALGD LTD" }]
|
|
17
|
+
keywords = ["jupyter", "kernel", "stata", "do-file", "econometrics", "statistics"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Framework :: Jupyter",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["ipykernel>=6.0", "jupyter_client>=7.0"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://regwright.com"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""`python -m regwright_kernel` starts the kernel; `python -m regwright_kernel install` installs its spec."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main() -> None:
|
|
7
|
+
if len(sys.argv) > 1 and sys.argv[1] == "install":
|
|
8
|
+
from .install import main as install_main
|
|
9
|
+
|
|
10
|
+
sys.exit(install_main(sys.argv[2:]))
|
|
11
|
+
from ipykernel.kernelapp import IPKernelApp
|
|
12
|
+
|
|
13
|
+
from .kernel import RegwrightKernel
|
|
14
|
+
|
|
15
|
+
IPKernelApp.launch_instance(kernel_class=RegwrightKernel)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
main()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Install the Regwright kernelspec so Jupyter lists "Regwright (Stata syntax)"."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
from importlib import resources
|
|
12
|
+
|
|
13
|
+
KERNEL_NAME = "regwright"
|
|
14
|
+
DISPLAY_NAME = "Regwright (Stata syntax)"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def kernel_json(python: str | None = None) -> dict:
|
|
18
|
+
return {
|
|
19
|
+
"argv": [python or sys.executable, "-m", "regwright_kernel", "-f", "{connection_file}"],
|
|
20
|
+
"display_name": DISPLAY_NAME,
|
|
21
|
+
"language": "stata",
|
|
22
|
+
"interrupt_mode": "signal",
|
|
23
|
+
"metadata": {"debugger": False},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def write_spec(directory: str, python: str | None = None) -> None:
|
|
28
|
+
os.makedirs(directory, exist_ok=True)
|
|
29
|
+
with open(os.path.join(directory, "kernel.json"), "w", encoding="utf-8") as f:
|
|
30
|
+
json.dump(kernel_json(python), f, indent=1)
|
|
31
|
+
pkg = resources.files(__package__)
|
|
32
|
+
for name in ("logo-32x32.png", "logo-64x64.png", "logo-svg.svg"):
|
|
33
|
+
src = pkg.joinpath(name)
|
|
34
|
+
if src.is_file():
|
|
35
|
+
with resources.as_file(src) as p:
|
|
36
|
+
shutil.copy(p, os.path.join(directory, name))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def install(user: bool = False, prefix: str | None = None, sys_prefix: bool = False, name: str = KERNEL_NAME) -> str:
|
|
40
|
+
from jupyter_client.kernelspec import KernelSpecManager
|
|
41
|
+
|
|
42
|
+
if sys_prefix:
|
|
43
|
+
prefix = sys.prefix
|
|
44
|
+
if not user and prefix is None and not _can_write_system():
|
|
45
|
+
user = True
|
|
46
|
+
with tempfile.TemporaryDirectory() as td:
|
|
47
|
+
write_spec(td)
|
|
48
|
+
return KernelSpecManager().install_kernel_spec(td, name, user=user, prefix=prefix)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _can_write_system() -> bool:
|
|
52
|
+
from jupyter_core.paths import SYSTEM_JUPYTER_PATH
|
|
53
|
+
|
|
54
|
+
for p in SYSTEM_JUPYTER_PATH:
|
|
55
|
+
try:
|
|
56
|
+
os.makedirs(p, exist_ok=True)
|
|
57
|
+
return os.access(p, os.W_OK)
|
|
58
|
+
except OSError:
|
|
59
|
+
continue
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def main(argv: list[str] | None = None) -> int:
|
|
64
|
+
ap = argparse.ArgumentParser(prog="python -m regwright_kernel install", description=f"Install the {DISPLAY_NAME} kernelspec.")
|
|
65
|
+
where = ap.add_mutually_exclusive_group()
|
|
66
|
+
where.add_argument("--user", action="store_true", help="install for the current user (default when the system folder is read-only)")
|
|
67
|
+
where.add_argument("--sys-prefix", action="store_true", help="install into this Python environment (venv/conda)")
|
|
68
|
+
where.add_argument("--prefix", help="install under PREFIX/share/jupyter/kernels")
|
|
69
|
+
ap.add_argument("--name", default=KERNEL_NAME, help="kernelspec name (default: regwright)")
|
|
70
|
+
a = ap.parse_args(argv)
|
|
71
|
+
dest = install(user=a.user, prefix=a.prefix, sys_prefix=a.sys_prefix, name=a.name)
|
|
72
|
+
print(f"Installed kernelspec {a.name!r} ({DISPLAY_NAME}) in {dest}")
|
|
73
|
+
if not shutil.which("regwright") and not os.environ.get("REGWRIGHT_PATH"):
|
|
74
|
+
print("Note: the regwright CLI is not on PATH. Install it from https://regwright.com or set REGWRIGHT_PATH.")
|
|
75
|
+
return 0
|