Skip to content

Commit

Permalink
Use format SQL settings when creating new notebook (#115)
Browse files Browse the repository at this point in the history
* create new settings

* workflow

remove snowflake tests

rm redshift snowflake

added load_extension

remove tests

serverapp

revert

jl version

removed newlines

insert btn

revert

revert

revert

test

original code

revert test

timeout

* force

newlines

newlines

newlines
  • Loading branch information
neelasha23 authored Jun 14, 2024
1 parent 68325a8 commit 3a602cf
Show file tree
Hide file tree
Showing 6 changed files with 2,813 additions and 3,739 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:

- name: Lint
run: |
python3 -m venv env
source env/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pkgmt nox
pkgmt lint
pkgmt lint --exclude env
- name: Setup node
uses: actions/setup-node@v3
Expand All @@ -48,6 +50,7 @@ jobs:

- name: Test
run: |
source env/bin/activate
nox --session test --verbose
ui-test:
Expand Down Expand Up @@ -81,6 +84,8 @@ jobs:

- name: Install and test
run: |
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade nox
SHARD=${{ matrix.shard }}
Expand Down
18 changes: 18 additions & 0 deletions jupysql_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@

def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": "jupysql-plugin"}]


def _jupyter_server_extension_points():
return [{"module": "jupysql_plugin"}]


def _load_jupyter_server_extension(serverapp):
"""
This function is called when the extension is loaded.
Parameters
----------
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
serverapp.log.info(f"Registered {_module_name} server extension")


load_jupyter_server_extension = _load_jupyter_server_extension
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jupyterlab>=4,<4.0.12
jupyterlab>=4
build
twine
hatch
Expand Down
10 changes: 9 additions & 1 deletion src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class FormattingExtension
private notebookCodeFormatter: JupyterlabNotebookCodeFormatter;
private formatSQLButton: ToolbarButton;
private panel: NotebookPanel;
private extensionSettings: boolean;


constructor(
tracker: INotebookTracker
Expand All @@ -39,6 +41,7 @@ export class FormattingExtension
}

private _onSettingsChanged = (sender: any, settings: JupySQLSettings) => {
this.extensionSettings = settings.showFormatSQL;
if (!settings.showFormatSQL) {
this.formatSQLButton.parent = null;
} else {
Expand All @@ -65,6 +68,11 @@ export class FormattingExtension
this.formatSQLButton.node.setAttribute("data-testid", "format-btn");

panel.toolbar.insertItem(10, 'formatSQL', this.formatSQLButton);
if (!this.extensionSettings) {
this.formatSQLButton.parent = null;
} else {
this.panel.toolbar.insertItem(10, 'formatSQL', this.formatSQLButton);
}

return new DisposableDelegate(() => {
this.formatSQLButton.dispose();
Expand Down Expand Up @@ -97,4 +105,4 @@ const plugin_formatting: JupyterFrontEndPlugin<void> = {
};


export { plugin_formatting }
export { plugin_formatting }
2 changes: 1 addition & 1 deletion ui-tests/tests/format_sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('test format SQL', async ({ page }) => {
await page.notebook.openByPath("sample.ipynb");
await page.notebook.activate("sample.ipynb");
await page.notebook.addCell("code", "%%sql\nselect * from table")
await page.getByTestId('format-btn').locator('button').click();
await page.getByTestId('format-btn').locator('button').click({ force: true });
await page.waitForTimeout(2000);

await expect(page.locator('body')).toContainText('SELECT');
Expand Down
Loading

0 comments on commit 3a602cf

Please sign in to comment.