How can I get my setup.py to use a relative path to my files?

前端 未结 5 1091
孤街浪徒
孤街浪徒 2021-01-04 04:43

I\'m trying to build a Python distribution with distutils. Unfortunately, my directory structure looks like this:

/code
    /mypackage
        __ini         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 04:57

    What directory structure do you want inside of the distribution archive file? The same as your existing structure?

    You could package everything one directory higher (code in your example) with this modified setup.py:

    from distutils.core import setup
    
    setup(
        name = 'MyPackage',
        description = 'This is my package',
        packages = ['mypackage', 'mypackage.subpackage'], 
        version = '1',
        url = 'http://www.mypackage.org/',
        author = 'Me',
        author_email = 'me@here.com',
        script_name = './build/setup.py',
        data_files = ['./build/setup.py']
    )
    

    You'd run this (in the code directory):

    python build/setup.py sdist
    

    Or, if you want to keep dist inside of build:

    python build/setup.py sdist --dist-dir build/dist
    

    I like the directory structure you're trying for. I've never thought setup.py was special enough to warrant being in the root code folder. But like it or not, I think that's where users of your distribution will expect it to be. So it's no surprise that you have to trick distutils to do something else. The data_files parameter is a hack to get your setup.py into the distribution in the same place you've located it.

提交回复
热议问题