Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install local extras in Python

setup.py of my package X uses setuptools to optionally install an extra package Y, via the extras_require parameter.

Now package Y disappeared from PyPi and, as far as I can tell, from the visible Internet. easy_install X[Y] fails with error: Could not find suitable distribution for Y.

However, I still have a local copy of Y's tarball. Y is a pure-Python package.

What is the best way to modify setup.py to allow this (local?) optional extra?


EDIT: The fix is meant to be temporary, until I figure out a proper replacement. I do not want to start officially maintaining Y myself :)

like image 287
Radim Avatar asked Jun 27 '11 23:06

Radim


People also ask

How do I install a local package in Python?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How do I install additional modules in Python?

To add a new module or change the version of an existing module, use the --additional-python-modules job parameter key with a value containing a list of comma-separated Python modules. This allows your AWS Glue 2.0 ETL job to install the additional modules using the Python package installer (pip3).


2 Answers

You could subclass setuptools.Command and then overload the default install command. Then you could have THAT execute a subprocess that installs the dependency. It's a hack, but that's what you were asking for!

In setup.py:

from setuptools import Command
class MyInstallCommand(Command):
    # Overload the 'install' command to do default install but also install
    # your provided tarball. Blah blah blah read the docs on what to do here.

setup(
    name='mypackage',
    # etc ... and then...
    # Overload the 'install' command 
    cmdclass={
        'install': MyInstallCommand, 
    }
)

I'm grossly oversimplifying it, but this is the basic gist.

like image 79
jathanism Avatar answered Oct 26 '22 20:10

jathanism


I found a quick workaround via the dependency_links option of setuptools.

  1. Upload Y's tarball to some url http://URL_Y.
  2. Add the line: dependency_links = ['http://URL_Y'], to my setup.py.

Now easy_install X[Y] works and I didn't have to register Y anywhere. I will delete it from URL_Y as soon as I have a proper fix.

like image 44
Radim Avatar answered Oct 26 '22 20:10

Radim