Skip to content

Commit 620a06b

Browse files
committed
updates
1 parent d7b55d4 commit 620a06b

6 files changed

Lines changed: 498 additions & 11 deletions

File tree

docs/source/components/configuration.rst

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ Configures how **Sphinx-CodeLinks** discovers and processes source files within
178178
exclude = []
179179
include = []
180180
gitignore = true
181+
follow_links = false
181182
comment_type = "cpp"
182183
183184
**Configuration fields:**
184185

185186
- ``src_dir`` - Root directory for source file discovery (relative to Sphinx project root or the directory where the TOML config file is located if given)
186187
- ``exclude`` - List of glob patterns to exclude from processing
187188
- ``include`` - List of glob patterns to include (if empty, includes all files)
188-
- ``gitignore`` - Whether to respect ``.gitignore`` rules when discovering files (Nested .gitignore is NOT supported yet)
189-
- ``comment_type`` - Comment style for the programming language ("cpp" and "python" are currently supported)
189+
- ``gitignore`` - Whether to respect ``.gitignore``, ``.ignore``, and related ignore files when discovering files
190+
- ``follow_links`` - Whether to follow symbolic links during file discovery
191+
- ``comment_type`` - Comment style for the programming language
190192

191193
.. _`source_dir`:
192194

@@ -251,7 +253,9 @@ Defines a list of glob patterns for files to explicitly include in discovery. Wh
251253
"include/**/*.hpp"
252254
]
253255
254-
**Priority:** The ``include`` option has the highest priority and overrides both ``exclude`` and ``gitignore`` settings.
256+
**Priority:** When ``include`` patterns are specified, only files matching those patterns
257+
are considered (this overrides ``gitignore`` exclusions for matched files).
258+
``exclude`` patterns are then applied to remove files from that set.
255259

256260
**Common inclusion patterns:**
257261

@@ -317,7 +321,9 @@ Specifies the comment syntax style used in the source code files. This determine
317321
gitignore
318322
^^^^^^^^^
319323

320-
Controls whether to respect ``.gitignore`` files when discovering source files. When enabled, files and directories listed in ``.gitignore`` will be automatically excluded from processing.
324+
Controls whether to respect ignore files when discovering source files.
325+
When enabled, files and directories matched by ignore rules will be automatically
326+
excluded from processing.
321327

322328
**Type:** ``bool``
323329
**Default:** ``true``
@@ -329,10 +335,34 @@ Controls whether to respect ``.gitignore`` files when discovering source files.
329335
330336
**Behavior:**
331337

332-
- ``true`` - Respect ``.gitignore`` rules (recommended)
333-
- ``false`` - Ignore ``.gitignore`` files and process all matching files
338+
When set to ``true`` (recommended), the following ignore sources are respected:
334339

335-
.. important:: **Current Limitation:** This option only supports the root-level ``.gitignore`` file. Nested ``.gitignore`` files in subdirectories or parent directories are not currently processed.
340+
- ``.gitignore`` files (including nested ``.gitignore`` files in subdirectories)
341+
- ``.ignore`` files (same syntax as ``.gitignore``, useful for non-git projects)
342+
- ``.git/info/exclude``
343+
- Global gitignore (e.g. ``~/.config/git/ignore``)
344+
- Parent directory ignore files
345+
346+
When set to ``false``, all ignore files are disregarded and every matching file is processed.
347+
348+
follow_links
349+
^^^^^^^^^^^^
350+
351+
Controls whether symbolic links are followed during file discovery.
352+
When disabled, symbolic links to directories are not traversed.
353+
354+
**Type:** ``bool``
355+
**Default:** ``false``
356+
357+
.. code-block:: toml
358+
359+
[codelinks.projects.my_project.source_discover]
360+
follow_links = true
361+
362+
**Behavior:**
363+
364+
- ``false`` - Symbolic links to directories are skipped (default, safer)
365+
- ``true`` - Symbolic links are followed, discovering files inside linked directories
336366

337367
For more information about the usage examples, see :ref:`source discover <discover>`.
338368

@@ -355,6 +385,7 @@ Configures how **Sphinx-CodeLinks** analyse source files to extract markers from
355385
exclude = []
356386
include = []
357387
gitignore = true
388+
follow_links = false
358389
comment_type = "cpp"
359390
360391
[codelinks.projects.my_project.analyse]

docs/source/components/discover.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Usage Examples
2626
include = []
2727
exclude = ["src/legacy/**", "**/*_test.cpp"]
2828
gitignore = true
29+
follow_links = false
2930
comment_type = "cpp"
3031
3132
**Python Project:**

docs/source/development/roadmap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Source Code Parsing
1919

2020
- Introduce a configurable option to strip leading characters (e.g., ``*``) from commented RST blocks.
2121
- Enrich tagged scopes with additional metadata.
22-
- Enhance ``.gitignore`` handling to support nested ``.gitignore`` files.
22+
- ✅ Nested ``.gitignore`` files are now supported (implemented via ``ignore-python``).
2323

2424
Defining Needs in Source Code
2525
-----------------------------

src/sphinx_codelinks/source_discover/source_discover.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ def _discover(self) -> list[Path]:
5252
if not src_dir.is_dir():
5353
return []
5454

55+
gitignore = self.src_discover_config.gitignore
56+
5557
builder = WalkBuilder(str(src_dir))
58+
# Replicate the Rust ignore crate's standard_filters(gitignore)
59+
# followed by hidden(false), matching ubc_codelinks behaviour.
60+
builder.ignore(gitignore)
61+
builder.parents(gitignore)
62+
builder.git_ignore(gitignore)
63+
builder.git_global(gitignore)
64+
builder.git_exclude(gitignore)
5665
builder.hidden(False)
57-
builder.git_ignore(self.src_discover_config.gitignore)
58-
builder.git_global(False)
59-
builder.git_exclude(False)
6066
builder.follow_links(self.src_discover_config.follow_links)
6167

6268
override_builder = self._build_overrides()

0 commit comments

Comments
 (0)