From 65ba4e8608b1d53d7e0b602d2aaad5d005c95cbd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:07:39 -0400 Subject: [PATCH 01/14] Sanitize MD and initiate addition of tests dependabot sends PRs with `[]()` in the title eg [gh-actions](deps): Bump actions/setup-python from 4 to 5 making it not legitimate markdown - [[gh-actions](deps): Bump actions/setup-python from 4 to 5](https://github.com/dandi/zarr_checksum/pull/42) (253 days) so with this change we just remove any of the [] symbols, making it a legit - [gh-actions(deps): Bump actions/setup-python from 4 to 5](https://github.com/dandi/zarr_checksum/pull/42) (253 days) --- setup.cfg | 6 ++++++ src/solidation/__main__.py | 7 ++++++- src/solidation/tests/__init__.py | 0 src/solidation/tests/test_main.py | 5 +++++ tox.ini | 7 ++++++- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/solidation/tests/__init__.py create mode 100644 src/solidation/tests/test_main.py diff --git a/setup.cfg b/setup.cfg index d5ca746..fec5c85 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,12 @@ install_requires = PyGithub ~= 2.0 ruamel.yaml ~= 0.15 +[options.extras_require] +test = + mypy + pytest + pytest-cov + [options.packages.find] where = src diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 37e550e..6bf0e52 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -250,7 +250,7 @@ def to_markdown(self) -> str: if user is None: user = i.user.login s += ( - f"- [{i.title}]({i.html_url}) by {user}" + f"- [{sanitize_md(i.title)}]({i.html_url}) by {user}" f" [{i.repository.full_name}]\n" ) @@ -437,6 +437,11 @@ def ensure_aware(dt: datetime) -> datetime: return dt.replace(tzinfo=timezone.utc) if dt.tzinfo is None else dt +def sanitize_md(s: str) -> str: + # Remove `[]` symbols to ensure correct markdown in the references + return re.sub(r'[\[\]]', '', s) + + @click.command() @click.option( "-c", diff --git a/src/solidation/tests/__init__.py b/src/solidation/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/solidation/tests/test_main.py b/src/solidation/tests/test_main.py new file mode 100644 index 0000000..59dd5cc --- /dev/null +++ b/src/solidation/tests/test_main.py @@ -0,0 +1,5 @@ +from ..__main__ import sanitize_md + + +def test_sanitize_md() -> None: + assert sanitize_md("[gh-actions](deps): Bump") == "gh-actions(deps): Bump" diff --git a/tox.ini b/tox.ini index 740b591..a49816e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,13 @@ [tox] -envlist = lint,typing +envlist = lint,typing,py3 isolated_build = True minversion = 3.3.0 +[testenv] +extras = test +commands = + python -m pytest -v {posargs} src + [testenv:lint] skip_install = True deps = From 9ace6e32721a4c0e5642859e9b9a2dc8572a91af Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:49:40 -0400 Subject: [PATCH 02/14] no mypy for test --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index fec5c85..e175c48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,7 +43,6 @@ install_requires = [options.extras_require] test = - mypy pytest pytest-cov From b3ccc84a158e59ccae088c571af182a9f6643930 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:49:49 -0400 Subject: [PATCH 03/14] Escape, not remove, [] and \ --- src/solidation/__main__.py | 2 +- src/solidation/tests/test_main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 6bf0e52..74c9e76 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -439,7 +439,7 @@ def ensure_aware(dt: datetime) -> datetime: def sanitize_md(s: str) -> str: # Remove `[]` symbols to ensure correct markdown in the references - return re.sub(r'[\[\]]', '', s) + return re.sub(r'([\\\[\]])', r'\\\1', s) @click.command() diff --git a/src/solidation/tests/test_main.py b/src/solidation/tests/test_main.py index 59dd5cc..de1d589 100644 --- a/src/solidation/tests/test_main.py +++ b/src/solidation/tests/test_main.py @@ -2,4 +2,4 @@ def test_sanitize_md() -> None: - assert sanitize_md("[gh-actions](deps): Bump") == "gh-actions(deps): Bump" + assert sanitize_md(r"[gh-actions](deps): Fix \n") == r"\[gh-actions\](deps): Fix \\n" From 8af3febbbecef1a68c0ca0c589d0da68d30f5182 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:50:45 -0400 Subject: [PATCH 04/14] More of sanitize_md --- src/solidation/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 74c9e76..0915e28 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -271,7 +271,7 @@ def to_markdown(self) -> str: if untriaged_issues: s += f"##### Untriaged issues of the last {dayscovered} days\n" for i in sorted(untriaged_issues, key=lambda x: x.created_at): - s += f"- [{i.title}]({i.html_url}) [{i.repository.full_name}]\n" + s += f"- [{sanitize_md(i.title)}]({i.html_url}) [{i.repository.full_name}]\n" s += ( f"##### Max {self.config.num_oldest_prs} oldest, open, non-draft" @@ -297,7 +297,7 @@ def to_markdown(self) -> str: # issue, which slows things down considerably. continue age = now - ensure_aware(i.created_at) # type: ignore[unreachable] - s += f"- [{i.title}]({i.html_url}) ({age.days} days old)\n" + s += f"- [{sanitize_md(i.title)}]({i.html_url}) ({age.days} days old)\n" n_random_ip -= 1 if n_random_ip == 0: break From 65e4d0c67e0d099166936a91a45cef830e03c7a3 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:53:51 -0400 Subject: [PATCH 05/14] Add workflow for running tests --- .github/workflows/test.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..77839dc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Unit Test + +on: + - push + - pull_request + +jobs: + typing: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox + + - name: Run type checker + run: tox -e py3 From 4978b8a9099b4f4f1c3e1072efb6ebb330b43722 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:00:04 -0400 Subject: [PATCH 06/14] Move tests/ under the root of the project --- {src/solidation/tests => tests}/__init__.py | 0 {src/solidation/tests => tests}/test_main.py | 2 +- tox.ini | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) rename {src/solidation/tests => tests}/__init__.py (100%) rename {src/solidation/tests => tests}/test_main.py (73%) diff --git a/src/solidation/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/solidation/tests/__init__.py rename to tests/__init__.py diff --git a/src/solidation/tests/test_main.py b/tests/test_main.py similarity index 73% rename from src/solidation/tests/test_main.py rename to tests/test_main.py index de1d589..4661e90 100644 --- a/src/solidation/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,4 @@ -from ..__main__ import sanitize_md +from solidation.__main__ import sanitize_md def test_sanitize_md() -> None: diff --git a/tox.ini b/tox.ini index a49816e..11f1422 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ minversion = 3.3.0 [testenv] extras = test commands = - python -m pytest -v {posargs} src + python -m pytest -v {posargs} tests [testenv:lint] skip_install = True @@ -16,13 +16,13 @@ deps = flake8-builtins flake8-unused-arguments commands = - flake8 src + flake8 src tests [testenv:typing] deps = mypy commands = - mypy src + mypy src tests [flake8] doctests = True @@ -42,4 +42,4 @@ lines_between_sections = 0 profile = black reverse_relative = True sort_relative_in_force_sorted_sections = True -src_paths = src +src_paths = src tests From 190f48349b91e11028f51729fc5092c6f239619a Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:01:19 -0400 Subject: [PATCH 07/14] Satisfy linters --- src/solidation/__main__.py | 3 ++- tests/test_main.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 0915e28..1612d74 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -271,7 +271,8 @@ def to_markdown(self) -> str: if untriaged_issues: s += f"##### Untriaged issues of the last {dayscovered} days\n" for i in sorted(untriaged_issues, key=lambda x: x.created_at): - s += f"- [{sanitize_md(i.title)}]({i.html_url}) [{i.repository.full_name}]\n" + s += f"- [{sanitize_md(i.title)}]({i.html_url}) " + \ + f"[{i.repository.full_name}]\n" s += ( f"##### Max {self.config.num_oldest_prs} oldest, open, non-draft" diff --git a/tests/test_main.py b/tests/test_main.py index 4661e90..1c680d4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,4 +2,5 @@ def test_sanitize_md() -> None: - assert sanitize_md(r"[gh-actions](deps): Fix \n") == r"\[gh-actions\](deps): Fix \\n" + assert sanitize_md(r"[gh-actions](deps): Fix \n") \ + == r"\[gh-actions\](deps): Fix \\n" From 9adbdb18a931fdbea60ca005e1508e954761e519 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:53:38 -0400 Subject: [PATCH 08/14] Fix name for CI step Co-authored-by: John T. Wodder II --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77839dc..87d2920 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,5 +23,5 @@ jobs: python -m pip install --upgrade pip python -m pip install --upgrade tox - - name: Run type checker + - name: Run tests run: tox -e py3 From 15047f158a532afa0e8eb8b74a4ce8f50dcf2e18 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:56:58 -0400 Subject: [PATCH 09/14] pre-commit fixups --- README.md | 1 - src/solidation/__main__.py | 8 +++++--- tests/test_main.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ac52b3..1d83108 100644 --- a/README.md +++ b/README.md @@ -128,4 +128,3 @@ keys (all optional): - Proposed by: mih (6), jwodder (4), TheChymera (1), mslw (1), jsheunis (1) - Merged by: mih (6), yarikoptic (4), bpoldrack (1), christian-monch (1), jsheunis (1) - PR duration quantiles (days): [0.0, 0.0, 5.0] - diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 1612d74..48e8ce4 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -271,8 +271,10 @@ def to_markdown(self) -> str: if untriaged_issues: s += f"##### Untriaged issues of the last {dayscovered} days\n" for i in sorted(untriaged_issues, key=lambda x: x.created_at): - s += f"- [{sanitize_md(i.title)}]({i.html_url}) " + \ - f"[{i.repository.full_name}]\n" + s += ( + f"- [{sanitize_md(i.title)}]({i.html_url}) " + + f"[{i.repository.full_name}]\n" + ) s += ( f"##### Max {self.config.num_oldest_prs} oldest, open, non-draft" @@ -440,7 +442,7 @@ def ensure_aware(dt: datetime) -> datetime: def sanitize_md(s: str) -> str: # Remove `[]` symbols to ensure correct markdown in the references - return re.sub(r'([\\\[\]])', r'\\\1', s) + return re.sub(r"([\\\[\]])", r"\\\1", s) @click.command() diff --git a/tests/test_main.py b/tests/test_main.py index 1c680d4..1031a05 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,5 +2,6 @@ def test_sanitize_md() -> None: - assert sanitize_md(r"[gh-actions](deps): Fix \n") \ - == r"\[gh-actions\](deps): Fix \\n" + assert ( + sanitize_md(r"[gh-actions](deps): Fix \n") == r"\[gh-actions\](deps): Fix \\n" + ) From 6b57e0e904ad85cc823da10df3b0826a434ab023 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:58:09 -0400 Subject: [PATCH 10/14] One more sanitize invocation I missed and John noted --- src/solidation/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 48e8ce4..27b9af1 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -284,7 +284,7 @@ def to_markdown(self) -> str: (p for p in self.open_prs if not p.draft), key=lambda x: x.created_at )[: self.config.num_oldest_prs]: age = now - ensure_aware(pr.created_at) - s += f"- [{pr.title}]({pr.html_url}) ({age.days} days)\n" + s += f"- [{sanitize_md(pr.title)}]({pr.html_url}) ({age.days} days)\n" n_random_ip = min(self.config.max_random_issues, len(self.open_ip)) if n_random_ip: From 0d6d737a8d727152dbc938b0bf13cf2aaea38752 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 10:58:44 -0400 Subject: [PATCH 11/14] no pytest-cov --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e175c48..9723d48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,6 @@ install_requires = [options.extras_require] test = pytest - pytest-cov [options.packages.find] where = src From 5ef9981b2a8f8c93e51b2857c600d7dc6fe59dcc Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 11:03:44 -0400 Subject: [PATCH 12/14] No tests within src_paths for isort! John: This has nothing to do with whether imports are sorted in the tests. src_paths = tests declares that any modules immediately within tests/ are to be treated as first-party packages for sorting purposes, but we shouldn't be importing anything from modules within tests/ anyway. --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 11f1422..ac832c7 100644 --- a/tox.ini +++ b/tox.ini @@ -42,4 +42,4 @@ lines_between_sections = 0 profile = black reverse_relative = True sort_relative_in_force_sorted_sections = True -src_paths = src tests +src_paths = src From b56188aeb8098e824c52cf77a0f6eac16002c45c Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 21:57:19 -0400 Subject: [PATCH 13/14] [DATALAD RUNCMD] pre-commit autoupdate === Do not change lines below === { "chain": [], "cmd": "pre-commit autoupdate", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b65463..7ba5db2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-json @@ -10,17 +10,17 @@ repos: - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.8.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.1.1 hooks: - id: flake8 additional_dependencies: From ceedd36fdb4007c00c0478737f0ca0c3cff080f3 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 23 Aug 2024 14:02:41 -0400 Subject: [PATCH 14/14] rm tests/__init__.py since not needed according to @jwodder --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000