How to upload a pristine Python package to PyPI?

♀尐吖头ヾ 提交于 2019-12-05 17:48:23

问题


What's the magic "python setup.py some_incantation_here" command to upload a package to PyPI, in a form that can be downloaded to get the original package in its original form?

I have a package with some source and a few image files (as package_data). If I do "setup.py sdist register upload", the .tar.gz has the image files excluded. If I do "setup.py bdist_egg register upload", the egg contains the images but excludes the setup.py file. I want to be able to get a file uploaded that is just the entirety of my project -- aka "setup.py the_whole_freaking_thing register upload".

Perhaps the best way to do this is to manually tar.gz my project directory and upload it using the PyPI web interface?

Caveat: I'm trying to avoid having to store a simple project I just created in my SVN repo as well as on PyPI -- it seems like a waste of work to keep track of its history and files in two places.


回答1:


When you perform an "sdist" command, then what controls the list of included files is your "MANIFEST.in" file sitting next to "setup.py", not whatever you have listed in "package_data". This has something to do with the schizophrenic nature of the Python packaging solutions today; "sdist" is powered by the distutils in the standard library, while "bdist_egg" is controlled by the setuptools module.

To solve the problem, try creating a MANIFEST.in next to your setup.py file, and give it contents like this:

include *.jpg

Of course, I'm imaging that your "image files" are actual pictures rather than disk images or ISO images or something; you might have to adjust the above line if I've guessed wrong! But check out the Specifying which files to distribute section of the distutils docs, and see whether you can't get those files appearing in your .tar.gz source distribution! Good luck.



来源:https://stackoverflow.com/questions/778980/how-to-upload-a-pristine-python-package-to-pypi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!