What happened to this `setup.py`?

I had problems getting setup.py for sdist to work sdist . I cooked it. I have the following directory structure:

 my_package\ my_subpackage\ __init__.py deep_module.py __init__.py module.py setup.py 

And here is what I have in setup.py :

 #!/usr/bin/env python from distutils.core import setup import distutils setup( name='a', version='0.1', description='a', author='a', author_email=' a@a.com ', url='http://a.org', packages=['my_package','my_package.my_subpackage'], package_dir={'': '..'}, license= "a", long_description = 'aaa', ) 

(The file 'aaa' is just a placeholder.)

Anyway, it works fine when I do setup.py install , but when I try to do setup.py sdist , a few interesting things happen:

  • The MANIFEST file has been created.

  • A copy of the my_package folder is created inside the existing my_package folder (although it skips several installation-related files that I think.)

  • The A dist folder is created, inside which there is a zipfile, inside the folder with the package name, but inside this folder there is no whole package, as I hoped, but only two files, setup.py and PKG-INFO .

What am I doing wrong? How to make sdist work?

0
source share
2 answers

Instead of this:

 my_package\ my_subpackage\ __init__.py deep_module.py __init__.py module.py setup.py 

Try the following:

 my_package_source\ setup.py README.txt my_package\ my_subpackage\ __init__.py deep_module.py __init__.py module.py 

You really don't need README, it's just for illustrative purposes, what things are in the root directory of your project folder.

=== EDIT ============================================== ================

I have to clarify. After starting, its directory should look something like this:

 my_package_source\ setup.py README.txt MANIFEST PKG-INFO dist\ my_package_0.X.tar.gz (or .zip on windows I believe) my_package\ my_subpackage\ __init__.py deep_module.py __init__.py module.py 

Use the package in the dist distribution.

+4
source

The problem is well explained here :

Setuptools has many silent crash modes. One of them is to include all the files in the sdist release (well, not entirely unsuccessful, you could have RTFM, but the default behavior is unexpected). This post will serve as a google-yourself-answer for this problem until we get a new, more brilliant one. Distribute all our problems.

As the comments note, the misdesign error is actually located in distutils - setuptools just cannot fix it (if you use svn, everything is actually a little better).

I can reproduce your problem as it is observed, i.e. shorten the file names a bit, I have:

 $ ls -lR total 8 -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 modu.py drwxr-xr-x 4 aleax eng 136 Oct 24 11:25 mysub -rw-r--r-- 1 aleax eng 323 Oct 24 11:26 setup.py ./mysub: total 0 -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 deepmod.py 

and running python setup.py sdist produces (as well as warnings):

 $ ls -lR total 16 -rw-r--r-- 1 aleax eng 104 Oct 24 11:35 MANIFEST -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 __init__.py drwxr-xr-x 3 aleax eng 102 Oct 24 11:35 dist -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 modu.py drwxr-xr-x 5 aleax eng 170 Oct 24 11:35 mypack drwxr-xr-x 4 aleax eng 136 Oct 24 11:25 mysub -rw-r--r-- 1 aleax eng 323 Oct 24 11:26 setup.py ./dist: total 8 -rw-r--r-- 1 aleax eng 483 Oct 24 11:35 a-0.1.tar.gz ./mypack: total 0 -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 modu.py drwxr-xr-x 4 aleax eng 136 Oct 24 11:35 mysub ./mypack/mysub: total 0 -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 deepmod.py ./mysub: total 0 -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 2 aleax eng 0 Oct 24 11:25 deepmod.py 

One solution is to change the layout of the directory as follows (from the current mypack directory):

 $ mkdir mypack $ mv __init__.py modu.py mysub/ mypack $ touch README.txt 

it happened:

 $ ls -lR total 8 -rw-r--r-- 1 aleax eng 0 Oct 24 11:37 README.txt drwxr-xr-x 5 aleax eng 170 Oct 24 11:37 mypack -rw-r--r-- 1 aleax eng 323 Oct 24 11:26 setup.py ./mypack: total 0 -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 modu.py drwxr-xr-x 4 aleax eng 136 Oct 24 11:25 mysub ./mypack/mysub: total 0 -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 __init__.py -rw-r--r-- 1 aleax eng 0 Oct 24 11:25 deepmod.py 

(and get rid of one of the warnings, that is, about README - about the missing MANIFEST.in obviously remains ;-). Also change one line of setup.py to:

 package_dir={'': '.'}, 

Now, after python setup.py sdist , you will get a decent archive:

 $ tar tvf dist/a-0.1.tar.gz drwxr-xr-x aleax/eng 0 2009-10-24 11:40:05 a-0.1/ drwxr-xr-x aleax/eng 0 2009-10-24 11:40:05 a-0.1/mypack/ -rw-r--r-- aleax/eng 0 2009-10-24 11:25:30 a-0.1/mypack/__init__.py -rw-r--r-- aleax/eng 0 2009-10-24 11:25:30 a-0.1/mypack/modu.py drwxr-xr-x aleax/eng 0 2009-10-24 11:40:05 a-0.1/mypack/mysub/ -rw-r--r-- aleax/eng 0 2009-10-24 11:25:30 a-0.1/mypack/mysub/__init__.py -rw-r--r-- aleax/eng 0 2009-10-24 11:25:30 a-0.1/mypack/mysub/deepmod.py -rw-r--r-- aleax/eng 156 2009-10-24 11:40:05 a-0.1/PKG-INFO -rw-r--r-- aleax/eng 0 2009-10-24 11:37:41 a-0.1/README.txt -rw-r--r-- aleax/eng 322 2009-10-24 11:39:46 a-0.1/setup.py 

the MANIFEST file is still being created in your current directory, but I hope this is not a problem.

+6
source

Source: https://habr.com/ru/post/1492406/


All Articles