Skip to content

Commit 6a89e2b

Browse files
committed
Allow searching for requirements in multiple directories.
1 parent 108a867 commit 6a89e2b

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

seed_intersphinx_mapping/extension.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Sphinx-specific functionality.
66
"""
77
#
8-
# Copyright (c) 2020 Dominic Davis-Foster <[email protected]>
8+
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
99
#
1010
# Permission is hereby granted, free of charge, to any person obtaining a copy
1111
# of this software and associated documentation files (the "Software"), to deal
@@ -34,22 +34,25 @@
3434
# 3rd party
3535
from sphinx.application import Sphinx
3636
from sphinx.config import Config
37-
from sphinx.environment import BuildEnvironment
3837

3938
# this package
40-
from seed_intersphinx_mapping.cache import cache
41-
from seed_intersphinx_mapping.core import get_sphinx_doc_url, seed_intersphinx_mapping
39+
from seed_intersphinx_mapping.core import seed_intersphinx_mapping
4240

43-
__all__ = ["sphinx_seed_intersphinx_mapping", "sphinx_purge_cache", "setup"]
41+
__all__ = ["sphinx_seed_intersphinx_mapping", "setup"]
4442

4543

4644
def sphinx_seed_intersphinx_mapping(app: Sphinx, config: Config) -> None:
4745
"""
4846
Updates the ``intersphinx_mapping`` dictionary in the sphinx configuration
49-
to include the documentation for the projects listed in the ``requirements.txt`` file.
47+
to include the documentation for the project's requirements.
5048
51-
The ``requirements.txt`` file is found in the directory given by the ``repository_root`` option
52-
given in the Sphinx configuration file.
49+
If :confval:`pkg_requirements_source` is a list, it is taken to be a list of directories
50+
in which to search for ``requirements.txt`` files. Any files found will be used to compile
51+
the list of requirements.
52+
53+
Otherwise, if :confval:`pkg_requirements_source` is the string ``requirements``,
54+
the list of requirements will be determined from the ``requirements.txt`` file
55+
in the directory given by the :confval:`repository_root` option.
5356
5457
:param app:
5558
:param config:
@@ -61,6 +64,12 @@ def sphinx_seed_intersphinx_mapping(app: Sphinx, config: Config) -> None:
6164
if config.pkg_requirements_source == "requirements":
6265
for name, (uri, inv) in seed_intersphinx_mapping(repo_root).items():
6366
config.intersphinx_mapping[name] = (name, (uri, (inv, )))
67+
68+
elif isinstance(config.pkg_requirements_source, list):
69+
for directory in config.pkg_requirements_source:
70+
for name, (uri, inv) in seed_intersphinx_mapping(repo_root / directory).items():
71+
config.intersphinx_mapping[name] = (name, (uri, (inv, )))
72+
6473
else: # pragma: no cover
6574
raise NotImplementedError(f"Unsupported requirements source '{config.pkg_requirements_source}'")
6675

@@ -81,7 +90,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
8190
# this package
8291
from seed_intersphinx_mapping import __version__
8392

84-
# Currently, only "requirements"
93+
# Currently, only "requirements" or a list of directories containing requirements.txt files relative to the repository root,
8594
app.add_config_value("pkg_requirements_source", "requirements", "html")
8695

8796
# Location of repository directory relative to documentation source directory

0 commit comments

Comments
 (0)