Skip to content

Infer dependencies from setup.cfg#1795

Closed
Copilot wants to merge 9 commits intomainfrom
copilot/infer-dependencies-setup-cfg
Closed

Infer dependencies from setup.cfg#1795
Copilot wants to merge 9 commits intomainfrom
copilot/infer-dependencies-setup-cfg

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

  • Create src/usethis/_file/setup_cfg/deps.py with get_setup_cfg_project_deps() and get_setup_cfg_dep_groups() functions
  • Update src/usethis/_deps.py to read from setup.cfg and merge those deps with pyproject.toml deps
  • Update docstrings in _deps.py to mention setup.cfg
  • Create tests/usethis/_file/setup_cfg/test_deps.py with 17 unit tests (100% coverage)
  • Update tests/usethis/test_deps.py to add SetupCFGManager() to all relevant test contexts and add integration tests for setup.cfg
  • Auto-generated docs updated (AGENTS.md, functions.txt, module-tree.txt)
  • Fix type annotations and clarify docstrings in setup.cfg dep inference
  • All static checks pass (prek + basedpyright)
  • Fix tests/usethis/test_init.py::TestWriteSimpleRequirementsTxt by adding SetupCFGManager() context (CI failure Add issue template for tasks #1)
  • Fix tests/conftest.py: reset usethis_config.backend and usethis_config.inferred_backend in autouse fixture to prevent test pollution (CI failure Add a new GitHub issue template for tasks #2)
  • Fix src/usethis/_config.py: add try-finally to UsethisConfig.set() so config state is always restored even when exceptions are raised inside with blocks (CI failure Configure testing suite #3 — root cause of cascading "empty output" failures)
  • Fix tests/usethis/_tool/test_base.py: add SetupCFGManager() to TestIsUsed and TestIsDeclaredAsDep tests
  • Fix tests/usethis/_core/test_core_tool.py: add SetupCFGManager() to ~28 tests missing it (TestCoverage, TestDeptry, TestRequirementsTxt, TestPyprojectFmt)
  • Remove # pragma: no cover comments and # type: ignore[union-attr] comments from setup_cfg/deps.py; simplify code to use raw_value or ""
  • Replace double backticks (\`...```) with single backticks in all docstrings written in this PR; filed issue Add prek hook to forbid double backticks in docstrings #1822 for a prek hook to enforce this

Copilot AI and others added 2 commits April 4, 2026 00:32
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/51322711-9cdb-484c-8a37-2aa0ad08ac75

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for dependencies in setup.cfg Infer dependencies from setup.cfg Apr 4, 2026
Copilot AI requested a review from nathanjmcdougall April 4, 2026 00:38
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 4, 2026 02:20
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 4, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/infer-dependencies-setup-cfg (841f512) with main (7c45f33)

Open in CodSpeed

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot some of the tests are failing. See the GH Actions config for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests were relevant to run.

…rementsTxt

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/f7cfd326-fb26-42fa-af09-f0b5d180b7dd

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 4, 2026

@copilot some of the tests are failing. See the GH Actions config for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests were...

Fixed in 62e9919. The 5 failing TestWriteSimpleRequirementsTxt tests in test_init.py needed SetupCFGManager() added to their context, since write_simple_requirements_txt() calls get_project_deps() which now reads from setup.cfg.

The root cause was that when I searched for tests to update, I only looked for direct callers of get_project_deps() and get_dep_groups(), missing test_init.py which calls write_simple_requirements_txt() — an indirect/transitive caller in _init.py. I've filed issue #1808 to track this lesson about checking transitive callers when modifying _deps.py.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot some of the tests are still failing. See the GH Actions logs for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests were relevant to run.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 4, 2026

@copilot some of the tests are still failing. See the GH Actions logs for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests ...

Fixed in 32abab5. The root cause was stale usethis_config.inferred_backend leaking between tests.

Tests in my new TestGetDepGroups::TestPoetry class (and the pre-existing TestGetProjectDeps::TestPoetry) set usethis_config.backend = BackendEnum.poetry via direct assignment rather than the usethis_config.set() context manager. Direct assignment leaves inferred_backend cached as poetry after the test completes. Since get_backend() checks inferred_backend first, all subsequent tests that relied on backend auto-detection silently received poetry and called the Poetry subprocess (which is broken in the min-dependencies CI environment).

Fix: added usethis_config.backend = BackendEnum(BACKEND_DEFAULT) and usethis_config.inferred_backend = None resets to the autouse clear_functools_caches fixture in tests/conftest.py. Filed issue #1812 to track this lesson.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot some of the tests are still failing. See the GH Actions logs for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests were relevant to run.

…upCFGManager to missing test contexts

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/9ec216b2-e65e-4fec-aa2f-6addd5a627e1

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 4, 2026

@copilot some of the tests are still failing. See the GH Actions logs for details. Please fix the issue, and then create a ticket regarding what went wrong in terms of the agent inferring which tests ...

Fixed in bfb2905. There were two root causes:

1. UnexpectedSetupCFGIOError in tests missing SetupCFGManager() contexttest_base.py::TestIsUsed, test_core_tool.py::TestDeptry::TestAdd, TestRequirementsTxt, TestPyprojectFmt, etc. all used PyprojectTOMLManager() without SetupCFGManager(). Added SetupCFGManager() to ~30 test contexts.

2. Missing try-finally in UsethisConfig.set() (root cause of the cascading "empty output" failures): Python's @contextmanager does NOT run cleanup code after yield if an exception is raised inside the with block — unless try-finally is used. Since UsethisConfig.set() lacked try-finally, any UnexpectedSetupCFGIOError raised inside a with usethis_config.set(quiet=True): block (in _core/tool.py) left quiet=True permanently, causing ~80 subsequent tests to produce empty output.

Fixed _config.py to wrap yield in try-finally, and filed issue #1818 to track this lesson about @contextmanager requiring try-finally for proper cleanup on exceptions.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Comment thread src/usethis/_file/setup_cfg/deps.py Outdated
result: dict[str, list[Dependency]] = {}
for extra_name in cfg["options.extras_require"].options(): # type: ignore[union-attr]
raw_value: str | None = cfg["options.extras_require"][extra_name].value # type: ignore[union-attr]
if raw_value is None: # pragma: no cover
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please remove all pragma comments. Also all "type:" comments should be converted to "pyright:".

We should create a GitHub ticket for this lesson so that we make a hook which forbids particular keywords in comments, provided via CLI. This is one of them: "pragma". Another is "type:"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 841f512. Removed all # pragma: no cover comments and # type: ignore[union-attr] comments from setup_cfg/deps.py. Since Option.value returns str | None but is always a non-None string when parsed from a file (empty values return ''), I simplified the code to use raw_value or "" instead of the unreachable None checks. Pyright requires no type suppression for this code.

Filed issue #1820 to track adding a prek hook that forbids pragma: and type: ignore keywords in comments.

…_cfg/deps.py

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/dddc5605-30c3-4d38-9d88-5e6b7fc9b894

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Comment thread src/usethis/_file/setup_cfg/deps.py Outdated
def get_setup_cfg_dep_groups() -> dict[str, list[Dependency]]:
"""Get dependency groups from setup.cfg [options.extras_require].

This reads the ``[options.extras_require]`` section of ``setup.cfg``, which is the
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please remove double backticks in docstrings.

Please also create a lesson about this - with the suggested solution that we create a prek hook to forbid double backticks in docstrings, and update agent skills accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 77e7b4e. Replaced all double backticks with single backticks in setup_cfg/deps.py and _deps.py docstrings. Filed issue #1822 to track adding a prek hook to forbid double backticks in docstrings.

Comment thread src/usethis/_deps.py Outdated
Usually this is just the dependencies in the ``project.dependencies`` section
of the ``pyproject.toml`` file. When the poetry backend is active, also
reads from ``[tool.poetry.dependencies]``.
reads from ``[tool.poetry.dependencies]``. Also merges from ``setup.cfg``
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot again - remove double backticks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 77e7b4e.

Comment thread src/usethis/_deps.py Outdated

Reads from ``[dependency-groups]`` (PEP 735). When the poetry backend
is active, also reads from ``[tool.poetry.group.*.dependencies]``.
is active, also reads from ``[tool.poetry.group.*.dependencies]``. Also
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again -remove double backticks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 77e7b4e.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Per #1823 I want to close this PR for now until some bigger questions are resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infer dependencies from setup.cfg

2 participants