Skip to content

Commit 232ab46

Browse files
ianhiryantam626
authored andcommitted
update for jlab3
1 parent 3bd3bff commit 232ab46

26 files changed

+289
-1680
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ lib/
33
node_modules/
44
*.egg-info/
55
.ipynb_checkpoints
6+
jupyterlab_code_formatter/labextension
67

78
# Byte-compiled / optimized / DLL files
89
__pycache__/
@@ -21,3 +22,24 @@ venv/
2122
build/
2223

2324
**/dist/
25+
26+
27+
# Distribution / packaging
28+
.Python
29+
build/
30+
develop-eggs/
31+
dist/
32+
downloads/
33+
eggs/
34+
.eggs/
35+
lib/
36+
lib64/
37+
parts/
38+
sdist/
39+
var/
40+
wheels/
41+
pip-wheel-metadata/
42+
share/python-wheels/
43+
.installed.cfg
44+
*.egg
45+
MANIFEST

MANIFEST.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
include LICENSE
2+
include README.md
3+
include pyproject.toml
4+
include jupyter-config/jupyterlab_code_formatter.json
5+
6+
include package.json
7+
include install.json
8+
include ts*.json
9+
10+
graft jupyterlab_code_formatter/labextension
11+
12+
# Javascript files
13+
graft src
14+
graft style
15+
prune **/node_modules
16+
prune lib
17+
18+
# Patterns to exclude from any directory
19+
global-exclude *~
20+
global-exclude *.pyc
21+
global-exclude *.pyo
22+
global-exclude .git
23+
global-exclude .ipynb_checkpoints

Makefile

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,20 @@ conda-freeze: ## Use conda to freeze the current env available
1919
conda-install-frozen: ## Use conda to install dev dependencies using pinned env specification - subject to repodata.json changes
2020
conda env create -f environment-frozen.yml --force --name jupyterlab-code-formatter
2121

22-
dev-install-serverextension: ## Use pip to install the server extension in dev mode
23-
pip install -e serverextension
24-
jupyter serverextension enable --py jupyterlab_code_formatter
25-
26-
dev-install-labextension: ## Use npm to install the lab extension in dev mode
27-
cd $(LABEXTENSION_PATH)
28-
npm install
29-
npm run build
30-
jupyter labextension link .
31-
cd -
32-
33-
dev-install: dev-install-serverextension dev-install-labextension ## Install both lab and server extension in dev mode
22+
dev-install:
23+
pip install -e .
24+
jupyter labextension develop . --overwrite
25+
jlpm run build
3426

3527
dev-watch-labextension: ## Recompile labextension on changes
36-
cd $(LABEXTENSION_PATH)
3728
npm run watch
3829

39-
dev-watch-jupyterlab: ## Start jupyterlab under watch mode
40-
jupyter lab --watch
41-
4230
lint: # Run linters
43-
find serverextension/jupyterlab_code_formatter -name '*.py' | xargs black --check
44-
cd $(LABEXTENSION_PATH)
31+
find jupyterlab_code_formatter -name '*.py' | xargs black --check
4532
npm run lint
4633

4734
format: # Run formatters
48-
find serverextension/jupyterlab_code_formatter -name '*.py' | xargs black
49-
cd $(LABEXTENSION_PATH)
35+
find jupyterlab_code_formatter -name '*.py' | xargs black
5036
npm run format
5137

5238
test: # Run test

install.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "jupyterlab-code-formatter",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab-code-formatter"
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ServerApp": {
3+
"jpserver_extensions": {
4+
"jupyterlab-code-formatter": true
5+
}
6+
}
7+
}

jupyterlab_code_formatter/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import json
2+
import os.path as osp
3+
4+
from .handlers import setup_handlers
5+
from ._version import __version__
6+
7+
HERE = osp.abspath(osp.dirname(__file__))
8+
9+
with open(osp.join(HERE, "labextension", "package.json")) as fid:
10+
data = json.load(fid)
11+
12+
13+
def _jupyter_labextension_paths():
14+
return [{"src": "labextension", "dest": data["name"]}]
15+
16+
17+
def _jupyter_server_extension_paths():
18+
return [{"module": "jupyterlab_code_formatter"}]
19+
20+
21+
def _load_jupyter_server_extension(server_app):
22+
"""Registers the API handler to receive HTTP requests from the frontend extension.
23+
24+
Parameters
25+
----------
26+
lab_app: jupyterlab.labapp.LabApp
27+
JupyterLab application instance
28+
"""
29+
setup_handlers(server_app.web_app)

jupyterlab_code_formatter/_version.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
__all__ = ["__version__"]
2+
3+
4+
def _fetchVersion():
5+
import json
6+
import os
7+
8+
HERE = os.path.abspath(os.path.dirname(__file__))
9+
10+
for d, _, _ in os.walk(HERE):
11+
try:
12+
with open(os.path.join(d, "package.json")) as f:
13+
return json.load(f)["version"]
14+
except FileNotFoundError:
15+
pass
16+
17+
raise FileNotFoundError("Could not find package.json under dir {}".format(HERE))
18+
19+
20+
__version__ = _fetchVersion()

serverextension/jupyterlab_code_formatter/handlers.py renamed to jupyterlab_code_formatter/handlers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import json
2+
3+
from jupyter_server.base.handlers import APIHandler
4+
from jupyter_server.utils import url_path_join
5+
26
import pkg_resources
37

48
from notebook.notebookapp import NotebookWebApplication
5-
from notebook.utils import url_path_join
6-
from notebook.base.handlers import APIHandler
79

8-
from jupyterlab_code_formatter.formatters import SERVER_FORMATTERS
10+
from .formatters import SERVER_FORMATTERS
911

1012

1113
def setup_handlers(web_app: NotebookWebApplication) -> None:

serverextension/jupyterlab_code_formatter/tests/test_handlers.py renamed to jupyterlab_code_formatter/tests/test_handlers.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def _generate_list_formaters_entry_json_schema(
2929

3030
EXPECTED_VERSION_SCHEMA = {
3131
"type": "object",
32-
"properties": {"version": {"type": "string",}},
32+
"properties": {
33+
"version": {
34+
"type": "string",
35+
}
36+
},
3337
}
3438

3539
EXPECTED_LIST_FORMATTERS_SCHEMA = {
@@ -157,7 +161,9 @@ def test_can_handle_magic(self):
157161
expected = '%%timeit\nsome_string = "abc"'
158162
for formatter in ["black", "yapf", "isort"]:
159163
response = self._format_code_request(
160-
formatter=formatter, code=[given], options={},
164+
formatter=formatter,
165+
code=[given],
166+
options={},
161167
)
162168
json_result = self._check_http_200_and_schema(response)
163169
assert json_result["code"][0]["code"] == expected
@@ -168,7 +174,9 @@ def test_can_handle_shell_cmd(self):
168174
expected = '%%timeit\nsome_string = "abc"\n!pwd'
169175
for formatter in ["black", "yapf", "isort"]:
170176
response = self._format_code_request(
171-
formatter=formatter, code=[given], options={},
177+
formatter=formatter,
178+
code=[given],
179+
options={},
172180
)
173181
json_result = self._check_http_200_and_schema(response)
174182
assert json_result["code"][0]["code"] == expected
@@ -177,7 +185,9 @@ def test_can_use_styler(self):
177185
given = "a = 3; 2"
178186
expected = "a <- 3\n2"
179187
response = self._format_code_request(
180-
formatter="styler", code=[given], options={"scope": "tokens"},
188+
formatter="styler",
189+
code=[given],
190+
options={"scope": "tokens"},
181191
)
182192
json_result = self._check_http_200_and_schema(response)
183193
assert json_result["code"][0]["code"] == expected
@@ -194,7 +204,9 @@ def test_can_use_styler_2(self):
194204
large = 6
195205
)"""
196206
response = self._format_code_request(
197-
code=[given], options={"strict": False}, formatter="styler",
207+
code=[given],
208+
options={"strict": False},
209+
formatter="styler",
198210
)
199211
json_result = self._check_http_200_and_schema(response)
200212
assert json_result["code"][0]["code"] == expected
@@ -278,7 +290,10 @@ def test_422_on_mismatch_version_1(self):
278290
assert response.status_code == 422
279291

280292
def test_200_on_version_without_header(self):
281-
response = self.request(verb="GET", path="/jupyterlab_code_formatter/version",)
293+
response = self.request(
294+
verb="GET",
295+
path="/jupyterlab_code_formatter/version",
296+
)
282297
assert response.status_code == 200
283298
validate(instance=response.json(), schema=EXPECTED_VERSION_SCHEMA)
284299

0 commit comments

Comments
 (0)