-1

I want to create a thin wrapper around this library https://github.com/jupyter-incubator/sparkmagic#installation

As you can see in the link, the installation step requires

  1. installing some packages with pip
  2. run some command of the type jupyter enable ... or jupyter-kernelspec install
  3. custom configuration file that I want to generate and place in the correct place

I am checking which options I have to make the installation as automatic as calling a script. So far I have came up creating a bash script with all these commands. In this way it works with a simple install.sh but I might have problems since I will not know which python binaries to use. If a user wants to install the lib for python2 or python3 he cannot have this choice unless he touches the script.

I have then tried to use setup.py and override the cmdclass to insert custom code

from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install


class PostDevelopCommand(develop):
  """Post-installation for development mode."""
  def run(self):
    develop.run(self)
    print("do things")

class PostInstallCommand(install):
  """Post-installation for installation mode."""
  def run(self):
    install.run(self)
    print("do things")

setup(
  ...
  install_requires=['sparkmagic'],
  cmdclass={
    'develop': PostDevelopCommand,
    'install': PostInstallCommand,
},

...
)

but the custom prints worked only when running python setup.py install but not for pip install

I would like to make this last option work but if this is not the right patter to do this kind of things, could you suggest me which way to go?

alexlipa
  • 1,131
  • 2
  • 12
  • 27

1 Answers1

1

The issue is not with pip install directly but with wheels. Projects packaged as wheel can not have custom install steps. See for example this discussion. Since pip prefers working with wheels, building them locally if necessary, your custom steps are not run at install time. There are probably ways to prevent the wheel step though.

Knowing this, you probably should follow the advice from Jan Vlcinsky in his comment for his answer to this question: Post install script after installing a wheel.

  • Add a setuptools console entry point to your project (let's call it myprojectconfigure). Maybe you prefer using the distutils script feature instead.

  • Instruct the users of your package to run it immediately after installing your package (pip install myproject && myprojectconfigure).

  • Eventually think about providing myprojectconfigure --uninstall as well.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • so you suggest tu use `virtualenv`? Otherwise how `myprojectconfigure` will know what interpreter to use? – alexlipa Oct 12 '19 at 13:00
  • _Setuptools_ hardcodes the Python interpreter used to install the project into the entry points, whether it is from a virtual environment or not. So that shouldn't be an issue. – sinoroc Oct 12 '19 at 13:42