Skip to content

Commit

Permalink
Updated module search path. Resolves #22.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirbs- committed Aug 19, 2016
1 parent 510ff7b commit ca73cc9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dev-copy.py
/hide_code/*.pyc
hide_code.egg*
hide_code.sublime-project
hide_code.sublime-workspace
hide_code.sublime-workspace
/hide_code/test/*.ipynb
/hide_code/test/.ipynb_checkpoints/*
21 changes: 15 additions & 6 deletions hide_code/hide_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,20 @@ def load_jupyter_server_extension(nb_app):


def install(nb_path=None, server_config=True, DEBUG=False):
"""
Installs javascript and exporting server extensions in Jupyter notebook.
Args:
nb_path (string): Path to notebook module.
server_config (boolean): Install exporting server extensions.
DEBUG (boolean): Verbose mode.
"""

install_path = None
print('Starting hide_code.js install...')
current_dir = path.abspath(path.dirname(__file__))
config_dirs = j_path.jupyter_config_path()
site_packages_path = Utils.get_site_package_dir()
notebook_module_path = Utils.get_notebook_module_dir()

# check for config directory with a "custom" folder
# TODO update this logic to check if custom.js file exists
Expand All @@ -96,8 +105,8 @@ def install(nb_path=None, server_config=True, DEBUG=False):

# last ditch effort in case jupyter config directories don't contain custom/custom.js
if install_path == None:
print("No config directories contain \"custom\" folder. Trying site-packages...")
install_path = path.join(site_packages_path, "notebook", "static", "custom")
print("No config directories contain \"custom\" folder. Trying Jupyter notebook module path...")
install_path = path.join(notebook_module_path, "static", "custom")


if nb_path != None:
Expand Down Expand Up @@ -190,17 +199,17 @@ def setup_info():
ext = 'Loaded'

files = []
for (dirpath, dirnames, filenames) in os.walk(path.join(Utils.get_site_package_dir(), 'hide_code')):
for (dirpath, dirnames, filenames) in os.walk(path.join(Utils.get_module_dir())):
files.extend(filenames)
break

custom_js = ''
with open(path.join(Utils.get_site_package_dir(), 'notebook','static','custom','custom.js'), 'r') as f:
with open(path.join(Utils.get_notebook_module_dir(), 'notebook','static','custom','custom.js'), 'r') as f:
for line in iter(f):
if not line.startswith(' *') and not line.startswith('/'):
custom_js = custom_js + line + ' '


return ("Installation dir: {0}\nConfiguration dir: {1}\nExport handler extensions: {2}\nHide Code files: {3}\nCustom JS contents: {4}"
.format(Utils.get_site_package_dir(), j_path.jupyter_config_dir(), ext, files, custom_js))
.format(Utils.get_module_dir(), j_path.jupyter_config_dir(), ext, files, custom_js))

2 changes: 1 addition & 1 deletion hide_code/hide_code_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils import Utils
class HideCodeConfig(object):

config_file = path.join(Utils.get_site_package_dir(), 'hide_code','hide_code_config.json')
config_file = path.join(Utils.get_module_dir(),'hide_code_config.json')

@classmethod
def set(cls, key, value):
Expand Down
17 changes: 11 additions & 6 deletions hide_code/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import os
import inspect
import notebook

class Utils(object):

@classmethod
def get_site_package_dir(cls):
def get_notebook_module_dir(cls):
"""
Returns path to jupter notebook module.
"""
return os.path.dirname(inspect.getfile(notebook))

@classmethod
def get_module_dir(cls):
"""
Returns path to hide_code module.
"""
os_file = os.__file__
if os_file.endswith('c'):
return os.path.join(os_file[:-7], "site-packages")
else:
return os.path.join(os_file[:-6], "site-packages")
return os.path.dirname(inspect.getfile(cls))
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run(self):
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.3.0',
version='0.3.1',

description='A Jupyter notebook extension to hide code, prompts and outputs.',
long_description=long_description,
Expand All @@ -61,7 +61,7 @@ def run(self):
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',

# Indicate who your project is intended for
'Intended Audience :: Developers',
Expand Down

0 comments on commit ca73cc9

Please sign in to comment.