Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -*- coding: utf-8 -*- 

2""" 

3@file 

4@brief Functions to prepare a setup on Windows 

5 

6.. todoext:: 

7 :title: enables js extension on jupyter 

8 :tag: enhancement 

9 

10 Run something like:: 

11 

12 jupyter nbextension enable --py --sys-prefix widgetsnbextension 

13""" 

14from __future__ import print_function 

15import sys 

16import os 

17 

18from ..installhelper.install_cmd_helper import run_cmd, get_pip_program 

19from .win_exception import WinInstallException 

20 

21if sys.version_info[0] == 2: 

22 FileNotFoundError = Exception 

23 

24 

25def ipython_create_profile(config_path, python_path, name="win_profile", fLOG=print): 

26 """ 

27 creates a ipython profile 

28 

29 @param config_path where to create it 

30 @param python_path python path (to get ipython) 

31 @param profile name 

32 @param fLOG logging function 

33 @return profile path 

34 """ 

35 if sys.platform.startswith("win"): 

36 ipython_path = os.path.join(python_path, "ipython.exe") 

37 if not os.path.exists(ipython_path): 

38 ipython_path = os.path.join( 

39 python_path, "Scripts", "ipython.exe") 

40 if not os.path.exists(ipython_path): 

41 raise FileNotFoundError(ipython_path) 

42 else: 

43 ipython_path = os.path.join( 

44 python_path, "ipython") 

45 

46 cmd = " profile create {1} --ipython-dir={0}".format(config_path, name) 

47 cmd = ipython_path + cmd 

48 out, err = run_cmd(cmd, wait=True, fLOG=fLOG, change_path=python_path) 

49 profile = os.path.join( 

50 config_path, "profile_" + name, "ipython_config.py") 

51 if not os.path.exists(profile): 

52 raise WinInstallException( 

53 "missing file, unable to execute:\nFILE:\n{3}\nCMD:\n{0}\nOUT:\n{1}\nERR-6:\n{2}".format(cmd, out, err, profile)) 

54 return os.path.dirname(profile) 

55 

56 

57def ipython_update_profile(profile_path): 

58 """ 

59 update the profile with custom settings (file filters) 

60 

61 @param profile_path path to profile 

62 """ 

63 profile = os.path.join(profile_path, "ipython_kernel_config.py") 

64 with open(profile, "r") as f: 

65 content = f.read() 

66 add = """ 

67 c.ContentsManager.hide_globs = ['__pycache__', '*.pyc', '*.pyo', '.DS_Store', '*.so', '*.dylib', '*~', ".ipynb_checkpoints", 

68 ".kernel-*.json", ".kernel", ".RData", ".RHistory"] 

69 c.FileContentsManager.hide_globs = ['__pycache__', '*.pyc', '*.pyo', '.DS_Store', 

70 '*.so', '*.dylib', '*~', ".ipynb_checkpoints", ".kernel-*.json", ".kernel", ".RData", ".RHistory"] 

71 """.split("\n") 

72 content += "\n".join(_.strip() for _ in add) 

73 with open(profile, "w") as f: 

74 f.write("\n" + content + "\n") 

75 

76 

77def install_jupyter_extension(python_path): 

78 """ 

79 install jupyter extension 

80 

81 @param python_path python path 

82 @return out, err 

83 """ 

84 if sys.platform.startswith("win"): 

85 pip = os.path.join(python_path, "Scripts", "pip.exe") 

86 if not os.path.exists(pip): 

87 pip = get_pip_program(exe=python_path) 

88 else: 

89 pip = get_pip_program(exe=python_path) 

90 

91 cmd = "{0} install https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip --user".format( 

92 pip) 

93 out, err = run_cmd(cmd) 

94 if err: 

95 raise WinInstallException( 

96 "unable to install jupyter extension\nOUT:{0}\nERR-7{1}".format(out, err)) 

97 return out, err