trame-code 1.0.1__tar.gz → 1.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.
- trame_code-1.1.0/.codespellrc +2 -0
- trame_code-1.1.0/.github/workflows/test_and_release.yml +122 -0
- trame_code-1.1.0/.gitignore +27 -0
- trame_code-1.1.0/.pre-commit-config.yaml +68 -0
- trame_code-1.1.0/CHANGELOG.md +67 -0
- trame_code-1.1.0/CONTRIBUTING.rst +19 -0
- {trame-code-1.0.1/trame_code.egg-info → trame_code-1.1.0}/PKG-INFO +27 -8
- trame_code-1.1.0/README.rst +44 -0
- trame_code-1.1.0/example/language-features/app.py +99 -0
- trame_code-1.1.0/example/language-features/requirements.txt +4 -0
- trame_code-1.1.0/example/live-state/app.py +129 -0
- trame_code-1.1.0/example/live-state/requirements.txt +3 -0
- trame_code-1.1.0/example/read-only/requirements.txt +2 -0
- trame_code-1.1.0/example/read-only/viewer.py +105 -0
- trame_code-1.1.0/example/read-only/viewer_vue3.py +114 -0
- trame_code-1.1.0/example/textmate/app.py +105 -0
- trame_code-1.1.0/example/textmate/files/javascript_example.js +221 -0
- trame_code-1.1.0/example/textmate/files/latex_example.tex +9 -0
- trame_code-1.1.0/example/textmate/files/moose_example.i +106 -0
- trame_code-1.1.0/example/textmate/files/python_example.py +9 -0
- trame_code-1.1.0/example/textmate/langs/__init__.py +6 -0
- trame_code-1.1.0/example/textmate/langs/moose/__init__.py +24 -0
- trame_code-1.1.0/example/textmate/langs/moose/moose.config.json +41 -0
- trame_code-1.1.0/example/textmate/langs/moose/moose.grammar.json +321 -0
- trame_code-1.1.0/example/textmate/langs/python/__init__.py +38 -0
- trame_code-1.1.0/example/textmate/langs/python/python.config.json +135 -0
- trame_code-1.1.0/example/textmate/langs/python/python.grammar.json +5335 -0
- trame_code-1.1.0/pyproject.toml +98 -0
- trame_code-1.1.0/src/trame_code/module/.gitignore +5 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/__init__.py +0 -1
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/trame-code.umd.js +312 -312
- trame_code-1.1.0/src/trame_code/widgets/code.py +78 -0
- trame_code-1.1.0/tests/requirements.txt +2 -0
- trame_code-1.1.0/tests/test_import.py +4 -0
- trame_code-1.1.0/tests/test_language_features.py +30 -0
- trame_code-1.1.0/vue-components/.eslintrc.cjs +14 -0
- trame_code-1.1.0/vue-components/.gitignore +23 -0
- trame_code-1.1.0/vue-components/.prettierrc.json +1 -0
- trame_code-1.1.0/vue-components/README.md +29 -0
- trame_code-1.1.0/vue-components/package-lock.json +13079 -0
- trame_code-1.1.0/vue-components/package.json +31 -0
- trame_code-1.1.0/vue-components/src/components/Editor.js +293 -0
- trame_code-1.1.0/vue-components/src/components/index.js +5 -0
- trame_code-1.1.0/vue-components/src/themes/README.md +2 -0
- trame_code-1.1.0/vue-components/src/themes/dark_plus.json +192 -0
- trame_code-1.1.0/vue-components/src/themes/dark_plus_experimental.json +139 -0
- trame_code-1.1.0/vue-components/src/themes/dark_vs.json +393 -0
- trame_code-1.1.0/vue-components/src/themes/hc_black.json +457 -0
- trame_code-1.1.0/vue-components/src/themes/hc_light.json +566 -0
- trame_code-1.1.0/vue-components/src/themes/index.js +70 -0
- trame_code-1.1.0/vue-components/src/themes/light_plus.json +193 -0
- trame_code-1.1.0/vue-components/src/themes/light_plus_experimental.json +152 -0
- trame_code-1.1.0/vue-components/src/themes/light_vs.json +420 -0
- trame_code-1.1.0/vue-components/src/themes/reference-style-textmate.txt +533 -0
- trame_code-1.1.0/vue-components/src/use.js +7 -0
- trame_code-1.1.0/vue-components/src/utils/monacoEnv.js +50 -0
- trame_code-1.1.0/vue-components/src/utils/onig.js +17 -0
- trame_code-1.1.0/vue-components/src/utils/textmate.js +229 -0
- trame_code-1.1.0/vue-components/vite.config.ts +27 -0
- trame-code-1.0.1/MANIFEST.in +0 -1
- trame-code-1.0.1/PKG-INFO +0 -49
- trame-code-1.0.1/README.rst +0 -30
- trame-code-1.0.1/setup.cfg +0 -38
- trame-code-1.0.1/setup.py +0 -3
- trame-code-1.0.1/trame_code/widgets/code.py +0 -50
- trame-code-1.0.1/trame_code.egg-info/SOURCES.txt +0 -26
- trame-code-1.0.1/trame_code.egg-info/dependency_links.txt +0 -1
- trame-code-1.0.1/trame_code.egg-info/requires.txt +0 -1
- trame-code-1.0.1/trame_code.egg-info/top_level.txt +0 -2
- {trame-code-1.0.1 → trame_code-1.1.0}/LICENSE +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame/__init__.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame/modules/__init__.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame/modules/code.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame/widgets/__init__.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame/widgets/code.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/__init__.py +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/monacoeditorwork/css.worker.bundle.js +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/monacoeditorwork/editor.worker.bundle.js +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/monacoeditorwork/html.worker.bundle.js +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/monacoeditorwork/json.worker.bundle.js +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/monacoeditorwork/ts.worker.bundle.js +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/module/serve/style.css +0 -0
- {trame-code-1.0.1 → trame_code-1.1.0/src}/trame_code/widgets/__init__.py +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
name: Test and Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
pre-commit:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
env:
|
|
13
|
+
UV_PYTHON: "3.12"
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v6
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v6
|
|
18
|
+
with:
|
|
19
|
+
version: "0.8.12"
|
|
20
|
+
enable-cache: true
|
|
21
|
+
- name: Install the project
|
|
22
|
+
run: uv sync --all-extras --dev
|
|
23
|
+
|
|
24
|
+
# Install and run pre-commit
|
|
25
|
+
- run: |
|
|
26
|
+
uv run pre-commit install
|
|
27
|
+
uv run pre-commit run --all-files
|
|
28
|
+
|
|
29
|
+
pytest:
|
|
30
|
+
name: Pytest ${{ matrix.config.name }}
|
|
31
|
+
runs-on: ${{ matrix.config.os }}
|
|
32
|
+
strategy:
|
|
33
|
+
fail-fast: false
|
|
34
|
+
matrix:
|
|
35
|
+
python-version: ["3.12"]
|
|
36
|
+
config:
|
|
37
|
+
- { name: "Linux", os: ubuntu-latest }
|
|
38
|
+
- { name: "MacOSX", os: macos-latest }
|
|
39
|
+
- { name: "Windows", os: windows-latest }
|
|
40
|
+
|
|
41
|
+
defaults:
|
|
42
|
+
run:
|
|
43
|
+
shell: bash
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- name: Checkout
|
|
47
|
+
uses: actions/checkout@v6
|
|
48
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
49
|
+
uses: actions/setup-python@v6
|
|
50
|
+
with:
|
|
51
|
+
python-version: ${{ matrix.python-version }}
|
|
52
|
+
- name: Install uv
|
|
53
|
+
uses: astral-sh/setup-uv@v6
|
|
54
|
+
with:
|
|
55
|
+
version: "0.8.12"
|
|
56
|
+
enable-cache: true
|
|
57
|
+
- name: Install and Run Tests
|
|
58
|
+
run: |
|
|
59
|
+
uv sync --dev
|
|
60
|
+
uv pip install -r tests/requirements.txt
|
|
61
|
+
uv run pytest -s ./tests
|
|
62
|
+
|
|
63
|
+
test-npm-build:
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
|
|
66
|
+
steps:
|
|
67
|
+
- name: Checkout
|
|
68
|
+
uses: actions/checkout@v6
|
|
69
|
+
|
|
70
|
+
- name: Set Up Node
|
|
71
|
+
uses: actions/setup-node@v6
|
|
72
|
+
with:
|
|
73
|
+
node-version: 24
|
|
74
|
+
|
|
75
|
+
- name: Build Vue Components
|
|
76
|
+
run: |
|
|
77
|
+
cd vue-components
|
|
78
|
+
npm i
|
|
79
|
+
npm run build
|
|
80
|
+
|
|
81
|
+
release:
|
|
82
|
+
needs: [pre-commit, pytest, test-npm-build]
|
|
83
|
+
runs-on: ubuntu-latest
|
|
84
|
+
environment: release
|
|
85
|
+
permissions:
|
|
86
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
87
|
+
contents: write # IMPORTANT: mandatory for making GitHub Releases
|
|
88
|
+
attestations: write # IMPORTANT: mandatory to attest build provenance
|
|
89
|
+
if: github.event_name == 'push'
|
|
90
|
+
|
|
91
|
+
steps:
|
|
92
|
+
- name: Checkout
|
|
93
|
+
uses: actions/checkout@v6
|
|
94
|
+
with:
|
|
95
|
+
fetch-depth: 0
|
|
96
|
+
|
|
97
|
+
- name: Set Up Node
|
|
98
|
+
uses: actions/setup-node@v6
|
|
99
|
+
with:
|
|
100
|
+
node-version: 24
|
|
101
|
+
|
|
102
|
+
- name: Build Vue Components
|
|
103
|
+
run: |
|
|
104
|
+
cd vue-components
|
|
105
|
+
npm i
|
|
106
|
+
npm run build
|
|
107
|
+
|
|
108
|
+
- name: Python Semantic Release
|
|
109
|
+
id: release
|
|
110
|
+
uses: python-semantic-release/python-semantic-release@v10.5.3
|
|
111
|
+
with:
|
|
112
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
113
|
+
|
|
114
|
+
- name: Generate artifact attestation for sdist and wheel
|
|
115
|
+
if: steps.release.outputs.released == 'true'
|
|
116
|
+
uses: actions/attest-build-provenance@v4.1.0
|
|
117
|
+
with:
|
|
118
|
+
subject-path: "dist/*"
|
|
119
|
+
|
|
120
|
+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
|
|
121
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
122
|
+
if: steps.release.outputs.released == 'true'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
node_modules
|
|
3
|
+
.venv
|
|
4
|
+
build
|
|
5
|
+
|
|
6
|
+
# local env files
|
|
7
|
+
.env.local
|
|
8
|
+
.env.*.local
|
|
9
|
+
|
|
10
|
+
# Log files
|
|
11
|
+
npm-debug.log*
|
|
12
|
+
yarn-debug.log*
|
|
13
|
+
yarn-error.log*
|
|
14
|
+
pnpm-debug.log*
|
|
15
|
+
|
|
16
|
+
# Editor directories and files
|
|
17
|
+
.idea
|
|
18
|
+
.vscode
|
|
19
|
+
*.suo
|
|
20
|
+
*.ntvs*
|
|
21
|
+
*.njsproj
|
|
22
|
+
*.sln
|
|
23
|
+
*.sw?
|
|
24
|
+
|
|
25
|
+
__pycache__
|
|
26
|
+
*egg-info
|
|
27
|
+
*pyc
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
autoupdate_commit_msg: "chore: update pre-commit hooks"
|
|
3
|
+
autofix_commit_msg: "style: pre-commit fixes"
|
|
4
|
+
|
|
5
|
+
exclude: ^.cruft.json|.copier-answers.yml$|uv\.lock$
|
|
6
|
+
|
|
7
|
+
repos:
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: "v5.0.0"
|
|
10
|
+
hooks:
|
|
11
|
+
- id: check-added-large-files
|
|
12
|
+
- id: check-case-conflict
|
|
13
|
+
- id: check-merge-conflict
|
|
14
|
+
- id: check-symlinks
|
|
15
|
+
- id: check-yaml
|
|
16
|
+
- id: debug-statements
|
|
17
|
+
- id: end-of-file-fixer
|
|
18
|
+
- id: mixed-line-ending
|
|
19
|
+
- id: name-tests-test
|
|
20
|
+
args: ["--pytest-test-first"]
|
|
21
|
+
- id: requirements-txt-fixer
|
|
22
|
+
- id: trailing-whitespace
|
|
23
|
+
|
|
24
|
+
- repo: https://github.com/pre-commit/pygrep-hooks
|
|
25
|
+
rev: "v1.10.0"
|
|
26
|
+
hooks:
|
|
27
|
+
- id: rst-backticks
|
|
28
|
+
- id: rst-directive-colons
|
|
29
|
+
- id: rst-inline-touching-normal
|
|
30
|
+
|
|
31
|
+
- repo: https://github.com/rbubley/mirrors-prettier
|
|
32
|
+
rev: "v3.4.2"
|
|
33
|
+
hooks:
|
|
34
|
+
- id: prettier
|
|
35
|
+
types_or: [yaml, markdown, html, css, scss, javascript, json]
|
|
36
|
+
args: [--prose-wrap=always]
|
|
37
|
+
|
|
38
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
39
|
+
rev: "v0.15.10"
|
|
40
|
+
hooks:
|
|
41
|
+
- id: ruff
|
|
42
|
+
args: ["--fix", "--show-fixes"]
|
|
43
|
+
- id: ruff-format
|
|
44
|
+
|
|
45
|
+
- repo: https://github.com/codespell-project/codespell
|
|
46
|
+
rev: "v2.3.0"
|
|
47
|
+
hooks:
|
|
48
|
+
- id: codespell
|
|
49
|
+
|
|
50
|
+
- repo: https://github.com/shellcheck-py/shellcheck-py
|
|
51
|
+
rev: "v0.10.0.1"
|
|
52
|
+
hooks:
|
|
53
|
+
- id: shellcheck
|
|
54
|
+
|
|
55
|
+
- repo: https://github.com/abravalheri/validate-pyproject
|
|
56
|
+
rev: "v0.25"
|
|
57
|
+
hooks:
|
|
58
|
+
- id: validate-pyproject
|
|
59
|
+
additional_dependencies:
|
|
60
|
+
- validate-pyproject[all]
|
|
61
|
+
- validate-pyproject-schema-store
|
|
62
|
+
|
|
63
|
+
- repo: https://github.com/python-jsonschema/check-jsonschema
|
|
64
|
+
rev: "0.31.0"
|
|
65
|
+
hooks:
|
|
66
|
+
- id: check-dependabot
|
|
67
|
+
- id: check-github-workflows
|
|
68
|
+
- id: check-readthedocs
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!--next-version-placeholder-->
|
|
4
|
+
|
|
5
|
+
## v1.0.2 (2025-01-07)
|
|
6
|
+
|
|
7
|
+
### Fix
|
|
8
|
+
|
|
9
|
+
- Update vue2 example to use vue2 client type
|
|
10
|
+
([`34b443d`](https://github.com/Kitware/trame-code/commit/34b443d4b02328db155a4e152516d312dbfa7090))
|
|
11
|
+
- Initial value for vue2
|
|
12
|
+
([`b356e66`](https://github.com/Kitware/trame-code/commit/b356e66608b7b0655bffa4022c8f9815ceffcdbf))
|
|
13
|
+
- Bring back vue2 support
|
|
14
|
+
([`d9dc6f8`](https://github.com/Kitware/trame-code/commit/d9dc6f8fe0d393e596a0eeb4a0d20d32e5aa6681))
|
|
15
|
+
- Update to use modelValue for vue3
|
|
16
|
+
([`4274d8f`](https://github.com/Kitware/trame-code/commit/4274d8f8221c2bc2f3052900186444ca8dab6af0))
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
- Remove value from python wrapper
|
|
21
|
+
([`9172e3b`](https://github.com/Kitware/trame-code/commit/9172e3b87a3959dee4df5bcbbf912576a5bbd459))
|
|
22
|
+
- Update README.rst
|
|
23
|
+
([`adc54bb`](https://github.com/Kitware/trame-code/commit/adc54bb796288d91b8b9d89c8140b24e7b372e1f))
|
|
24
|
+
|
|
25
|
+
## v1.0.1 (2023-08-16)
|
|
26
|
+
|
|
27
|
+
### Fix
|
|
28
|
+
|
|
29
|
+
- **docs:** Improve API
|
|
30
|
+
([`e125a5b`](https://github.com/Kitware/trame-code/commit/e125a5b03ea7518329adadb082fc4f142fd6f28e))
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
|
|
34
|
+
- **layout:** Use automaticLayout option
|
|
35
|
+
([`c416d98`](https://github.com/Kitware/trame-code/commit/c416d98d2827e06d0a281733186016d6dbee98ca))
|
|
36
|
+
- **example:** Cleanup of textmate
|
|
37
|
+
([`d2e3eb3`](https://github.com/Kitware/trame-code/commit/d2e3eb322bef5574b2ae5ab0971d43c4a8335cd7))
|
|
38
|
+
|
|
39
|
+
## v1.0.0 (2023-04-19)
|
|
40
|
+
|
|
41
|
+
### Feature
|
|
42
|
+
|
|
43
|
+
- **release:** Official release
|
|
44
|
+
([`080923c`](https://github.com/Kitware/trame-code/commit/080923c5ad7343dac65e192902947ed08f761f57))
|
|
45
|
+
|
|
46
|
+
### Breaking
|
|
47
|
+
|
|
48
|
+
- Just making that library official now that it vue2/3 compatible
|
|
49
|
+
([`080923c`](https://github.com/Kitware/trame-code/commit/080923c5ad7343dac65e192902947ed08f761f57))
|
|
50
|
+
|
|
51
|
+
## v0.1.0 (2023-04-18)
|
|
52
|
+
|
|
53
|
+
### Feature
|
|
54
|
+
|
|
55
|
+
- **textmate:** Handle textmate format
|
|
56
|
+
([`83cfb97`](https://github.com/Kitware/trame-code/commit/83cfb97110296afa5fbfd31a2d66a4c8dc9810d1))
|
|
57
|
+
- **vue23:** Working for both vue client
|
|
58
|
+
([`13b5a92`](https://github.com/Kitware/trame-code/commit/13b5a92851a3f73f6020626547e63a7c4887cead))
|
|
59
|
+
- Initial VS code editor
|
|
60
|
+
([`831f907`](https://github.com/Kitware/trame-code/commit/831f90763d6a37088a648b2948f7f4b80b6c81aa))
|
|
61
|
+
|
|
62
|
+
### Fix
|
|
63
|
+
|
|
64
|
+
- **version:** Add **version**
|
|
65
|
+
([`efac4ab`](https://github.com/Kitware/trame-code/commit/efac4abe7c61c0ce562e88c54461d3a19b1e553d))
|
|
66
|
+
- **options:** Fix setting the language and theme
|
|
67
|
+
([`4ae0c42`](https://github.com/Kitware/trame-code/commit/4ae0c42055df982181453371ae76dd9e5677b451))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
==========================
|
|
2
|
+
Contributing to trame-code
|
|
3
|
+
==========================
|
|
4
|
+
|
|
5
|
+
#. Clone the repository using ``git clone``
|
|
6
|
+
#. Install pre-commit via ``pip install pre-commit``
|
|
7
|
+
#. Run ``pre-commit install`` to set up pre-commit hooks
|
|
8
|
+
#. Make changes to the code, and commit your changes to a separate branch
|
|
9
|
+
#. Create a fork of the repository on GitHub
|
|
10
|
+
#. Push your branch to your fork, and open a pull request
|
|
11
|
+
|
|
12
|
+
Tips
|
|
13
|
+
####
|
|
14
|
+
|
|
15
|
+
#. When first creating a new project, it is helpful to run ``pre-commit run --all-files`` to ensure all files pass the pre-commit checks.
|
|
16
|
+
#. A quick way to fix ``black`` issues is by installing black (``pip install black``) and running the ``black`` command at the root of your repository.
|
|
17
|
+
#. Sometimes, ``black`` and ``flake8`` do not agree. Add options to your ``.flake8`` file to fix these things. See the `flake8 configuration docs <https://flake8.pycqa.org/en/latest/user/configuration.html>`_ for more details.
|
|
18
|
+
#. A quick way to fix ``codespell`` issues is by installing codespell (``pip install codespell``) and running the ``codespell -w`` command at the root of your directory.
|
|
19
|
+
#. The `.codespellrc file <https://github.com/codespell-project/codespell#using-a-config-file>`_ can be used fix any other codespell issues, such as ignoring certain files, directories, words, or regular expressions.
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: trame-code
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Widget for Monaco VS code editor for trame
|
|
5
5
|
Author: Kitware Inc.
|
|
6
6
|
License: MIT License
|
|
7
|
-
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: Application,Framework,Interactive,Python,Web
|
|
8
9
|
Classifier: Development Status :: 5 - Production/Stable
|
|
9
10
|
Classifier: Environment :: Web Environment
|
|
10
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
12
|
Classifier: Natural Language :: English
|
|
12
13
|
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
14
|
Classifier: Programming Language :: JavaScript
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
16
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: trame-client
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=6; extra == 'dev'
|
|
17
23
|
Description-Content-Type: text/x-rst
|
|
18
|
-
License-File: LICENSE
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
.. |pypi_download| image:: https://img.shields.io/pypi/dm/trame-code
|
|
26
|
+
|
|
27
|
+
==============================
|
|
28
|
+
trame-code |pypi_download|
|
|
29
|
+
==============================
|
|
23
30
|
|
|
24
31
|
Widget for Monaco VS code editor for trame
|
|
25
32
|
|
|
@@ -47,3 +54,15 @@ Install the python library
|
|
|
47
54
|
.. code-block:: console
|
|
48
55
|
|
|
49
56
|
pip install -e .
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
JavaScript dependency
|
|
60
|
+
-----------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
This Python package bundle the following set of libraries:
|
|
63
|
+
|
|
64
|
+
* ``monaco-editor@0.37.1``
|
|
65
|
+
* ``vscode-oniguruma@1.7.0``
|
|
66
|
+
* ``vscode-textmate@9.0.0``
|
|
67
|
+
|
|
68
|
+
If you would like us to upgrade any of those dependencies, `please reach out <https://www.kitware.com/trame/>`_.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.. |pypi_download| image:: https://img.shields.io/pypi/dm/trame-code
|
|
2
|
+
|
|
3
|
+
==============================
|
|
4
|
+
trame-code |pypi_download|
|
|
5
|
+
==============================
|
|
6
|
+
|
|
7
|
+
Widget for Monaco VS code editor for trame
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
License
|
|
11
|
+
-----------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
This library is distributed under the MIT License (Same as monaco/vscode-editor)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Development
|
|
17
|
+
-----------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
Build and install the Vue components
|
|
20
|
+
|
|
21
|
+
.. code-block:: console
|
|
22
|
+
|
|
23
|
+
cd vue-components
|
|
24
|
+
npm i
|
|
25
|
+
npm run build
|
|
26
|
+
cd -
|
|
27
|
+
|
|
28
|
+
Install the python library
|
|
29
|
+
|
|
30
|
+
.. code-block:: console
|
|
31
|
+
|
|
32
|
+
pip install -e .
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
JavaScript dependency
|
|
36
|
+
-----------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
This Python package bundle the following set of libraries:
|
|
39
|
+
|
|
40
|
+
* ``monaco-editor@0.37.1``
|
|
41
|
+
* ``vscode-oniguruma@1.7.0``
|
|
42
|
+
* ``vscode-textmate@9.0.0``
|
|
43
|
+
|
|
44
|
+
If you would like us to upgrade any of those dependencies, `please reach out <https://www.kitware.com/trame/>`_.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Editor language features: completion + hover backed by a Python callback.
|
|
2
|
+
|
|
3
|
+
The ``completion`` and ``hover`` props on ``code.Editor`` each take a callable
|
|
4
|
+
that receives ``(code, line, column)`` and returns results. Here both are backed
|
|
5
|
+
by jedi, giving live Python completion and docstring-on-hover entirely
|
|
6
|
+
in-process, with no client-side JavaScript.
|
|
7
|
+
|
|
8
|
+
The contract:
|
|
9
|
+
|
|
10
|
+
* completion returns a list of items, each a dict with keys ``label`` (required),
|
|
11
|
+
``kind``, ``detail``, ``documentation``, ``insertText``.
|
|
12
|
+
* hover returns a markdown string, a list of markdown strings, or
|
|
13
|
+
``{"contents": [...]}`` (or ``None`` for no hover).
|
|
14
|
+
* positions are passed as ``line`` (1-based) and ``column`` (0-based), matching
|
|
15
|
+
jedi's API directly.
|
|
16
|
+
|
|
17
|
+
Run with::
|
|
18
|
+
|
|
19
|
+
pip install trame trame-vuetify trame-code jedi
|
|
20
|
+
python app.py
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import jedi
|
|
24
|
+
from trame.app import TrameApp
|
|
25
|
+
from trame.ui.vuetify3 import SinglePageLayout
|
|
26
|
+
|
|
27
|
+
from trame.widgets import code
|
|
28
|
+
from trame.widgets import vuetify3 as v3
|
|
29
|
+
|
|
30
|
+
INITIAL_CODE = '''import math
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def circle_area(radius):
|
|
34
|
+
"""Return the area of a circle with the given radius."""
|
|
35
|
+
return math.pi * radius**2
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Type "math." below, or hover a name, to see completion and docstrings.
|
|
39
|
+
math.
|
|
40
|
+
'''
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class PyCodeEditor(TrameApp):
|
|
44
|
+
def __init__(self, server=None):
|
|
45
|
+
super().__init__(server)
|
|
46
|
+
self._build_ui()
|
|
47
|
+
|
|
48
|
+
def _build_ui(self):
|
|
49
|
+
self.state.trame__title = "PyEditor"
|
|
50
|
+
with SinglePageLayout(self.server) as self.ui:
|
|
51
|
+
self.ui.title.set_text("Editor language features (jedi)")
|
|
52
|
+
with self.ui.content:
|
|
53
|
+
with v3.VContainer(fluid=True, classes="fill-height pa-0"):
|
|
54
|
+
code.Editor(
|
|
55
|
+
v_model=("editor_code", INITIAL_CODE),
|
|
56
|
+
language="python",
|
|
57
|
+
theme="vs",
|
|
58
|
+
style="width: 100%; height: 100%;",
|
|
59
|
+
completion=self.on_completion,
|
|
60
|
+
hover=self.on_hover,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def on_completion(self, code_text, line, column):
|
|
64
|
+
"""Completion items for (code, line, column): line 1-based, column 0-based."""
|
|
65
|
+
try:
|
|
66
|
+
completions = jedi.Script(code=code_text).complete(line, column)
|
|
67
|
+
except Exception:
|
|
68
|
+
return []
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
"label": c.name,
|
|
72
|
+
"kind": c.type,
|
|
73
|
+
"detail": (c.description or "")[:80],
|
|
74
|
+
}
|
|
75
|
+
for c in completions[:200]
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
def on_hover(self, code_text, line, column):
|
|
79
|
+
"""Hover markdown (signature + docstring) for the symbol at the cursor."""
|
|
80
|
+
try:
|
|
81
|
+
definitions = jedi.Script(code=code_text).help(line, column)
|
|
82
|
+
except Exception:
|
|
83
|
+
return None
|
|
84
|
+
if not definitions:
|
|
85
|
+
return None
|
|
86
|
+
definition = definitions[0]
|
|
87
|
+
contents = []
|
|
88
|
+
signatures = [s.to_string() for s in definition.get_signatures()]
|
|
89
|
+
if signatures:
|
|
90
|
+
contents.append("```python\n" + "\n".join(signatures) + "\n```")
|
|
91
|
+
doc = definition.docstring(raw=True) or ""
|
|
92
|
+
if doc:
|
|
93
|
+
contents.append(doc)
|
|
94
|
+
return {"contents": contents} if contents else None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
app = PyCodeEditor()
|
|
99
|
+
app.server.start()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Editor language features: completion from live in-process state.
|
|
2
|
+
|
|
3
|
+
This example shows the capability that distinguishes a callback-backed provider
|
|
4
|
+
from a language server: the suggestions come from a live Python object in the
|
|
5
|
+
running process, not from source text or type stubs. A language server cannot
|
|
6
|
+
offer these names, because they exist only at runtime.
|
|
7
|
+
|
|
8
|
+
Here the editor completes the keys of an in-memory ``DATASET`` when the cursor
|
|
9
|
+
is inside a ``dataset["..."]`` subscript, annotating each with the live value's
|
|
10
|
+
type and length. Swap ``DATASET`` for a loaded data file, a database schema, or
|
|
11
|
+
any live object and the same handler surfaces those names into the editor.
|
|
12
|
+
|
|
13
|
+
The contract (shared with the language-features example):
|
|
14
|
+
|
|
15
|
+
* completion returns a list of items, each a dict with key ``label`` (required)
|
|
16
|
+
and optional ``kind``, ``detail``, ``documentation``, ``insertText``.
|
|
17
|
+
* positions are passed as ``line`` (1-based) and ``column`` (0-based).
|
|
18
|
+
|
|
19
|
+
Run with::
|
|
20
|
+
|
|
21
|
+
pip install trame trame-vuetify trame-code
|
|
22
|
+
python app.py
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import re
|
|
26
|
+
|
|
27
|
+
from trame.app import TrameApp
|
|
28
|
+
from trame.ui.vuetify3 import SinglePageLayout
|
|
29
|
+
|
|
30
|
+
from trame.widgets import code
|
|
31
|
+
from trame.widgets import vuetify3 as vuetify
|
|
32
|
+
|
|
33
|
+
# Stand-in for state that exists only at runtime (a loaded dataset, a live
|
|
34
|
+
# object graph, a fetched schema...). None of these names appear in the source.
|
|
35
|
+
DATASET = {
|
|
36
|
+
"pressure": [0.0] * 1000,
|
|
37
|
+
"density": [0.0] * 1000,
|
|
38
|
+
"temperature": [0.0] * 1000,
|
|
39
|
+
"velocity": [(0.0, 0.0, 0.0)] * 1000,
|
|
40
|
+
"time_steps": list(range(50)),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Match an unclosed string subscript at the cursor: dataset["pre
|
|
44
|
+
_SUBSCRIPT_RE = re.compile(r"""\[\s*["']([^"']*)$""")
|
|
45
|
+
|
|
46
|
+
INITIAL_CODE = """# Live-state completion demo
|
|
47
|
+
#
|
|
48
|
+
# 1. Put the cursor between the empty quotes on the last line: dataset[""]
|
|
49
|
+
# 2. Type a letter (p, d, t, or v). Suggestions appear automatically.
|
|
50
|
+
# 3. The keys are read live from the in-memory DATASET object
|
|
51
|
+
# (pressure, density, temperature, velocity, time_steps),
|
|
52
|
+
# each shown with its Python type and length.
|
|
53
|
+
#
|
|
54
|
+
# A language server cannot offer these: they exist only at runtime.
|
|
55
|
+
|
|
56
|
+
field = dataset[""]
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _describe(value):
|
|
61
|
+
"""A short, live description of a value: type plus length when available."""
|
|
62
|
+
type_name = type(value).__name__
|
|
63
|
+
try:
|
|
64
|
+
return f"{type_name}, len {len(value)}"
|
|
65
|
+
except TypeError:
|
|
66
|
+
return type_name
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class LiveStateEditor(TrameApp):
|
|
70
|
+
def __init__(self, server=None):
|
|
71
|
+
super().__init__(server)
|
|
72
|
+
self._build_ui()
|
|
73
|
+
|
|
74
|
+
def _build_ui(self):
|
|
75
|
+
self.state.trame__title = "Live-state completion"
|
|
76
|
+
with SinglePageLayout(self.server) as self.ui:
|
|
77
|
+
self.ui.title.set_text("Live-state completion")
|
|
78
|
+
with self.ui.content:
|
|
79
|
+
with vuetify.VContainer(fluid=True, classes="fill-height pa-0"):
|
|
80
|
+
code.Editor(
|
|
81
|
+
v_model=("live_code", INITIAL_CODE),
|
|
82
|
+
language="python",
|
|
83
|
+
theme="vs",
|
|
84
|
+
completion=self.live_complete,
|
|
85
|
+
# open the list as soon as the key string is entered
|
|
86
|
+
completion_trigger_characters=(
|
|
87
|
+
"completion_triggers",
|
|
88
|
+
['"', "'", "["],
|
|
89
|
+
),
|
|
90
|
+
# dict-key completion happens inside a string literal,
|
|
91
|
+
# where Monaco suppresses suggestions by default; enable
|
|
92
|
+
# them there, and drop document-word noise.
|
|
93
|
+
options=(
|
|
94
|
+
"live_editor_options",
|
|
95
|
+
{
|
|
96
|
+
"quickSuggestions": {
|
|
97
|
+
"other": True,
|
|
98
|
+
"comments": False,
|
|
99
|
+
"strings": True,
|
|
100
|
+
},
|
|
101
|
+
"wordBasedSuggestions": False,
|
|
102
|
+
"minimap": {"enabled": False},
|
|
103
|
+
},
|
|
104
|
+
),
|
|
105
|
+
style="width: 100%; height: 100%;",
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def live_complete(self, code_text, line, column):
|
|
109
|
+
"""Complete DATASET keys when the cursor is inside a string subscript."""
|
|
110
|
+
lines = code_text.split("\n")
|
|
111
|
+
if line < 1 or line > len(lines):
|
|
112
|
+
return []
|
|
113
|
+
prefix = lines[line - 1][:column]
|
|
114
|
+
|
|
115
|
+
match = _SUBSCRIPT_RE.search(prefix)
|
|
116
|
+
if not match:
|
|
117
|
+
return [] # not inside a key subscript -> defer to others
|
|
118
|
+
|
|
119
|
+
stub = match.group(1)
|
|
120
|
+
return [
|
|
121
|
+
{"label": key, "kind": "field", "detail": _describe(value)}
|
|
122
|
+
for key, value in DATASET.items()
|
|
123
|
+
if key.startswith(stub)
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if __name__ == "__main__":
|
|
128
|
+
app = LiveStateEditor()
|
|
129
|
+
app.server.start()
|