Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call another setup.py in setup.py

My repository contains my own python module and a submodule to one of its dependencies which has its own setup.py.

I'd like to call the dependency's setupy.py when installing my own lib, how is it possible?

My first attempt:

 $ tree
.
├── dependency
│   └── setup.py
└── mylib
    └── setup.py


 $ cat mylib/setup.py 
from setuptools import setup

setup(
    name='mylib',
    install_requires= ["../dependency"]
    # ...
)

$ cd mylib && python setup.py install
error in arbalet_core setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'../depen'"

However install_requires does not accept paths.

My second attempt was to use dependency_links=["../dependency"] with install_requires=["dependency"] however a dependency of the same name already exists in Pypi so setuptools tries to use that version instead of mine.

What's the correct/cleanest way?

like image 377
myoan Avatar asked Nov 27 '16 17:11

myoan


People also ask

Does pip call setup py?

For installing packages in “editable” mode (pip install --editable), pip will invoke setup.py develop , which will use setuptools' mechanisms to perform an editable/development installation.

What can I use instead of distutils?

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides: support for declaring project dependencies.

Is setup py outdated?

...as of the last few years all direct invocations of setup.py are effectively deprecated in favor of invocations via purpose-built and/or standards-based CLI tools like pip, build and tox.

How is setup py called?

The setup.py is a standard Python file. It can have any name, but by convention, it is named setup.py so that each script does not have a separate method.


1 Answers

A possible solution is to run a custom command before/after the install process.

An example:

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

import subprocess

class InstallLocalPackage(install):
    def run(self):
        install.run(self)
        subprocess.call(
            "python path_to/local_pkg/setup.py install", shell=True
        )

setup(
    ...,
    cmdclass={ 'install': InstallLocalPackage }
)
like image 61
HappyCry Avatar answered Sep 18 '22 23:09

HappyCry