5
5
Sphinx-specific functionality.
6
6
"""
7
7
#
8
- # Copyright (c) 2020 Dominic Davis-Foster <[email protected] >
8
+ # Copyright © 2020 Dominic Davis-Foster <[email protected] >
9
9
#
10
10
# Permission is hereby granted, free of charge, to any person obtaining a copy
11
11
# of this software and associated documentation files (the "Software"), to deal
34
34
# 3rd party
35
35
from sphinx .application import Sphinx
36
36
from sphinx .config import Config
37
- from sphinx .environment import BuildEnvironment
38
37
39
38
# 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
42
40
43
- __all__ = ["sphinx_seed_intersphinx_mapping" , "sphinx_purge_cache" , " setup" ]
41
+ __all__ = ["sphinx_seed_intersphinx_mapping" , "setup" ]
44
42
45
43
46
44
def sphinx_seed_intersphinx_mapping (app : Sphinx , config : Config ) -> None :
47
45
"""
48
46
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.
50
48
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.
53
56
54
57
:param app:
55
58
:param config:
@@ -61,6 +64,12 @@ def sphinx_seed_intersphinx_mapping(app: Sphinx, config: Config) -> None:
61
64
if config .pkg_requirements_source == "requirements" :
62
65
for name , (uri , inv ) in seed_intersphinx_mapping (repo_root ).items ():
63
66
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
+
64
73
else : # pragma: no cover
65
74
raise NotImplementedError (f"Unsupported requirements source '{ config .pkg_requirements_source } '" )
66
75
@@ -81,7 +90,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
81
90
# this package
82
91
from seed_intersphinx_mapping import __version__
83
92
84
- # Currently, only "requirements"
93
+ # Currently, only "requirements" or a list of directories containing requirements.txt files relative to the repository root,
85
94
app .add_config_value ("pkg_requirements_source" , "requirements" , "html" )
86
95
87
96
# Location of repository directory relative to documentation source directory
0 commit comments