-
Couldn't load subscription status.
- Fork 15
Allow for frontend driven indexing #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aebf263
frontend indexing
jtpio 43e5b41
add deploy workflow
jtpio 05dae92
demo folder
jtpio 396e0cb
fix typo
jtpio 02a2ca9
fixes
jtpio 4a35eda
fix frontend indexing
jtpio 212c20a
cleanup
jtpio a179f58
improve the loading of settings
jtpio 9d024aa
add TODO
jtpio de8f0dd
add jupyterlite section to the README
jtpio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Build and Deploy | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - '*' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install the dependencies | ||
| run: | | ||
| python -m pip install -r requirements.txt | ||
| working-directory: ./demo | ||
| - name: Clone jupyterlab-demo for example content | ||
| run: | | ||
| git clone --depth 1 https://github.com/jupyterlab/jupyterlab-demo | ||
|
|
||
| # remove hidden directories | ||
| rm -rf jupyterlab-demo/.* | ||
| working-directory: ./demo | ||
| - name: Build the JupyterLite site | ||
| run: | | ||
| jupyter lite build --contents jupyterlab-demo --output-dir dist | ||
| working-directory: ./demo | ||
| - name: Upload artifact | ||
| uses: actions/upload-pages-artifact@v4 | ||
| with: | ||
| path: ./demo/dist | ||
|
|
||
| deploy: | ||
| needs: build | ||
| if: github.ref == 'refs/heads/main' | ||
| permissions: | ||
| pages: write | ||
| id-token: write | ||
|
|
||
| environment: | ||
| name: github-pages | ||
| url: ${{ steps.deployment.outputs.page_url }} | ||
|
|
||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Deploy to GitHub Pages | ||
| id: deployment | ||
| uses: actions/deploy-pages@v4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,4 +121,4 @@ dmypy.json | |
| .yarn/ | ||
|
|
||
| # JupyterLab upgrade script | ||
| _temp_extension | ||
| _temp_extension | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ node_modules | |
| **/package.json | ||
| !/package.json | ||
| jupyterlab_quickopen | ||
| .venv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Demo | ||
|
|
||
| This directory contains configuration files for running a JupyterLite demo with the quickopen extension. | ||
|
|
||
| ## Files | ||
|
|
||
| - `requirements.txt` - JupyterLite dependencies | ||
| - `overrides.json` - Extension configuration to use frontend indexing method | ||
|
|
||
| ## Usage | ||
|
|
||
| Build and serve a JupyterLite instance with the quickopen extension configured for frontend-based file indexing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "jupyterlab-quickopen:plugin": { | ||
| "indexingMethod": "frontend" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| jupyterlite-core | ||
| jupyterlite-pyodide-kernel | ||
| .. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { PathExt } from '@jupyterlab/coreutils'; | ||
| import { Contents } from '@jupyterlab/services'; | ||
| import { | ||
| IQuickOpenOptions, | ||
| IQuickOpenProvider, | ||
| IQuickOpenResponse | ||
| } from './tokens'; | ||
|
|
||
| /** | ||
| * Frontend implementation of the quick open provider that uses the Contents API. | ||
| */ | ||
| export class FrontendQuickOpenProvider implements IQuickOpenProvider { | ||
| /** | ||
| * Create a new frontend quick open provider. | ||
| * @param options Options for creating the provider | ||
| */ | ||
| constructor(options: FrontendQuickOpenProvider.IOptions) { | ||
| this._contentsManager = options.contentsManager; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch contents from the filesystem using the Contents API. | ||
| * @param options Options for the fetch operation | ||
| * @returns Promise resolving to contents and scan time | ||
| */ | ||
| async fetchContents(options: IQuickOpenOptions): Promise<IQuickOpenResponse> { | ||
| const { path, excludes, depth } = options; | ||
| const startTime = performance.now(); | ||
| const contents: { [key: string]: string[] } = {}; | ||
|
|
||
| try { | ||
| const maxDepth = depth ?? Infinity; | ||
| await this._walkDirectory(path, excludes, contents, maxDepth); | ||
| } catch (error) { | ||
| console.warn('Error walking directory:', error); | ||
| } | ||
|
|
||
| const scanSeconds = (performance.now() - startTime) / 1000; | ||
| return { contents, scanSeconds }; | ||
| } | ||
|
|
||
| /** | ||
| * Recursively walk a directory and collect file listings. | ||
| * @param dirPath The directory path to walk | ||
| * @param excludes Array of patterns to exclude | ||
| * @param contents Object to accumulate results in | ||
| * @param maxDepth Maximum recursion depth | ||
| * @param currentDepth Current recursion depth | ||
| */ | ||
| private async _walkDirectory( | ||
| dirPath: string, | ||
| excludes: string[], | ||
| contents: { [key: string]: string[] }, | ||
| maxDepth: number = Infinity, | ||
| currentDepth: number = 0 | ||
| ): Promise<void> { | ||
| if (currentDepth >= maxDepth) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const listing = await this._contentsManager.get(dirPath, { | ||
| content: true, | ||
| type: 'directory' | ||
| }); | ||
|
|
||
| if (!listing.content) { | ||
| return; | ||
| } | ||
|
|
||
| for (const item of listing.content) { | ||
| const itemPath = dirPath ? PathExt.join(dirPath, item.name) : item.name; | ||
|
|
||
| // Check if item should be excluded | ||
| if (this._shouldExclude(item.name, itemPath, excludes)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (item.type === 'directory') { | ||
| // Recursively walk subdirectories | ||
| await this._walkDirectory( | ||
| itemPath, | ||
| excludes, | ||
| contents, | ||
| maxDepth, | ||
| currentDepth + 1 | ||
| ); | ||
| } else { | ||
| // Add file to contents under its directory category | ||
| const category = dirPath || '.'; | ||
| if (!contents[category]) { | ||
| contents[category] = []; | ||
| } | ||
| contents[category].push(item.name); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| // Silently skip directories we can't access | ||
| console.debug(`Skipping directory ${dirPath}:`, error); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check if a file should be excluded from results. | ||
| * @param filename The filename to check | ||
| * @param fullPath The full path to check | ||
| * @param excludes Array of exclusion patterns | ||
| * @returns True if the file should be excluded | ||
| */ | ||
| private _shouldExclude( | ||
| filename: string, | ||
| fullPath: string, | ||
| excludes: string[] | ||
| ): boolean { | ||
| for (const exclude of excludes) { | ||
| // TODO: support globs instead of simple string matching | ||
| if ( | ||
| filename.includes(exclude) || | ||
| fullPath.includes(exclude) || | ||
| (filename.startsWith('.') && exclude === '.*') | ||
| ) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private _contentsManager: Contents.IManager; | ||
| } | ||
|
|
||
| /** | ||
| * A namespace for the frontend quick open provider statics. | ||
| */ | ||
| export namespace FrontendQuickOpenProvider { | ||
| /** | ||
| * Options for creating a frontend quick open provider. | ||
| */ | ||
| export interface IOptions { | ||
| /** | ||
| * The contents manager to use for file operations | ||
| */ | ||
| contentsManager: Contents.IManager; | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is for JupyterLite support?
Long-term, we may want to extend the contentsManager implementation so that we don't need to make the recursive
gets here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed, this one is only for the frontend provider, so the provider making the calls to the contents API one by one.
You mean extending it directly in Jupyterlite? If so yes, that could be an option. Also the quickopen provider is defined in its own plugin, so it could be replaced by another plugin provided by JupyterLite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I mean that if the more advanced handler for recursive
getgets into jupyterlab-server, then thecontentsManagerAPI will be updated to expose this new recursiveget. Then JupyterLite will have to implement it and we can get rid of the recursion here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I guess this
FrontendQuickOpenProvideris mostly to enable the use of the extension in JupyterLite, and have everything available in the samejupyterlab-quickopenextension.If we decide to propose this extension for incorporation into core JupyterLab, we can expose the provider token and drop that custom
FrontendQuickOpenProvider, since JupyterLite will be able to provide its own.