Skip to content

Commit 783c14e

Browse files
committed
Correctly match import a,b
1 parent e9944e3 commit 783c14e

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__/
66
__pypackages__/
77

88
# Distribution / packaging
9+
.pypirc
910
.Python
1011
/build/
1112
/develop-eggs/

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Fix matching of ``import a, b`` (:issue:`142`)
14+
1115
0.15.1 (2024-04-17)
1216
-------------------
1317
- Fix linking blocks with line numbers (:issue:`137`)

src/sphinx_codeautolink/extension/block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ def link_html(
376376
call_dot_prere = r'(\)</span>\s*<span class="o">\.</span>\s*)'
377377
import_prere = (
378378
r'((<span class="kn">import</span>\s+(<span class="p">\(</span>\s*)?)'
379-
r'|(<span class="p">,</span>\s*))'
379+
r'|(<span class="[op]">,</span>\s*))'
380380
)
381381
from_prere = r'(<span class="kn">from</span>\s+)'
382382

383383
no_dot_postre = r'(?!(<span class="o">\.)|(</a>))'
384-
import_postre = r'(?=($)|(\s+)|(<span class="p">,</span>)|(<span class="p">\)))(?!</a>)'
384+
import_postre = r'(?=($)|(\s+)|(<span class="[op]">,</span>)|(<span class="p">\)))(?!</a>)'
385385
from_postre = r'(?=\s*<span class="kn">import</span>)'
386386

387387

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
json
2+
math
3+
# split
4+
extensions = [
5+
"sphinx.ext.intersphinx",
6+
"sphinx_codeautolink",
7+
]
8+
intersphinx_mapping = {"python": ('https://docs.python.org/3/', None)}
9+
# split
10+
Test project
11+
============
12+
13+
.. code:: python
14+
15+
import json, math
16+
17+
.. automodule:: test_project

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ commands_pre =
103103
commands =
104104
python -m build
105105
twine check --strict dist/*
106-
twine upload dist/*
106+
twine upload dist/* --config-file .pypirc
107107
commands_post =
108108
lin,mac: rm -r dist
109109
win: cmd /c rmdir /s /q dist

0 commit comments

Comments
 (0)