Pure Python Package Release Setup Scripting example

Source: Internet
Author: User

If you have multiple modules that need to be published and they exist in more than one package, it may be much easier to specify the entire package than the specified module. Even if your module is not in a package, this approach will work; you can tell Distutils to process the module from the root package, and it works like any other package (unless you don't need to have a __init__.py file).

Example 1.1 Root pack release

The file structure is:

<  Root>/ setup.  PY foo.  PY Bar.  PY          

The setup script can write this:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', packages=[ "],)                 

(empty string denotes root package)

Example 1.2 package release (module in subdirectories)

If you move the two module files in the example above into a subdirectory, they are still in the root package, such as:

<  Root>/setup.py src/ foo.  PY Bar.  PY         

Then the root package will still be specified, but you must tell Distutils where the source files are:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', package_dir ={':' src '}, packages=['],)     
Example 2.1 Package Release

If you want to publish multiple modules in the same package (or in a child package). For example, if the foo and bar modules belong to package Foobar, the file structure is as follows:

<  Root>/setup.py foobar/ __init__.  PY foo.  PY Bar.  PY           

In fact, this is the default level of Distutils, and a streamlined setup script can write:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', packages=[ ' Foobar '],)                 
Example 2.2 Package release (module directory name is not package name)

If you want to put the module in a directory that is not a package name, you also need to use the package_dir parameter. For example, if the src directory has multiple modules in the foobar package:

<  Root>/setup.py src/ __init__.  PY foo.  PY Bar.  PY           

The appropriate setup script will be:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', package_dir ={' foobar ':' src '}, packages=[' Foobar '],)    
Example 2.3 Package release (package exists in root directory)

Or you want to put the package in the publish root directory, such as:

<  Root>/ setup.  Py __init__.  PY foo.  PY Bar.  PY            

In this case your Setu script will be:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', package_dir ={' foobar ':'}, packages=[' Foobar '],)    

(The empty string also represents the current directory)

Example 2.4 Package release (multi-child package)

If you have multiple sub-packages, they must be explicitly listed in the packages parameter, but any other entities in the package_dir parameter are automatically extended to the child package. (in other words, Distutils does not browse your source tree, but instead looks for __init__.py a file to calculate the directory of the corresponding Python package.) Therefore, if the default hierarchy has a child package:

<  Root>/setup.py foobar/ __init__.  PY foo.  PY Bar.  PY Subfoo/ __init__.  PY blah.  PY                 

Then the corresponding setup script would be:

From distutils.  Import Setup Setup(name=' Foobar ', version=' 1.0 ', packages=[ ' Foobar ',' Foobar.subfoo '],)           
Note: Publishing a package publishes all modules that are in the directory where the package is located. Then we can't just publish some of the modules in the package.

For example, the file structure is as follows:

<  Root>/setup.py sub_package1/ __init__.  PY sub_model1 sub_model2 sub_package2/ __init__.  PY sub_model3           

With Distutils, we cannot publish the package sub_packe1 and sub_package2 not publish the module at the same time sub_model2 .

Pure Python Package Release Setup Scripting example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.