|
1 | 1 | """Provider for collecting doc files as libraries.""" |
| 2 | +SphinxDocsFileset = provider( |
| 3 | + doc = "A set of doc files sharing the same path manipulation.", |
| 4 | + fields = { |
| 5 | + "files": """ |
| 6 | +:type: tuple[File] |
| 7 | +
|
| 8 | +The documentation files. A tuple because depset elements must be immutable. |
| 9 | +""", |
| 10 | + "prefix": """ |
| 11 | +:type: str |
| 12 | +
|
| 13 | +Prefix to prepend to file paths in `files`. Added after `strip_prefix` is removed. |
| 14 | +""", |
| 15 | + "strip_prefix": """ |
| 16 | +:type: str |
| 17 | +
|
| 18 | +Prefix to remove from file paths in `files`. Removed before `prefix` is prepended. |
| 19 | +""", |
| 20 | + }, |
| 21 | +) |
2 | 22 |
|
3 | 23 | SphinxDocsLibraryInfo = provider( |
4 | 24 | doc = "Information about a collection of doc files.", |
5 | 25 | fields = { |
6 | 26 | "files": """ |
7 | | -:type: depset[File] |
| 27 | +:type: list[File] |
8 | 28 |
|
9 | | -The documentation files for the library. |
| 29 | +The direct documentation files for the library. |
10 | 30 | """, |
11 | 31 | "prefix": """ |
12 | 32 | :type: str |
13 | 33 |
|
14 | | -Prefix to prepend to file paths in `files`. It is added after `strip_prefix` |
15 | | -is removed. |
| 34 | +Prefix to prepend to file paths in `files`. Added after `strip_prefix` is removed. |
16 | 35 | """, |
17 | 36 | "strip_prefix": """ |
18 | 37 | :type: str |
19 | 38 |
|
20 | | -Prefix to remove from file paths in `files`. It is removed before `prefix` |
21 | | -is prepended. |
| 39 | +Prefix to remove from file paths in `files`. Removed before `prefix` is prepended. |
22 | 40 | """, |
23 | 41 | "transitive": """ |
24 | | -:type: depset[struct] |
| 42 | +:type: depset[SphinxDocsFileset] |
| 43 | +
|
| 44 | +This library's own files and those of its deps. |
25 | 45 |
|
26 | | -Depset of transitive library information. Each entry in the depset is a struct |
27 | | -with fields matching the fields of this provider. |
| 46 | +The only field consumers read, so a rule must include its own |
| 47 | +{obj}`SphinxDocsFileset` here or its files are silently ignored. Use |
| 48 | +{obj}`create_sphinx_docs_library_info` to construct the provider correctly. |
28 | 49 | """, |
29 | 50 | }, |
30 | 51 | ) |
| 52 | + |
| 53 | +def create_sphinx_docs_library_info(*, files = [], prefix = "", strip_prefix = "", deps = []): |
| 54 | + """Creates a {obj}`SphinxDocsLibraryInfo`, populating the `transitive` field. |
| 55 | +
|
| 56 | + Args: |
| 57 | + files: {type}`list[File]` the direct doc files. |
| 58 | + prefix: {type}`str` prefix to prepend to `files` paths. Not applied to `deps`. |
| 59 | + strip_prefix: {type}`str` prefix to remove from `files` paths. Not applied to `deps`. |
| 60 | + deps: {type}`list[Target]` targets with {obj}`SphinxDocsLibraryInfo` whose |
| 61 | + files are included as-is. |
| 62 | +
|
| 63 | + Returns: |
| 64 | + {type}`SphinxDocsLibraryInfo` |
| 65 | + """ |
| 66 | + direct = [] |
| 67 | + if files: |
| 68 | + direct.append(SphinxDocsFileset( |
| 69 | + files = tuple(files), |
| 70 | + prefix = prefix, |
| 71 | + strip_prefix = strip_prefix, |
| 72 | + )) |
| 73 | + |
| 74 | + return SphinxDocsLibraryInfo( |
| 75 | + files = files, |
| 76 | + prefix = prefix, |
| 77 | + strip_prefix = strip_prefix, |
| 78 | + transitive = depset( |
| 79 | + direct = direct, |
| 80 | + transitive = [d[SphinxDocsLibraryInfo].transitive for d in deps], |
| 81 | + ), |
| 82 | + ) |
0 commit comments