Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Dec 30, 2025

Summary by CodeRabbit

  • Refactor
    • Updated internal path handling throughout the SDK and tests to use modern Python patterns for improved code consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Walkthrough

This pull request transitions the codebase from using the os module for path operations to pathlib.Path. Changes include: replacing os.getcwd() with pathlib.Path.cwd() in SDK initialization code, updating test utility helpers and fixture directory discovery to use Path.resolve() instead of os.path.abspath(), and removing the corresponding os-based imports. Additionally, the pyproject.toml file removes two previously-ignored Ruff linting rules (PTH100 and PTH109) that enforce pathlib usage, activating these lint checks across the project.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing os-based path operations with pathlib throughout the codebase across multiple files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 30, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: af827c1
Status: ✅  Deploy successful!
Preview URL: https://7b71ad07.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-prefer-pathlib.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                Coverage Diff                @@
##           infrahub-develop     #722   +/-   ##
=================================================
  Coverage             76.28%   76.28%           
=================================================
  Files                   114      114           
  Lines                  9830     9831    +1     
  Branches               1508     1509    +1     
=================================================
+ Hits                   7499     7500    +1     
  Misses                 1837     1837           
  Partials                494      494           
Flag Coverage Δ
integration-tests 34.43% <25.00%> (+<0.01%) ⬆️
python-3.10 50.13% <50.00%> (-0.04%) ⬇️
python-3.11 50.13% <50.00%> (-0.02%) ⬇️
python-3.12 50.13% <50.00%> (-0.02%) ⬇️
python-3.13 50.13% <50.00%> (-0.02%) ⬇️
python-3.14 51.79% <50.00%> (+<0.01%) ⬆️
python-filler-3.12 24.01% <75.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/checks.py 70.19% <100.00%> (ø)
infrahub_sdk/operation.py 88.63% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad ogenstad marked this pull request as ready for review December 30, 2025 09:40
@ogenstad ogenstad requested a review from a team December 30, 2025 09:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/unit/ctl/test_render_app.py (1)

16-16: Simplify redundant Path nesting.

The expression Path(Path(Path(__file__).resolve()).parent / ".." / "..") has unnecessary nesting. Once Path(__file__).resolve() is called, you already have a Path object.

🔎 Proposed simplification
-FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "repos")
+FIXTURE_BASE_DIR = Path(__file__).resolve().parent.parent.parent / "fixtures" / "repos"

This is more idiomatic and avoids redundant Path() wrapping.

tests/integration/test_infrahubctl.py (1)

25-25: Simplify redundant Path nesting.

The expression Path(Path(Path(__file__).resolve()).parent / "..") has unnecessary nesting.

🔎 Proposed simplification
-FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / "fixtures")
+FIXTURE_BASE_DIR = Path(__file__).resolve().parent.parent / "fixtures"

This is more idiomatic and avoids redundant Path() wrapping.

tests/unit/ctl/test_transform_app.py (1)

21-23: Simplify redundant Path nesting.

The expression Path(Path(Path(__file__).resolve()).parent / ".." / "..") has unnecessary nesting.

🔎 Proposed simplification
-FIXTURE_BASE_DIR = Path(
-    Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl"
-)
+FIXTURE_BASE_DIR = (
+    Path(__file__).resolve().parent.parent.parent / "fixtures" / "integration" / "test_infrahubctl"
+)

This is more idiomatic and avoids redundant Path() wrapping.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71477e4 and af827c1.

📒 Files selected for processing (7)
  • infrahub_sdk/checks.py
  • infrahub_sdk/operation.py
  • pyproject.toml
  • tests/helpers/utils.py
  • tests/integration/test_infrahubctl.py
  • tests/unit/ctl/test_render_app.py
  • tests/unit/ctl/test_transform_app.py
💤 Files with no reviewable changes (1)
  • pyproject.toml
🧰 Additional context used
📓 Path-based instructions (5)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification

Files:

  • tests/integration/test_infrahubctl.py
  • tests/helpers/utils.py
  • infrahub_sdk/checks.py
  • tests/unit/ctl/test_transform_app.py
  • infrahub_sdk/operation.py
  • tests/unit/ctl/test_render_app.py
tests/**/*.py

📄 CodeRabbit inference engine (tests/AGENTS.md)

tests/**/*.py: Use httpx_mock fixture for HTTP mocking in tests instead of making real HTTP requests
Do not add @pytest.mark.asyncio decorator to async test functions (async auto-mode is globally enabled)

Files:

  • tests/integration/test_infrahubctl.py
  • tests/helpers/utils.py
  • tests/unit/ctl/test_transform_app.py
  • tests/unit/ctl/test_render_app.py
tests/integration/**/*.py

📄 CodeRabbit inference engine (tests/AGENTS.md)

tests/integration/**/*.py: Integration tests should use testcontainers to interact with real Infrahub instances
Clean up resources in integration tests

Files:

  • tests/integration/test_infrahubctl.py
infrahub_sdk/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Follow async/sync dual pattern for new features in the Python SDK

Files:

  • infrahub_sdk/checks.py
  • infrahub_sdk/operation.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (tests/AGENTS.md)

Unit tests must be fast, mocked, and have no external dependencies

Files:

  • tests/unit/ctl/test_transform_app.py
  • tests/unit/ctl/test_render_app.py
🧠 Learnings (3)
📚 Learning: 2025-12-10T17:13:37.990Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: tests/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:37.990Z
Learning: Applies to tests/integration/**/*.py : Integration tests should use testcontainers to interact with real Infrahub instances

Applied to files:

  • tests/integration/test_infrahubctl.py
  • tests/unit/ctl/test_transform_app.py
📚 Learning: 2025-12-10T17:13:21.977Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/ctl/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:21.977Z
Learning: Applies to infrahub_sdk/ctl/**/*.py : Do not instantiate InfrahubClient directly; always use initialize_client() or initialize_client_sync() helper functions

Applied to files:

  • tests/integration/test_infrahubctl.py
📚 Learning: 2025-11-25T13:23:15.190Z
Learnt from: wvandeun
Repo: opsmill/infrahub-sdk-python PR: 637
File: infrahub_sdk/operation.py:74-76
Timestamp: 2025-11-25T13:23:15.190Z
Learning: In infrahub_sdk/operation.py, the recursive=True parameter in _process_relationships is a temporary workaround to access Proposed Changes data. This will be replaced with proper object-level metadata implementation in version 1.7.

Applied to files:

  • infrahub_sdk/operation.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
infrahub_sdk/checks.py (1)

5-5: LGTM! Clean migration to pathlib.

The change from os.getcwd() to str(pathlib.Path.cwd()) is correct and maintains backward compatibility by preserving the string type for root_directory.

Also applies to: 58-58

tests/helpers/utils.py (1)

18-18: LGTM! Pathlib migration is correct.

The change from os.getcwd() to Path.cwd() is appropriate. The subsequent os.chdir() calls correctly accept Path objects as per PEP 519.

Also applies to: 33-33

infrahub_sdk/operation.py (1)

3-3: LGTM! Clean migration to pathlib.

The change from os.getcwd() to str(pathlib.Path.cwd()) is correct and maintains backward compatibility by preserving the string type for root_directory.

Also applies to: 25-25

@ogenstad ogenstad merged commit 38b9ece into infrahub-develop Dec 30, 2025
21 checks passed
@ogenstad ogenstad deleted the pog-prefer-pathlib branch December 30, 2025 10:20
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.

3 participants