Best way to share code across several setup.py scripts?

前端 未结 1 589
梦如初夏
梦如初夏 2021-01-13 18:50

I\'ve got several packages I\'m working on, and I\'d like to share code between their setup.py scripts. Is there any good way to do this or is code duplication my only opti

相关标签:
1条回答
  • 2021-01-13 18:59

    Normally setup.py is the entry point for distribution of distinct packages. As such, it's hard to then share code between those packages.

    If you use setuptools (or it's fork, distribute) in your setup.py, you can specify packages that must be installed when installing your package with the setup_requires entry.

    Unfortunately, your setup.py is executed first; as soon as the setup_requires line is parsed, the extra packages listed there will be installed locally, but this may be too late for your needs.

    The work-around is to create a separate Distribution object before you call setup which defines the setup_requires entries:

    import setuptools
    
    setuptools.dist.Distribution(dict(setup_requires='yoursharedsetuppackage'))
    # `setup_requires` is parsed and acted upon immediately; from here on out
    # the yoursharedsetuppackage is installed and importable.
    
    import yoursharedsetuppackage
    
    setup(...)
    
    0 讨论(0)
提交回复
热议问题