Skip to content

Commit a12cd55

Browse files
authored
devmerge: Correct docstring duplication and enhance CI
This pull request resolves a critical issue where repeatedly processing a Python file with a manual docstring would lead to content duplication. Key changes: - Reworked logic to correctly handle existing docstrings. - Enhanced the CI/CD pipeline to run on the 'dev' branch and added checks to prevent accidental version bumps in feature branches. Closes #7
2 parents 0d806f1 + b70aa9f commit a12cd55

10 files changed

Lines changed: 527 additions & 455 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [master, dev]
66
pull_request_target:
7-
branches: [master]
7+
branches: [master, dev]
88

99
jobs:
1010
test:
@@ -58,6 +58,7 @@ jobs:
5858

5959
report:
6060
name: Report Coverage
61+
if: github.ref == 'refs/heads/master'
6162
runs-on: ubuntu-latest
6263
needs: test
6364
steps:
@@ -77,3 +78,22 @@ jobs:
7778
token: ${{ secrets.CODECOV_TOKEN }}
7879
directory: ./coverage-artifacts/
7980
fail_ci_if_error: false
81+
82+
check-version:
83+
name: Check for accidental version bump
84+
if: github.base_ref == 'dev'
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Checkout repository
88+
uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
92+
- name: Verify that version was not bumped
93+
run: |
94+
if ! git diff --quiet origin/dev HEAD -- pyproject.toml; then
95+
echo "::error::Version in pyproject.toml was changed in a PR to dev."
96+
echo "Version bumping should only happen in a release PR to master."
97+
exit 1
98+
fi
99+
echo "Version check passed for pyproject.toml"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ share/python-wheels/
2727
.installed.cfg
2828
*.egg
2929
MANIFEST
30-
/git_diff.txt
30+
git_diff.txt
31+
temporary/
3132

3233
# PyInstaller
3334
# Usually these files are written by a small stub bootstrap script and should be

CHANGELOG.md

Lines changed: 176 additions & 159 deletions
Large diffs are not rendered by default.

agent_docstrings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Attributes:
88
__version__ (str): Current version of the *agent-docstrings* package.
99
"""
10-
__version__ = "1.3.0"
10+
__version__ = "1.3.1"

agent_docstrings/core.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def process_file(path: Path, verbose: bool = False, beta: bool = False) -> None:
412412
idx += 1
413413
# Check for manual docstring start
414414
if idx < len(body_lines) and body_lines[idx].strip().startswith(('"""', "'''")):
415-
delim = body_lines[idx].strip()
415+
delim_line = body_lines[idx].strip()
416416
# Ensure it's not an existing auto-generated docstring
417417
marker_present = False
418418
for i in range(idx, min(idx + 5, len(body_lines))):
@@ -422,12 +422,29 @@ def process_file(path: Path, verbose: bool = False, beta: bool = False) -> None:
422422
if not marker_present:
423423
# Find end of manual docstring
424424
end_idx = None
425-
for j in range(idx + 1, len(body_lines)):
426-
if body_lines[j].strip() == delim:
427-
end_idx = j
428-
break
425+
manual_inner = []
426+
delim = None
427+
428+
delim_quotes = '"""' if delim_line.startswith('"""') else "'''"
429+
is_single_line = delim_line.endswith(delim_quotes) and delim_line != delim_quotes
430+
431+
if is_single_line:
432+
end_idx = idx
433+
content_part = delim_line[len(delim_quotes):-len(delim_quotes)]
434+
if content_part:
435+
manual_inner = [content_part]
436+
delim = delim_quotes
437+
else:
438+
# Multi-line docstring
439+
delim = delim_line
440+
for j in range(idx + 1, len(body_lines)):
441+
if body_lines[j].strip() == delim:
442+
end_idx = j
443+
break
444+
if end_idx is not None:
445+
manual_inner = body_lines[idx + 1:end_idx]
446+
429447
if end_idx is not None:
430-
manual_inner = body_lines[idx + 1:end_idx]
431448
# Compute auto header content lines with correct offset for merge
432449
# temp_header_lines holds the auto header lines including delimiters
433450
# content_lines length is temp_header_lines minus start/end markers

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "agent-docstrings"
7-
version = "1.3.0"
7+
version = "1.3.1"
88
description = "A command-line tool to auto-generate and update file-level docstrings summarizing classes and functions. Useful for maintaining a high-level overview of your files, especially in projects with code generated or modified by AI assistants."
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
license = { file = "LICENSE" }
@@ -148,7 +148,7 @@ exclude_lines = [
148148
]
149149

150150
[tool.bumpversion]
151-
current_version = "1.3.0"
151+
current_version = "1.3.1"
152152
commit = false
153153
tag = false
154154

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""This is a manual docstring.
2+
It has multiple lines.
3+
The generator should not break it.
4+
"""
5+
6+
class MyClass:
7+
"""A simple example class."""
8+
def my_method(self, arg1: int) -> str:
9+
"""A simple example method."""
10+
return f"Hello {arg1}"

0 commit comments

Comments
 (0)