-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
env statusbar item, get env info via py script, refactoring
- Loading branch information
Showing
8 changed files
with
494 additions
and
254 deletions.
There are no files selected for viewing
This file contains 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 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,145 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { VDomModel, VDomRenderer } from '@jupyterlab/apputils'; | ||
import React from 'react'; | ||
import { GroupItem, interactiveItem, TextItem } from '@jupyterlab/statusbar'; | ||
import { | ||
pythonIcon | ||
} from '@jupyterlab/ui-components'; | ||
|
||
/** | ||
* A pure functional component for rendering environment status. | ||
*/ | ||
function EnvironmentStatusComponent( | ||
props: EnvironmentStatusComponent.IProps | ||
): React.ReactElement<EnvironmentStatusComponent.IProps> { | ||
return ( | ||
<GroupItem onClick={props.handleClick} spacing={2} title={props.description}> | ||
<pythonIcon.react title={''} top={'2px'} stylesheet={'statusBar'} /> | ||
<TextItem source={props.name} /> | ||
</GroupItem> | ||
); | ||
} | ||
|
||
/** | ||
* A namespace for EnvironmentStatusComponent statics. | ||
*/ | ||
namespace EnvironmentStatusComponent { | ||
/** | ||
* Props for the environment status component. | ||
*/ | ||
export interface IProps { | ||
/** | ||
* A click handler for the environment status component. By default | ||
* we have it bring up the environment change dialog. | ||
*/ | ||
handleClick: () => void; | ||
|
||
/** | ||
* The name the environment. | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* The description of the environment. | ||
*/ | ||
description: string; | ||
} | ||
} | ||
|
||
/** | ||
* A VDomRenderer widget for displaying the environment. | ||
*/ | ||
export class EnvironmentStatus extends VDomRenderer<EnvironmentStatus.Model> { | ||
/** | ||
* Construct the environment status widget. | ||
*/ | ||
constructor(opts: EnvironmentStatus.IOptions) { | ||
super(new EnvironmentStatus.Model()); | ||
this.model.name = opts.name; | ||
this.model.description = opts.description; | ||
this._handleClick = opts.onClick; | ||
this.addClass(interactiveItem); | ||
} | ||
|
||
/** | ||
* Render the environment status item. | ||
*/ | ||
render() { | ||
if (this.model === null) { | ||
return null; | ||
} else { | ||
return ( | ||
<EnvironmentStatusComponent | ||
name={this.model.name} | ||
description={this.model.description} | ||
handleClick={this._handleClick} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
private _handleClick: () => void; | ||
} | ||
|
||
/** | ||
* A namespace for EnvironmentStatus statics. | ||
*/ | ||
export namespace EnvironmentStatus { | ||
export class Model extends VDomModel { | ||
constructor() { | ||
super(); | ||
|
||
this._name = 'env'; | ||
this._description = ''; | ||
} | ||
|
||
get name() { | ||
return this._name; | ||
} | ||
|
||
set name(val: string) { | ||
const oldVal = this._name; | ||
if (oldVal === val) { | ||
return; | ||
} | ||
this._name = val; | ||
this.stateChanged.emit(void 0); | ||
} | ||
|
||
get description(): string { | ||
return this._description; | ||
} | ||
set description(val: string) { | ||
const oldVal = this._description; | ||
if (oldVal === val) { | ||
return; | ||
} | ||
this._description = val; | ||
this.stateChanged.emit(void 0); | ||
} | ||
|
||
private _name: string; | ||
private _description: string; | ||
} | ||
|
||
/** | ||
* Options for creating a EnvironmentStatus object. | ||
*/ | ||
export interface IOptions { | ||
/** | ||
* Environment name | ||
*/ | ||
name: string; | ||
/** | ||
* Environment description | ||
*/ | ||
description: string; | ||
/** | ||
* A click handler for the item. By default | ||
* we launch an environment selection dialog. | ||
*/ | ||
onClick: () => void; | ||
} | ||
} |
This file contains 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 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 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,15 @@ | ||
import os, sys, json | ||
|
||
env_type = 'system' | ||
env_name = 'python' | ||
|
||
if (getattr(sys, "base_prefix", None) or getattr(sys, "real_prefix", None) or sys.prefix) != sys.prefix: | ||
env_type = 'venv' | ||
|
||
if env_type != 'venv' and os.path.exists(os.path.join(sys.prefix, "conda-meta")): | ||
env_type = 'conda' | ||
|
||
if env_type != 'system': | ||
env_name = os.path.basename(sys.prefix) | ||
|
||
print(json.dumps({"type" : env_type, "name": env_name})) |
Oops, something went wrong.