-
Notifications
You must be signed in to change notification settings - Fork 36
feat: create new environment using a remote mamba solver #141
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
Open
mariobuikhuizen
wants to merge
15
commits into
mamba-org:main
Choose a base branch
from
mariobuikhuizen:mamba_hint_solve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2da6178
feat: create new environment using a remote mamba solver
mariobuikhuizen e9caf49
fix: set quetzUrl and quetzSolverUrl via the settings system
mariobuikhuizen 35374f7
added args to standalone app
hbcarlos 6892473
added quetzUrl and quetzSolverUrl to config_data
hbcarlos e71b4de
Added settings to config_data on standalone app
hbcarlos f53ab5e
refactor: get subdir from command line
mariobuikhuizen d9c4745
refactor: reuse import_env for explicit list
mariobuikhuizen 6f60a41
fix: add better error handling
mariobuikhuizen 86e7334
feat: wire standalone settings to Ennvironment Manager
mariobuikhuizen 0a9294e
feat: add document editor for .conda, .conda.yml and .yml
mariobuikhuizen ff07f05
refactor: use initialize method on Handler to pass extra settings
mariobuikhuizen 089923c
refactor: use functions instead of arrow functions for components
mariobuikhuizen cfbe405
docs: document props and functions
mariobuikhuizen 72a2f70
feat: enable conda complete depending presence of quetzUrl
mariobuikhuizen b337da6
refactor: use proper plugin name
mariobuikhuizen 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
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
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,192 @@ | ||
| import * as React from 'react'; | ||
| import CodeMirror, { Editor } from 'codemirror'; | ||
| import 'codemirror/lib/codemirror.css'; | ||
| import './yaml'; | ||
| import * as condaHint from './CondaHint'; | ||
| import { IEnvironmentManager } from '../tokens'; | ||
| import { INotification } from 'jupyterlab_toastify'; | ||
|
|
||
| /** | ||
| * Conda solve properties | ||
| */ | ||
| export interface ICondaEnvSolveProps { | ||
| /** | ||
| * The URL of the Quetz server | ||
| */ | ||
| quetzUrl: string; | ||
| /** | ||
| * The URL of the Quetz server with the solver plugin, if different from quetzUrl | ||
| */ | ||
| quetzSolverUrl: string; | ||
| /** | ||
| * The Conda subdir (or platform e.g. osx-64, linux-32) of the backend | ||
| */ | ||
| subdir: string; | ||
| /** | ||
| * The initial content of the editors text area | ||
| */ | ||
| content?: string; | ||
| /** | ||
| * Should the channel name be expanded to the channel URL in the editors text area | ||
| */ | ||
| expandChannelUrl?: boolean; | ||
| /** | ||
| * Callback to get notified of changes to the editors text area | ||
| */ | ||
| onContentChange?(content: string): void; | ||
| } | ||
|
|
||
| export function CondaEnvSolve(props: ICondaEnvSolveProps): JSX.Element { | ||
| condaHint.register(props.quetzUrl, props.expandChannelUrl); | ||
| const codemirrorElem = React.useRef(null); | ||
|
|
||
| const [editor, setEditor] = React.useState(null); | ||
|
|
||
| React.useEffect(() => { | ||
| if (editor) { | ||
| if (props.content !== undefined && props.content !== editor.getValue()) { | ||
| editor.setValue(props.content); | ||
| editor.refresh(); | ||
| } | ||
| return; | ||
| } | ||
| const newEditor = CodeMirror(codemirrorElem.current, { | ||
| value: props.content || '', | ||
| lineNumbers: true, | ||
| extraKeys: { | ||
| 'Ctrl-Space': 'autocomplete', | ||
| 'Ctrl-Tab': 'autocomplete' | ||
| }, | ||
| tabSize: 2, | ||
| mode: 'yaml', | ||
| autofocus: true | ||
| }); | ||
| if (props.onContentChange) { | ||
| newEditor.on('change', (instance: Editor) => | ||
| props.onContentChange(instance.getValue()) | ||
| ); | ||
| } | ||
| setEditor(newEditor); | ||
|
|
||
| /* Apply lab styles to this codemirror instance */ | ||
| codemirrorElem.current.childNodes[0].classList.add('cm-s-jupyter'); | ||
| }); | ||
| return ( | ||
| <div | ||
| ref={codemirrorElem} | ||
| className="conda-complete-panel" | ||
| onMouseEnter={() => editor && editor.refresh()} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Solve the environment provided in environment_yml on the Quetz server and create it on the | ||
| * backend. | ||
| * | ||
| * @param environment_yml - The environment.yml content | ||
| * @param environmentManager - The Conda environment manager | ||
| * @param expandChannelUrl - The environment_yml contains channel names that should be expanded to | ||
| * channel URLS | ||
| * @param onMessage - Callback to provide feedback about the process | ||
| */ | ||
| export async function solveAndCreateEnvironment( | ||
| environment_yml: string, | ||
| environmentManager: IEnvironmentManager, | ||
| expandChannelUrl: boolean, | ||
| onMessage?: (msg: string) => void | ||
| ): Promise<void> { | ||
| const name = condaHint.getName(environment_yml); | ||
| const { quetzUrl, quetzSolverUrl, subdir } = environmentManager; | ||
|
|
||
| let message = 'Solving environment...'; | ||
| onMessage && onMessage(message); | ||
| let toastId = await INotification.inProgress(message); | ||
| try { | ||
| const explicitList = await condaHint.fetchSolve( | ||
| quetzUrl, | ||
| quetzSolverUrl, | ||
| (await subdir()).subdir, | ||
| environment_yml, | ||
| expandChannelUrl | ||
| ); | ||
| await INotification.update({ | ||
| toastId, | ||
| message: 'Environment has been solved.', | ||
| type: 'success', | ||
| autoClose: 5000 | ||
| }); | ||
|
|
||
| message = `creating environment ${name}...`; | ||
| onMessage && onMessage(message); | ||
| toastId = await INotification.inProgress(message); | ||
| await environmentManager.import(name, explicitList); | ||
|
|
||
| message = `Environment ${name} created.`; | ||
| onMessage && onMessage(message); | ||
| await INotification.update({ | ||
| toastId, | ||
| message, | ||
| type: 'success', | ||
| autoClose: 5000 | ||
| }); | ||
| } catch (error) { | ||
| onMessage && onMessage(error.message); | ||
| if (toastId) { | ||
| await INotification.update({ | ||
| toastId, | ||
| message: error.message, | ||
| type: 'error', | ||
| autoClose: 0 | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export interface ICondaEnvSolveDialogProps { | ||
| /** | ||
| * The Conda subdir (or platform e.g. osx-64, linux-32) of the backend | ||
| */ | ||
| subdir: string; | ||
| /** | ||
| * The Conda environment manager | ||
| */ | ||
| environmentManager: IEnvironmentManager; | ||
| } | ||
|
|
||
| export function CondaEnvSolveDialog( | ||
| props: ICondaEnvSolveDialogProps | ||
| ): JSX.Element { | ||
| const [environment_yml, setEnvironment_yml] = React.useState(''); | ||
| const [solveState, setSolveState] = React.useState(null); | ||
|
|
||
| return ( | ||
| <div className="condaCompleteDialog__panel"> | ||
| <div style={{ flexGrow: 1 }}> | ||
| <CondaEnvSolve | ||
| expandChannelUrl={false} | ||
| subdir={props.subdir} | ||
| quetzUrl={props.environmentManager.quetzUrl} | ||
| quetzSolverUrl={props.environmentManager.quetzSolverUrl} | ||
| onContentChange={setEnvironment_yml} | ||
| /> | ||
| </div> | ||
| <div style={{ padding: '12px' }}> | ||
| <button | ||
| onClick={() => | ||
| solveAndCreateEnvironment( | ||
| environment_yml, | ||
| props.environmentManager, | ||
| true, | ||
| setSolveState | ||
| ) | ||
| } | ||
| className="jp-Dialog-button jp-mod-accept jp-mod-styled" | ||
| > | ||
| Create | ||
| </button> | ||
| <span style={{ marginLeft: '12px' }}>{solveState}</span> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.