0

In my python project, there is another python project s2p downloaded as a git submodule. How can I install my project and only the s2p folder in s2p project without running s2p/setup.py in s2p project.
Eg:

myproject
    - setup.py
    - mypackage
        - __init__.py
    - s2p
        - setup.py
        - s2p
            - __init__.py
        - many other files ...

As you can see, there are two setup.py in myproject/ folder. One is the setup.py of myproject and another setup.py is in a git-submodule s2p.

The myproject/setup.py looks like:

packages=(find_packages(include=["mypackage.*"]) + find_packages(where="./s2p/s2p")),

Explanation: I want it to install mypackage and only the folder s2p under s2p submodule without using s2p/setup.py.

Installation: the following is run

~/myproject$ pip install -e .

But s2p is still not installed correctly:

$ python
>>> import s2p
>>> print(s2p.__file__)
None

Note: the myproject/setup.py installs all required packages to run s2p.

1 Answer 1

0

One solution is:

  • Rename myproject/s2p to myproject/s2p_repo
  • Copy s2p_repo/s2p/ folder under myproject. Thus the directory tree is:
myproject
    - setup.py
    - mypackage
        - __init__.py
    - s2p_repo
        - setup.py
    - s2p
        - __init__.py
  • Change the content of myproject/setup.py to:
packages=find_packages(include=["mypackage.*", "s2p.*"])
  • And run pip install -e .

The above steps can be automated by customizing develop command in setup.py.
E.g.:

from setuptools.command import develop
class CustomDevelop(develop.develop, object):
    """
    Class needed for "pip install -e ."
    """

    def run(self):
        subprocess.check_call("cp -r s2p_repo/s2p s2p", shell=True)
        super(CustomDevelop, self).run()

setup(
    ...
    packages=find_packages(include=["liveeo.*", "s2p.*"]),
    python_requires="~=3.8",
    cmdclass={"develop": CustomDevelop,},
)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.