Skip to content

Commit

Permalink
Bump version 0.1.3 enable/disable command
Browse files Browse the repository at this point in the history
  • Loading branch information
costrouc committed Jun 28, 2022
1 parent 4790777 commit c75b740
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## [0.1.3] - 2022-06-28

### Added

- Enable and Disable command for nb_conda_store_kernels being enabled

## [0.1.2] - 2022-06-28

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Alternatively `pip` works as well but requires one additional step.
```shell
pip install nb_conda_store_kernels
python -m nb_conda_store_kernels.install --enable
# python -m nb_conda_store_kernels.install --disable # to disable
```

`python -m nb_conda_store_kernels.install --enable` simply modifies a
Expand Down
13 changes: 0 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@
(system:
let pkgs = nixpkgs.legacyPackages.${system};
pythonPackages = pkgs.python3Packages;
nb_conda_store_kernels = pythonPackages.buildPythonPackage {
pname = "nb_conda_store_kernels";
version = "0.1.0";

src = ./.;

propagatedBuildInputs = [
pythonPackages.jupyter-client
pythonPackages.traitlets
pythonPackages.requests
];
};
in
{
devShell = pkgs.mkShell {
buildInputs = [
nb_conda_store_kernels
pythonPackages.jupyterlab

pythonPackages.pytest
Expand Down
2 changes: 1 addition & 1 deletion nb_conda_store_kernels/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.1.3"
51 changes: 39 additions & 12 deletions nb_conda_store_kernels/install.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
import sys
import argparse
import pathlib

from jupyter_core.paths import jupyter_config_path
from traitlets.config.manager import BaseJSONConfigManager


def install():
jupyter_config_path = pathlib.Path("~/.jupyter").expanduser()
cfg = BaseJSONConfigManager(config_dir=str(jupyter_config_path))
cfg.set(
"jupyter_config",
{
"JupyterApp": {
"kernel_spec_manager_class": "nb_conda_store_kernels.manager.CondaStoreKernelSpecManager"
}
},
)
def main():
parser = argparse.ArgumentParser(description='nb_conda_store_kernels install and uninstall')
parser.add_argument('--enable', action='store_true', help='Enable nb_conda_store_kernels kernel manager')
parser.add_argument('--disable', action='store_true', help='Disable nb_conda_store_kernels kernel manager')
args = parser.parse_args()

config_path = pathlib.Path(jupyter_config_path()[0])

if args.enable and args.disable:
print('Cannot have both enable and disable options active')
sys.exit(1)
elif args.enable:
enable(config_path)
elif args.disable:
disable(config_path)



KERNEL_MANAGER = "nb_conda_store_kernels.manager.CondaStoreKernelSpecManager"


def enable(config_path: pathlib.Path):
cfg = BaseJSONConfigManager(config_dir=str(config_path))
data = cfg.get("jupyter_config")
data['JupyterApp'] = data.get("JupyterApp", {})
data['JupyterApp']["kernel_spec_manager_class"] = KERNEL_MANAGER
cfg.set("jupyter_config", data)


def disable(config_path: pathlib.Path):
cfg = BaseJSONConfigManager(config_dir=str(config_path))
data = cfg.get("jupyter_config")
if data.get("JupyterApp", {}).get("kernel_spec_manager_class") == KERNEL_MANAGER:
del data["JupyterApp"]["kernel_spec_manager_class"]
cfg.set("jupyter_config", data)


if __name__ == "__main__":
install()
main()

0 comments on commit c75b740

Please sign in to comment.