Skip to content

Commit

Permalink
Make ETSConfig class documentation visible in the API docs (#1688)
Browse files Browse the repository at this point in the history
This PR provides an alternative to #1669. The goal is to make the ETSConfig docstrings available in the API docs, so that a search for "ETSConfig" in the online documentation gives useful results.

To that end, this PR:

* Renames the ETSConfig class to ETSConfigType
* Keeps the ETSConfig instance the same as before (previously, the created instance shadowed the class)
* Updates the main docstrings of ETSConfigType and ETSConfig.

There shouldn't be backwards-compatibility concerns with the rename: the ETSConfig class wasn't available before (since it was shadowed by the instance), and the trick of using type(ETSConfig) to get the class will still work.

I'm deliberately not exposing ETSConfigType in traits.api, since in most circumstances it shouldn't be used directly
  • Loading branch information
mdickinson committed Aug 9, 2022
1 parent 18341f7 commit 9e4664c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/source/traits_api_reference/traits.etsconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
.. automodule:: traits.etsconfig.etsconfig
:no-members:

.. autoclass:: ETSConfigType

.. autodata:: ETSConfig
23 changes: 16 additions & 7 deletions traits/etsconfig/etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ def __init__(self, message="", toolkit=None, *args):
self.args = args


class ETSConfig(object):
class ETSConfigType:
"""
Enthought Tool Suite configuration information.
This class should not use ANY other package in the tool suite so that it
will always work no matter which other packages are present.
Instances of this class record state useful for ETS-using applications,
including the current GUI toolkit in use, and data and home directory
setttings.
Users typically shouldn't make use of this class directly. Instead, use the
module-level :data:`~.ETSConfig` instance of this class, which is shared
between the various ETS packages.
"""
# This class should not use ANY other package in the tool suite so that it
# will always work no matter which other packages are present.

###########################################################################
# 'object' interface.
Expand Down Expand Up @@ -511,7 +517,10 @@ def _initialize_user_data(self):
return usr_dir


# We very purposefully only have one object and do not export the class. We
# could have just made everything class methods, but that always seems a bit
# gorpy, especially with properties etc.
ETSConfig = ETSConfig()
#: This single instance of :class:`~.ETSConfigType` is shared between the
#: various ETS packages, and used to store global state relevant to
#: ETS-using applications.
#:
#: See https://github.com/enthought/traits/discussions/1666 for a discussion
#: of writing tests that depend on :data:`~.ETSConfig` state.
ETSConfig = ETSConfigType()

0 comments on commit 9e4664c

Please sign in to comment.