Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `python setup.py check` actually do?

What exactly does python setup.py check actually do?

like image 816
Dave Avatar asked May 19 '15 14:05

Dave


People also ask

What does python setup py do?

setup.py is a python file, the presence of which is an indication that the module/package you are about to install has likely been packaged and distributed with Distutils, which is the standard for distributing Python Modules. This allows you to easily install Python packages.

Why do you need a setup py?

Use of Setup.py It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on. Secondly, it serves as the command line interface via which packaging commands may be executed.

How do I check python setup py?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How does pip use setup py?

If you use setup.py , you have to visit the library's website, figure out where to download it, extract the file, run setup.py ... In contrast, pip will automatically search the Python Package Index (PyPi) to see if the package exists there, and will automatically download, extract, and install the package for you.


1 Answers

First stop, the distutils package documentation:

The check command performs some tests on the meta-data of a package. For example, it verifies that all required meta-data are provided as the arguments passed to the setup() function.

So it tests if you have filled in your metadata correctly; see it as a quality control step when creating a Python package.

Next, we can check if the command line offers any help:

$ python setup.py --help-commands | grep check
  check             perform some checks on the package
$ python setup.py check --help
# ...
Options for 'check' command:
  --metadata (-m)          Verify meta-data
  --restructuredtext (-r)  Checks if long string meta-data syntax are
                           reStructuredText-compliant
  --strict (-s)            Will exit with an error if a check fails

So we can check for metadata and validate the long description as reStructuredText. The latter requires that you have docutils installed:

$ python setup.py check -rs
running check
error: The docutils package is needed.

If you do have it installed and there are no problems, the script just runs and exits with no messages:

$ python setup.py check -r
running check

but if required metadata is missing you get warning messages:

$ python setup.py check -r
running check
warning: check: missing required meta-data: url

warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

which becomes an error if you have the -s flag given:

$ python setup.py check -rs
running check
warning: check: missing required meta-data: url

warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

error: Please correct your package.

By default, -m is enabled, -r and -s are disabled.

Also see the command source code.

like image 106
Martijn Pieters Avatar answered Sep 19 '22 12:09

Martijn Pieters