File tree Expand file tree Collapse file tree 5 files changed +105
-1
lines changed
packages/jupyterlab-lsp/src/transclusions Expand file tree Collapse file tree 5 files changed +105
-1
lines changed Original file line number Diff line number Diff line change 1
1
## CHANGELOG
2
2
3
- ### ` @krassowski/jupyterlab-lsp 3.4.2 ` (unreleased)
3
+ ### ` @krassowski/jupyterlab-lsp 3.5.0 ` (unreleased)
4
+
5
+ - features:
6
+
7
+ - adds ` %%bigquery ` IPython cell magic support for BigQuery ([ #553 ] , thanks @julioyildo )
4
8
5
9
- bug fixes:
6
10
9
13
10
14
[ #544 ] : https://github.com/krassowski/jupyterlab-lsp/pull/544
11
15
[ #547 ] : https://github.com/krassowski/jupyterlab-lsp/pull/547
16
+ [ #553 ] : https://github.com/krassowski/jupyterlab-lsp/pull/553
12
17
13
18
### ` jupyter-lsp 1.1.4 ` (2020-02-21)
14
19
Original file line number Diff line number Diff line change 1
1
import { JupyterFrontEndPlugin } from '@jupyterlab/application' ;
2
2
import { IPYTHON_RPY2_TRANSCLUSIONS } from './ipython-rpy2' ;
3
3
import { IPYTHON_SQL_TRANSCLUSIONS } from './ipython-sql' ;
4
+ import { IPYTHON_BIGQUERY_TRANSCLUSIONS } from './ipython-bigquery' ;
4
5
import { IPYTHON_TRANSCLUSIONS } from './ipython' ;
5
6
6
7
export const DEFAULT_TRANSCLUSIONS : JupyterFrontEndPlugin < void > [ ] = [
7
8
IPYTHON_RPY2_TRANSCLUSIONS ,
8
9
IPYTHON_SQL_TRANSCLUSIONS ,
10
+ IPYTHON_BIGQUERY_TRANSCLUSIONS ,
9
11
IPYTHON_TRANSCLUSIONS
10
12
] ;
Original file line number Diff line number Diff line change
1
+ import { VirtualDocument } from '../../virtual/document' ;
2
+ import { expect } from 'chai' ;
3
+ import { foreign_code_extractors } from './extractors' ;
4
+ import { extract_code , get_the_only_virtual } from '../../extractors/testutils' ;
5
+
6
+ describe ( 'Bigquery SQL extractors' , ( ) => {
7
+ let document : VirtualDocument ;
8
+
9
+ function extract ( code : string ) {
10
+ return extract_code ( document , code ) ;
11
+ }
12
+
13
+ beforeEach ( ( ) => {
14
+ document = new VirtualDocument ( {
15
+ language : 'python' ,
16
+ path : 'test.ipynb' ,
17
+ overrides_registry : { } ,
18
+ foreign_code_extractors : foreign_code_extractors ,
19
+ standalone : false ,
20
+ file_extension : 'py' ,
21
+ has_lsp_supported_file : false
22
+ } ) ;
23
+ } ) ;
24
+
25
+ afterEach ( ( ) => {
26
+ document . clear ( ) ;
27
+ } ) ;
28
+
29
+ describe ( '%%bigquery cell magic' , ( ) => {
30
+ it ( 'extracts simple commands' , ( ) => {
31
+ let code = "%%bigquery\nselect * from character\nwhere abbrev = 'ALICE'" ;
32
+ let { cell_code_kept, foreign_document_map } = extract ( code ) ;
33
+
34
+ expect ( cell_code_kept ) . to . equal ( code ) ;
35
+ let document = get_the_only_virtual ( foreign_document_map ) ;
36
+ expect ( document . language ) . to . equal ( 'sql' ) ;
37
+ expect ( document . value ) . to . equal (
38
+ "select * from character\nwhere abbrev = 'ALICE'\n"
39
+ ) ;
40
+ } ) ;
41
+ } ) ;
42
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { IForeignCodeExtractorsRegistry } from '../../extractors/types' ;
2
+ import { RegExpForeignCodeExtractor } from '../../extractors/regexp' ;
3
+
4
+ export const SQL_URL_PATTERN = '(?:(?:.*?)://(?:.*))' ;
5
+ // note: -a/--connection_arguments and -f/--file are not supported yet
6
+ const single_argument_options = [
7
+ '--destination_table' ,
8
+ '--project' ,
9
+ '--use_bqstorage_api' ,
10
+ '--use_rest_api' ,
11
+ '--use_legacy_sql' ,
12
+ '--verbose' ,
13
+ '--params'
14
+ ] ;
15
+ const zero_argument_options = [ '-l' , '--connections' ] ;
16
+
17
+ const COMMAND_PATTERN =
18
+ '(?:' +
19
+ ( zero_argument_options . join ( '|' ) +
20
+ '|' +
21
+ single_argument_options . map ( command => command + ' \\w+' ) . join ( '|' ) ) +
22
+ ')' ;
23
+
24
+ export let foreign_code_extractors : IForeignCodeExtractorsRegistry = {
25
+ // general note: to match new lines use [^] instead of dot, unless the target is ES2018, then use /s
26
+ python : [
27
+ new RegExpForeignCodeExtractor ( {
28
+ language : 'sql' ,
29
+ pattern : `^%%bigquery(?: (?:${ SQL_URL_PATTERN } |${ COMMAND_PATTERN } |(?:\\w+ << )|(?:\\w+@\\w+)))?\n?(.+\n)?([^]*)` ,
30
+ extract_to_foreign : '$1$2' ,
31
+ is_standalone : true ,
32
+ file_extension : 'sql'
33
+ } )
34
+ ]
35
+ } ;
Original file line number Diff line number Diff line change
1
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application' ;
2
+ import { ILSPCodeExtractorsManager , PLUGIN_ID } from '../../tokens' ;
3
+ import { foreign_code_extractors } from './extractors' ;
4
+
5
+ /**
6
+ * Implements extraction of code for IPython Magics for BigQuery, see:
7
+ * https://googleapis.dev/python/bigquery/latest/magics.html.
8
+ */
9
+ export const IPYTHON_BIGQUERY_TRANSCLUSIONS : JupyterFrontEndPlugin < void > = {
10
+ id : PLUGIN_ID + ':ipython-bigquery' ,
11
+ requires : [ ILSPCodeExtractorsManager ] ,
12
+ activate : ( app , extractors_manager : ILSPCodeExtractorsManager ) => {
13
+ for ( let language of Object . keys ( foreign_code_extractors ) ) {
14
+ for ( let extractor of foreign_code_extractors [ language ] ) {
15
+ extractors_manager . register ( extractor , language ) ;
16
+ }
17
+ }
18
+ } ,
19
+ autoStart : true
20
+ } ;
You can’t perform that action at this time.
0 commit comments