Skip to content

Commit

Permalink
installl kernel on download
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfast committed Sep 8, 2020
1 parent 0ea6cd9 commit e31343f
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
from pathlib import Path
import setuptools, datetime
import setuptools, datetime, sys, os
from setuptools.command.install import install


try:
from jupyter_client.kernelspec import KernelSpecManager

HAVE_JUPYTER = True
except ImportError:
HAVE_JUPYTER = False


class kernelspec(install):
def run(self):
print("run")
root = self.root if self.root else None
prefix = self.prefix if self.prefix else None
try:
install_jupyter_hook(prefix=prefix, root=root)
except Exception:
import traceback

traceback.print_exc()
print("Installing Jupyter hook failed.")
install.run(self)


def install_jupyter_hook(prefix=None, root=None):
"""Make pidgy available as a Jupyter kernel."""

if not HAVE_JUPYTER:
print(
"Could not install Jupyter kernel spec, please install " "Jupyter/IPython."
)
return

if "CONDA_BUILD" in os.environ:
prefix = sys.prefix
if sys.platform == "win32":
prefix = prefix.replace(os.sep, os.altsep)
user = "--user" in sys.argv
print("Installing Jupyter kernel spec:")
print(" root: {0!r}".format(root))
print(" prefix: {0!r}".format(prefix))
print(" as user: {0}".format(user))
if root and prefix:
# os.path.join isn't used since prefix is probably absolute
prefix = root + prefix
print(" combined prefix {0!r}".format(prefix))
KernelSpecManager().install_kernel_spec(
"./pidgy/kernelspec", "pidgy", user=user, replace=True, prefix=prefix
)


name = "pidgy"

Expand Down Expand Up @@ -40,6 +92,7 @@
"Programming Language :: Python :: 3.8",
"Framework :: Pytest",
],
cmdclass={"install": kernelspec},
zip_safe=False,
)

Expand Down

0 comments on commit e31343f

Please sign in to comment.