How Lino applications use setup.py¶
This document describes our trick for keeping the metadata about a Python package in a single place. It does not depend on Lino and we recommend it for any Python project which contains a package.
For example the version number. You need it of course in the
setup.py, but there are quite some projects that want to show somehow
their version. So they need it at runtime as well. And that number can change
quickly and can be critical. You don't want to store it in two different places.
Is there a way to have setup information both in a central place and* accessible at runtime?
It is an old problem, and e.g. Single-sourcing the package version describes a series of answers.
To solve this problem, we store the setup information in a separate file, which
we usually name
setup_info.py and which we load from both our
setup.py and our packages's main
__init__.py file. The
setup.py loads it using the
exec() function while the packages's
__init__.py file can simply import it.
That's why the
setup.py of a package "xxyyzz" contains just this:
from setuptools import setup fn = 'xxyyzz/setup_info.py') with open(fn, "rb") as fd: exec(compile(fd.read(), fn, 'exec')) if __name__ == '__main__': setup(**SETUP_INFO)
__init__.py file of the main module contains this:
from os.path import join, dirname from setup_info import SETUP_INFO __version__ = SETUP_INFO.get('version')
>>> from lino import SETUP_INFO >>> print(SETUP_INFO['description']) A framework for writing desktop-like sustainably free web applications using Django and ExtJS or React
>>> from lino_xl import SETUP_INFO >>> print(SETUP_INFO['description']) The Lino Extensions Library
setup() function has a lot of keyword parameters, which are documented
A terse plain-text description of the package. Usually a single sentence and no period at the end.
A longer description to be published on PyPI.
May contain reStructuredText formatting, but no Sphinx-specific additions.
How to suggest changes to a README file¶
We assume that you have installed a development environment as explained in Installing a Lino developer environment.
setup_info.py file of your project and find the
Edit its content.
inv bd in the root directory of the project. This will ask you:
Overwrite /path/to/my/project/README.rst [Y,n]?
README.rst file and check that it contains your changes.