user1859451 user1859451 - 1 year ago 158
Python Question

what does "__requires__" mean in python?

I am newbie in python.

Could anybody answer what does

means in the following code?
Why would they put
__requires__ = 'flower==0.4.0'
in the beginning of the file?


__requires__ = 'flower==0.4.0'
import sys
from pkg_resources import load_entry_point

load_entry_point('flower==0.4.0', 'console_scripts', 'flower')()

Answer Source

The __requires__ line is part of a generated console script. It has no meaning to Python itself, only the setuptools library itself uses this information.

Console scripts are python scripts defined in a python package metadata, and setuptools installs wrapper script files to let you run them as command line scripts. The flower file installed in your virtualenv is such a script, defined by the flower package file.

The pkg_resources module imported in the wrapper script inspects the value of __requires__ in the main script to make sure the correct version of the library is available and loaded before the load_entry_point function (or any other pkg_resources function) is run. It'll not install the version specified, it is assumed that that version is already installed on your system. It's purpose is to avoid loading incorrect, incompatible resources when the script runs and loads dependencies.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download