sphinx-codelinks 2.0.1__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/PKG-INFO +3 -3
  2. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/pyproject.toml +3 -3
  3. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/__init__.py +1 -1
  4. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/analyse.py +32 -22
  5. sphinx_codelinks-2.1.0/src/sphinx_codelinks/analyse/entity.py +1610 -0
  6. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/models.py +23 -9
  7. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/utils.py +265 -192
  8. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/needextend_write.py +7 -0
  9. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/directives/src_trace.py +226 -67
  10. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/source_tracing.py +4 -2
  11. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/LICENSE +0 -0
  12. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/README.md +0 -0
  13. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/__init__.py +0 -0
  14. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/multiline_parser.py +0 -0
  15. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/oneline_parser.py +0 -0
  16. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/preproc/__init__.py +0 -0
  17. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/preproc/compile_db.py +0 -0
  18. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/preproc/libclang_parser.py +0 -0
  19. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/preproc/loader.py +0 -0
  20. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/projects.py +0 -0
  21. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/analyse/references.py +0 -0
  22. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/cmd.py +0 -0
  23. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/config.py +0 -0
  24. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/logger.py +0 -0
  25. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/py.typed +0 -0
  26. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/source_discover/__init__.py +0 -0
  27. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/source_discover/config.py +0 -0
  28. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/source_discover/source_discover.py +0 -0
  29. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/__init__.py +0 -0
  30. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/debug.py +0 -0
  31. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/directives/__init__.py +0 -0
  32. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/html_wrapper.py +0 -0
  33. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/need_id_refs.py +0 -0
  34. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/project_analysis.py +0 -0
  35. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/rediscovery.py +0 -0
  36. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/string_links.py +0 -0
  37. {sphinx_codelinks-2.0.1 → sphinx_codelinks-2.1.0}/src/sphinx_codelinks/sphinx_extension/ub_sct.css +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-codelinks
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: Fast Source Code Traceability for Sphinx-Needs
5
5
  Author-email: team useblocks <info@useblocks.com>
6
6
  Maintainer-email: Marco Heinemann <marco.heinemann@useblocks.com>, Jui-Wen Chen <jui-wen.chen@useblocks.com>
@@ -13,8 +13,8 @@ Requires-Dist: ignore-python>=0.3.3
13
13
  Requires-Dist: typer>=0.16.0
14
14
  Requires-Dist: jsonschema
15
15
  Requires-Dist: sphinx>=7.4,<10
16
- Requires-Dist: sphinx-needs>=9.1.0,<10
17
- Requires-Dist: ub-project>=1.1.0,<2
16
+ Requires-Dist: sphinx-needs>=9.2.0,<10
17
+ Requires-Dist: ub-project>=1.2.0,<2
18
18
  Requires-Dist: jinja2
19
19
  Requires-Dist: pygments
20
20
  Requires-Dist: docutils>=0.21
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sphinx-codelinks"
3
- version = "2.0.1"
3
+ version = "2.1.0"
4
4
  description = "Fast Source Code Traceability for Sphinx-Needs"
5
5
  authors = [{ name = "team useblocks", email = "info@useblocks.com" }]
6
6
  maintainers = [
@@ -28,8 +28,8 @@ dependencies = [
28
28
  # edge. uv never validates a specifier it resolves through `workspace = true` (uv#9811),
29
29
  # so the floor is the only statement of what was actually tested, and the cap is what
30
30
  # stops a future major being co-installed with a wheel written against this one.
31
- "sphinx-needs>=9.1.0,<10",
32
- "ub-project>=1.1.0,<2",
31
+ "sphinx-needs>=9.2.0,<10",
32
+ "ub-project>=1.2.0,<2",
33
33
  "jinja2",
34
34
  "pygments",
35
35
  "docutils>=0.21", # the `typing` group's series
@@ -2,7 +2,7 @@
2
2
 
3
3
  from sphinx_codelinks.sphinx_extension.source_tracing import setup
4
4
 
5
- __version__ = "2.0.1"
5
+ __version__ = "2.1.0"
6
6
 
7
7
  __all__ = [
8
8
  "__version__",
@@ -9,6 +9,7 @@ from tree_sitter import Node as TreeSitterNode
9
9
  from tree_sitter import Parser, Query
10
10
 
11
11
  from sphinx_codelinks.analyse import multiline_parser, utils
12
+ from sphinx_codelinks.analyse.entity import CodeScope, code_scope, scope_language
12
13
  from sphinx_codelinks.analyse.models import (
13
14
  MarkedContentType,
14
15
  MultilineNeed,
@@ -420,11 +421,13 @@ class SourceAnalyse:
420
421
  src_comment: SourceComment,
421
422
  first_row: int | None = None,
422
423
  first_column: int | None = None,
424
+ *,
425
+ scope: CodeScope | None = None,
423
426
  ) -> list[NeedIdRefs]:
424
427
  """Extract need-ids-refs from a comment.
425
428
 
426
429
  ``text`` starts at ``first_row`` and ``first_column`` (by default the
427
- comment's own row and column).
430
+ comment's own row and column). ``scope`` is the named ``tagged_scope``.
428
431
  """
429
432
  if first_row is None:
430
433
  first_row = src_comment.node.start_point.row
@@ -468,6 +471,7 @@ class SourceAnalyse:
468
471
  tagged_scope,
469
472
  need_ids,
470
473
  marker,
474
+ scope=scope,
471
475
  )
472
476
  )
473
477
  return anchors
@@ -578,11 +582,13 @@ class SourceAnalyse:
578
582
  oneline_comment_style: OneLineCommentStyle,
579
583
  first_row: int | None = None,
580
584
  first_column: int | None = None,
585
+ *,
586
+ scope: CodeScope | None = None,
581
587
  ) -> list[OneLineNeed]:
582
588
  """Extract the one-line needs of a comment.
583
589
 
584
590
  ``text`` starts at ``first_row`` and ``first_column`` (by default the
585
- comment's own row and column).
591
+ comment's own row and column). ``scope`` is the named ``tagged_scope``.
586
592
  """
587
593
  if first_row is None:
588
594
  first_row = src_comment.node.start_point.row
@@ -626,6 +632,7 @@ class SourceAnalyse:
626
632
  src_comment,
627
633
  tagged_scope,
628
634
  resolved, # int arguments were deleted # ty: ignore[invalid-argument-type]
635
+ scope=scope,
629
636
  )
630
637
  )
631
638
  return oneline_needs
@@ -694,11 +701,7 @@ class SourceAnalyse:
694
701
  ),
695
702
  run.comments[0],
696
703
  )
697
- tagged_scope: TreeSitterNode | None = None
698
- if not getattr(src_comment.node, "is_libclang", False):
699
- tagged_scope = utils.find_associated_scope(
700
- src_comment.node, self.analyse_config.comment_type
701
- )
704
+ tagged_scope, scope = self._associate(src_comment, filepath)
702
705
  lineno = block.open_row + 1
703
706
  remote_url = self.git_remote_url
704
707
  if self.git_remote_url and self.git_commit_rev:
@@ -718,15 +721,6 @@ class SourceAnalyse:
718
721
  if block.content_start is not None
719
722
  else None
720
723
  )
721
- scope = (
722
- {
723
- "kind": tagged_scope.type,
724
- "start": tagged_scope.start_point.row + 1,
725
- "end": tagged_scope.end_point.row + 1,
726
- }
727
- if tagged_scope is not None
728
- else None
729
- )
730
724
  source: dict[str, Any] = {
731
725
  "project": self.name,
732
726
  "path": _relative_posix(filepath, self.project_path),
@@ -747,6 +741,25 @@ class SourceAnalyse:
747
741
  block.need,
748
742
  block.markup,
749
743
  source,
744
+ scope=scope,
745
+ )
746
+
747
+ def _associate(
748
+ self, src_comment: SourceComment, filepath: Path
749
+ ) -> tuple[TreeSitterNode | None, CodeScope | None]:
750
+ """The entity a comment of ``filepath`` is attached to: its node and its
751
+ ``scope`` object.
752
+
753
+ A libclang comment has no tree-sitter node, so it is attached to nothing.
754
+ """
755
+ if getattr(src_comment.node, "is_libclang", False):
756
+ return None, None
757
+ comment_type = self.analyse_config.comment_type
758
+ association = utils.associate(src_comment.node, comment_type)
759
+ if association is None or not association.node.text:
760
+ return None, None
761
+ return association.node, code_scope(
762
+ association, comment_type, scope_language(comment_type, filepath)
750
763
  )
751
764
 
752
765
  def extract_marked_content(self) -> None:
@@ -761,12 +774,7 @@ class SourceAnalyse:
761
774
  )
762
775
  if not filepath:
763
776
  continue
764
- if getattr(src_comment.node, "is_libclang", False):
765
- tagged_scope: TreeSitterNode | None = None
766
- else:
767
- tagged_scope = utils.find_associated_scope(
768
- src_comment.node, self.analyse_config.comment_type
769
- )
777
+ tagged_scope, scope = self._associate(src_comment, filepath)
770
778
  for text, first_row, first_column in _scanned_texts(
771
779
  src_comment, claimed.get(id(src_comment))
772
780
  ):
@@ -779,6 +787,7 @@ class SourceAnalyse:
779
787
  src_comment,
780
788
  first_row,
781
789
  first_column,
790
+ scope=scope,
782
791
  )
783
792
  )
784
793
  if self.analyse_config.get_oneline_needs:
@@ -791,6 +800,7 @@ class SourceAnalyse:
791
800
  self.analyse_config.oneline_comment_style,
792
801
  first_row,
793
802
  first_column,
803
+ scope=scope,
794
804
  )
795
805
  )
796
806