PKzLjn=OOnyptune/__init__.py"""Nyptune hides a copy of your environment in your Jypyter notebooks so that other people can easily reproduce your work""" import time __version__ = '0.0.1.'+str(int(time.time())) from .magic import * from IPython import get_ipython ipy = get_ipython() if ipy: ipy.register_magics(CheckpointMagics) print("loaded bitches")PK/vL44nyptune/jupyter.pyfrom subprocess import * from pathlib import Path import os def presave(path, model, contents_manager): magix = model['content']['metadata''']['magix'] = {} conda = run(["conda", "list", "--explicit"], stdout = PIPE, encoding = 'utf-8', shell=False) magix['conda'] = conda.stdout.split('\n') pip = run(["pip", "list", "--format", "freeze"], stdout = PIPE, encoding = 'utf-8', shell = False) magix['pip'] = pip.stdout.split('\n') path = Path(path) cache = path.parent / '.cache' os.makedirs(cache, exist_ok = True) procs = [] magix['cache']={} ipfs = run(["ipfs", "add", "--nocopy", "-r", str(cache)], stdout = PIPE, encoding = 'utf-8', shell = False) for line in ipfs.stdout.strip().split('\n'): action, sig, name = line.split() magix['cache'][name] = sigPKyLwnyptune/magic.pyimport pprint from subprocess import * from pathlib import Path from abc import ABC, abstractmethod from collections import namedtuple import pickle, os from IPython.core.magic import * @magics_class class CheckpointMagics(Magics): def __init(self): self.enabled = false @line_cell_magic def checkpoint(self, line, cell = None): pass @line_magic def checkpoints(self, line): line = line.strip() if line == "on": self.enabled = true elif lien == "off": self.enabled = false class Restorable(ABC): @abstractmethod def save(self): pass def key(self): pass @abstractmethod def restore(self): pass class PickleRestorable(Restorable): def __init__(self, key=None, inner=None): self.inner = inner self.key = key def save(self): os.makedirs(".cache", exist_ok = True) with open(Path(".cache") / self.key, "wb") as file: pickle.dump(self.inner, file) def restore(self): with open(Path(".cache") / self.key, "rb") as file: self.inner = pickle.load(file) def get(): return innerPK}LMѨnyptune/script.pyimport sys import argparse from pathlib import Path from subprocess import * import re, platform, os def main(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(help='a subcommand') init_parser = subparsers.add_parser('init', help='initialize ipfs and add the save hook to the jupyter config file') init_parser.set_defaults(func=init) launch_parser = subparsers.add_parser('launch', help='create an environment for and launch a jupyter notebook') if len(sys.argv) == 1: parser.print_help() else: parsed = parser.parse_args() parsed.func(parsed) def init(parsed_args): config = Path.home() / '.jupyter' / 'jupyter_notebook_config.py' if not config.is_file(): print("generating an empty jupyter config file") run(["jupyter", "notebook", "--generate-config"], encoding = 'utf-8', shell = False) with open(config, 'r') as file: contents = file.read() if "nyptune" in contents: print("jupyter config file already mentions nyptune") else: with open(config, "a") as file: print("appending nyptune pre-save-hook to jupyter config") file.write("\nfrom nyptune.jupyter import presave\nc.ContentsManager.pre_save_hook = presave\n") if "64" in platform.machine(): machine = "amd64" else: machine = "386" name = platform.system().lower() ipfs = Path(os.path.realpath(__file__)).parent / "ipfs" / (name + "-" + machine) / "ipfs" run([str(ipfs), "init"], encoding = 'utf-8', shell = False) run([str(ipfs), "config", "--json", "Experimental.FilestoreEnabled", "true"], encoding = 'utf-8', shell = False)PK!HT:'/3nyptune-0.0.1.1526004232.dist-info/entry_points.txtN+I/N.,()ʫ,()Kz <..PK!Hp!Qa(nyptune-0.0.1.1526004232.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,zd&Y)r$[)T&UD"PK!H$2+nyptune-0.0.1.1526004232.dist-info/METADATA=R0 E{~ O+ D$<̮zQqΝ+iO Ve;5# ɞԿjoWo9EðE؉   ld XPB9Ab,f8,#z Lv))DH[㬞QkDBMsb5G}ix#߇9,]Yre9yU6}mU?PK!Hc)nyptune-0.0.1.1526004232.dist-info/RECORDv0}h ",CAT GR(~<=.{LH44 ARԏ]cHϕw>))ꂅy~&R{87jF:RK/]JQVB2T8{rS Z9C3&IkZT3҉9P7mό%(?!1e.EpZ" eT~Yz~qE * ,AIxL Sa]q۷AYΚ)pwmpJoJ8Y{eL(A-.]5csVRz*lN(Da휕_Ę&Z[_m1e4\VK8W\o {PKzLjn=OOnyptune/__init__.pyPK/vL44nyptune/jupyter.pyPKyLwnyptune/magic.pyPK}LMѨ nyptune/script.pyPK!HT:'/3nyptune-0.0.1.1526004232.dist-info/entry_points.txtPK!Hp!Qa(3nyptune-0.0.1.1526004232.dist-info/WHEELPK!H$2+nyptune-0.0.1.1526004232.dist-info/METADATAPK!Hc)nyptune-0.0.1.1526004232.dist-info/RECORDPKe