Skip to content

Commit 8eb3330

Browse files
committed
Document the two lifecycles of Configuration
1 parent 96ea512 commit 8eb3330

File tree

1 file changed

+59
-24
lines changed

1 file changed

+59
-24
lines changed

docs/html/development/architecture/configuration-files.rst

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,72 @@ Both of these operations utilize functionality provided the ``Configuration``
3636
object, which encapsulates all the logic for handling configuration files and
3737
provides APIs for the same.
3838

39-
The remainder of this section documents the ``Configuration`` class and
40-
other implementation details of the ``configuration`` module.
39+
The remainder of this section documents the ``Configuration`` class, and
40+
discusses potential future refactoring ideas.
4141

4242

43+
.. _configuration-class:
44+
45+
``Configuration`` class
46+
=======================
47+
48+
``Configuration`` loads configuration values from sources in the local
49+
environment: a combination of config files and environment variables.
50+
51+
It can be used in two "modes", for reading all the values from the local
52+
environment and for manipulating a single config file. It differentiates
53+
between these two modes using the ``load_only`` attribute.
54+
55+
The ``isolated`` attribute manipulates which sources are used when loading the
56+
configuration. If ``isolated`` is ``True``, user-specific config files and
57+
environment variables are not used.
58+
59+
Reading from local environment
60+
------------------------------
61+
62+
When using a ``Configuration`` object to read from all sources in the local
63+
environment, the ``load_only`` attribute is ``None``. The API provided for this
64+
use case is ``Configuration.load`` and ``Configuration.items``.
65+
66+
``Configuration.load`` does all the interactions with the environment to load
67+
all the configuration into objects in memory. ``Configuration.items``
68+
provides key-value pairs (like ``dict.items``) from the loaded-in-memory
69+
information, handling all of the override ordering logic.
70+
71+
At the time of writing, the only part of the codebase that uses
72+
``Configuration`` like this is the ``ConfigOptionParser`` in the command line parsing
73+
logic.
74+
75+
Manipulating a single config file
76+
---------------------------------
77+
78+
When using a ``Configuration`` object to read from a single config file, the
79+
``load_only`` attribute would be non-None, and would represent the
80+
:ref:`kind <config-kinds>` of the config file.
81+
82+
This use case uses the methods discussed in the previous section
83+
(``Configuration.load`` and ``Configuration.items``) and a few more that
84+
are more specific to this use case.
85+
86+
``Configuration.get_file_to_edit`` provides the "highest priority" file, for
87+
the :ref:`kind <config-kinds>` of config file specified by ``load_only``.
88+
The rest of this document will refer to this file as the "``load_only`` file".
89+
90+
``Configuration.set_value`` provides a way to add/change a single key-value pair
91+
in the ``load_only`` file. ``Configuration.unset_value`` removes a single
92+
key-value pair in the ``load_only`` file. ``Configuration.get_value`` gets the
93+
value of the given key from the loaded configuration. ``Configuration.save`` is
94+
used save the state ``load_only`` file, back into the local environment.
95+
4396
.. _config-kinds:
4497

4598
kinds
4699
=====
47100

48-
- used to represent "where" a configuration value comes from
49-
(eg. environment variables, site-specific configuration file,
50-
global configuration file)
51-
52-
.. _configuration-class:
53-
54-
Configuration
55-
============
56-
57-
- TODO: API & usage - ``Command``, when processing CLI options.
58-
- __init__()
59-
- load()
60-
- items()
61-
- TODO: API & usage - ``pip config``, when loading / manipulating config files.
62-
- __init__()
63-
- get_file_to_edit()
64-
- get_value()
65-
- set_value()
66-
- unset_value()
67-
- save()
68-
- TODO: nuances of ``load_only`` and ``get_file_to_edit``
69-
- TODO: nuances of ``isolated``
101+
This is an enumeration that provides values to represent a "source" for
102+
configuration. This includes environment variables and various types of
103+
configuration files (global, site-specific, user_specific, specified via
104+
``PIP_CONFIG_FILE``).
70105

71106
Future Refactoring Ideas
72107
========================

0 commit comments

Comments
 (0)