chore: Repalce appdirspackage with platformdirs#1373
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR replaces the deprecated Flow diagram for save_folder resolution using platformdirsflowchart TD
A["Start"] --> B["Read environment variable PARTSEG_SETTINGS_DIR"]
B --> C{Is PARTSEG_SETTINGS_DIR set?}
C -- Yes --> D["base_dir = PARTSEG_SETTINGS_DIR"]
C -- No --> E["base_dir = platformdirs.user_data_dir(APP_NAME, APP_LAB)"]
D --> F["version = packaging.version.parse(__version__).base_version"]
E --> F
F --> G["save_folder = os.path.join(base_dir, version)"]
G --> H["End"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📝 WalkthroughWalkthroughThe project replaces the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.16.4)package/PartSeg/state_store.py┌──────────────┐ �[32m✔�[39m �[1mOpengrep OSS�[0m �[1m Loading rules from local config...�[0m 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. Comment |
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
pyproject.tomlthe classifier line forProgramming Language :: Python :: 3now has a trailing comma on a separate line, which is an unnecessary formatting change and should be reverted to the previous single-line style for consistency. - After replacing
appdirswithplatformdirsinstate_store.py, ensure the corresponding import is updated and that there are no remaining references toappdirselsewhere in the codebase to avoid runtime errors. - The various
requirements/constraints_*.txtfiles are listed as changed but the diff shows no updates; ifappdirsis pinned in those files it should be replaced withplatformdirsto keep constraints consistent withpyproject.toml.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `pyproject.toml` the classifier line for `Programming Language :: Python :: 3` now has a trailing comma on a separate line, which is an unnecessary formatting change and should be reverted to the previous single-line style for consistency.
- After replacing `appdirs` with `platformdirs` in `state_store.py`, ensure the corresponding import is updated and that there are no remaining references to `appdirs` elsewhere in the codebase to avoid runtime errors.
- The various `requirements/constraints_*.txt` files are listed as changed but the diff shows no updates; if `appdirs` is pinned in those files it should be replaced with `platformdirs` to keep constraints consistent with `pyproject.toml`.
## Individual Comments
### Comment 1
<location path="pyproject.toml" line_range="20-21" />
<code_context>
"Framework :: napari",
"Operating System :: OS Independent",
- "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3"
+ ,
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
</code_context>
<issue_to_address>
**issue (bug_risk):** The comma on a separate line likely makes this TOML array invalid.
In TOML, commas must appear on the same line as the preceding value. Putting the comma on its own line makes the array invalid and can break `pyproject.toml` parsing. Please keep the comma at the end of the value line instead.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| "Programming Language :: Python :: 3" | ||
| , |
There was a problem hiding this comment.
issue (bug_risk): The comma on a separate line likely makes this TOML array invalid.
In TOML, commas must appear on the same line as the preceding value. Putting the comma on its own line makes the array invalid and can break pyproject.toml parsing. Please keep the comma at the end of the value line instead.
There was a problem hiding this comment.
Actionable comments posted: 4
♻️ Duplicate comments (7)
requirements/constraints_py3.10_pydantic_1.txt (1)
11-14:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 11:
platformdirs==4.3.6- Line 248:
platformdirs==4.9.4Also applies to: 248-253
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.10_pydantic_1.txt` around lines 11 - 14, The constraints file contains duplicate entries for the same package name (platformdirs) with conflicting versions; remove the duplicate so only one platformdirs==<chosen_version> remains (decide between 4.3.6 and 4.9.4), update any dependent constraint comments if necessary, and regenerate/validate the constraints (e.g., re-run your constraints/lock generation) so build tooling uses the single canonical version; search for the package name "platformdirs" to locate both occurrences to resolve.requirements/constraints_py3.11_pydantic_1.txt (1)
11-14:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 11:
platformdirs==4.3.6- Line 244:
platformdirs==4.9.4Also applies to: 244-249
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.11_pydantic_1.txt` around lines 11 - 14, The constraints file contains duplicate conflicting entries for platformdirs (platformdirs==4.3.6 and platformdirs==4.9.4); remove one and consolidate to a single version across the file (choose the intended version, e.g., platformdirs==4.9.4) so the constraints are consistent, and update any other duplicate blocks (the second occurrence around the file) to match the chosen version to avoid dependency conflicts.requirements/constraints_py3.9_pydantic_1.txt (1)
11-14:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 11:
platformdirs==4.3.6- Line 252:
platformdirs==4.4.0Also applies to: 252-257
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.9_pydantic_1.txt` around lines 11 - 14, The constraints file contains duplicate conflicting entries for the same package (platformdirs==4.3.6 and platformdirs==4.4.0); locate all occurrences of "platformdirs" in the constraints file and consolidate them to a single, correct version (choose either 4.3.6 or 4.4.0 consistent with the project/pyproject.toml requirements), remove the other duplicate entry, and update any nearby comment annotations (the "# via" dependency notes) so they still accurately reflect the source of that constraint; ensure no other sections later in the file reintroduce the old version.requirements/constraints_py3.12_docs.txt (1)
11-14:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 11:
platformdirs==4.3.6- Line 232:
platformdirs==4.9.4Also applies to: 232-237
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.12_docs.txt` around lines 11 - 14, The constraints file contains duplicate platformdirs entries with conflicting pins (platformdirs==4.3.6 and platformdirs==4.9.4); remove the duplicate and consolidate to a single chosen version (prefer the higher 4.9.4 unless another dependency requires 4.3.6), update any comments/markers referencing those lines, and rerun dependency resolution to ensure no other package (e.g., partseg, napari) requires the older pin before committing.requirements/constraints_py3.10.txt (1)
13-16:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 13:
platformdirs==4.3.6- Line 250:
platformdirs==4.9.4Also applies to: 250-255
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.10.txt` around lines 13 - 16, The constraints file contains duplicate conflicting entries for the package identifier "platformdirs": "platformdirs==4.3.6" and "platformdirs==4.9.4"; remove or consolidate them to a single, correct version (pick the project-compatible one, e.g., update all occurrences to "platformdirs==4.9.4" or the version required by your pyproject/lockfiles) so only one "platformdirs==<version>" line remains in requirements/constraints_py3.10.txt and ensure any comments referencing it are updated accordingly.requirements/constraints_py3.11.txt (1)
13-16:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 13:
platformdirs==4.3.6- Line 246:
platformdirs==4.9.4Also applies to: 246-251
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.11.txt` around lines 13 - 16, The constraints file contains duplicate platformdirs pins (platformdirs==4.3.6 and platformdirs==4.9.4); remove the duplicate and consolidate to a single pinned version (choose the correct/compatible one, e.g., platformdirs==4.9.4) so only one platformdirs entry remains; update any related comments or “# via” notes (references to partseg/napari) if necessary to reflect the chosen version and run dependency resolution to ensure no other package (e.g., partseg, napari) requires the removed version.requirements/constraints_py3.12_pydantic_1.txt (1)
11-14:⚠️ Potential issue | 🔴 CriticalCritical: Duplicate
platformdirsentries with conflicting versions.This constraints file contains
platformdirstwice with different versions:
- Line 11:
platformdirs==4.3.6- Line 244:
platformdirs==4.9.4This creates an unsolvable dependency conflict that will cause installation to fail.
Also applies to: 244-249
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@requirements/constraints_py3.12_pydantic_1.txt` around lines 11 - 14, The constraints file contains duplicate entries for the same package "platformdirs" with conflicting versions; remove one and keep a single, consistent constraint (e.g., consolidate to the newer compatible version platformdirs==4.9.4 or whichever version is verified against your dependency set), update any nearby comment/metadata that referenced the removed entry, and re-generate or re-validate the constraints so only one platformdirs==... line remains (also ensure the duplicate in the later block around the 244-249 region is removed or unified).
🧹 Nitpick comments (1)
pyproject.toml (1)
20-21: Unusual TOML formatting - trailing comma on separate line.The classifier string and its trailing comma are split across two lines, which is valid TOML but unconventional:
"Programming Language :: Python :: 3" ,This appears to be an unintentional formatting artifact. Consider consolidating to a single line.
🧹 Suggested fix
- "Programming Language :: Python :: 3" - , + "Programming Language :: Python :: 3",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pyproject.toml` around lines 20 - 21, The TOML fragment splits the classifier string and its trailing comma across two lines; consolidate them so the classifier entry is a single line (e.g., merge the line containing "Programming Language :: Python :: 3" with the following line that only contains a comma) ensuring the comma stays immediately after the string; locate the classifier array where "Programming Language :: Python :: 3" appears and fix the formatting to a conventional single-line entry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@requirements/constraints_py3.12.txt`:
- Around line 13-16: Multiple requirements/constraints files contain duplicate
platformdirs pins with conflicting versions; regenerate each constraints file so
it contains only a single resolved platformdirs entry. For each listed
constraints file (constraints_py3.9.txt, constraints_py3.9_pydantic_1.txt,
constraints_py3.10*.txt, constraints_py3.11*.txt, constraints_py3.12*.txt,
constraints_py3.13*.txt) re-run your constraints generation pipeline (the script
or tool that produced these files) ensuring dependency resolution yields one
platformdirs==<version> line per file, remove the older duplicate entry, and
commit the regenerated constraint files so every constraints_* file has a
single, consistent platformdirs pin.
In `@requirements/constraints_py3.13_pydantic_1.txt`:
- Around line 11-14: The constraints file contains duplicate platformdirs
entries with conflicting versions (platformdirs==4.3.6 and platformdirs==4.9.4);
search for the symbol "platformdirs==" and consolidate to a single version
across the file (pick the correct version for your environment, e.g.,
platformdirs==4.9.4), remove the other duplicate entry, and ensure any related
grouped comment blocks (the surrounding "# via" lines) remain consistent after
the change so the file has only one platformdirs==... line.
In `@requirements/constraints_py3.13.txt`:
- Around line 13-16: constraints_py3.13.txt contains duplicate pins for the same
package "platformdirs" with conflicting versions (e.g., 4.3.6 and 4.9.4); locate
all occurrences of "platformdirs==" in the constraints files and remove or
reconcile the duplicates by choosing the correct pinned version and regenerating
the constraints file(s) so the same version is consistently pinned (apply the
same fix to constraints_py3.9.txt as well).
In `@requirements/constraints_py3.9.txt`:
- Around line 13-16: The constraints file contains duplicate conflicting pins
for platformdirs (platformdirs==4.3.6 and platformdirs==4.4.0); regenerate the
autogenerated constraints by re-running the lock/compile step (uv pip compile)
so the file contains a single consistent platformdirs version and commit the
updated constraints file, ensuring references to platformdirs in the generated
output are resolved to one pin.
---
Duplicate comments:
In `@requirements/constraints_py3.10_pydantic_1.txt`:
- Around line 11-14: The constraints file contains duplicate entries for the
same package name (platformdirs) with conflicting versions; remove the duplicate
so only one platformdirs==<chosen_version> remains (decide between 4.3.6 and
4.9.4), update any dependent constraint comments if necessary, and
regenerate/validate the constraints (e.g., re-run your constraints/lock
generation) so build tooling uses the single canonical version; search for the
package name "platformdirs" to locate both occurrences to resolve.
In `@requirements/constraints_py3.10.txt`:
- Around line 13-16: The constraints file contains duplicate conflicting entries
for the package identifier "platformdirs": "platformdirs==4.3.6" and
"platformdirs==4.9.4"; remove or consolidate them to a single, correct version
(pick the project-compatible one, e.g., update all occurrences to
"platformdirs==4.9.4" or the version required by your pyproject/lockfiles) so
only one "platformdirs==<version>" line remains in
requirements/constraints_py3.10.txt and ensure any comments referencing it are
updated accordingly.
In `@requirements/constraints_py3.11_pydantic_1.txt`:
- Around line 11-14: The constraints file contains duplicate conflicting entries
for platformdirs (platformdirs==4.3.6 and platformdirs==4.9.4); remove one and
consolidate to a single version across the file (choose the intended version,
e.g., platformdirs==4.9.4) so the constraints are consistent, and update any
other duplicate blocks (the second occurrence around the file) to match the
chosen version to avoid dependency conflicts.
In `@requirements/constraints_py3.11.txt`:
- Around line 13-16: The constraints file contains duplicate platformdirs pins
(platformdirs==4.3.6 and platformdirs==4.9.4); remove the duplicate and
consolidate to a single pinned version (choose the correct/compatible one, e.g.,
platformdirs==4.9.4) so only one platformdirs entry remains; update any related
comments or “# via” notes (references to partseg/napari) if necessary to reflect
the chosen version and run dependency resolution to ensure no other package
(e.g., partseg, napari) requires the removed version.
In `@requirements/constraints_py3.12_docs.txt`:
- Around line 11-14: The constraints file contains duplicate platformdirs
entries with conflicting pins (platformdirs==4.3.6 and platformdirs==4.9.4);
remove the duplicate and consolidate to a single chosen version (prefer the
higher 4.9.4 unless another dependency requires 4.3.6), update any
comments/markers referencing those lines, and rerun dependency resolution to
ensure no other package (e.g., partseg, napari) requires the older pin before
committing.
In `@requirements/constraints_py3.12_pydantic_1.txt`:
- Around line 11-14: The constraints file contains duplicate entries for the
same package "platformdirs" with conflicting versions; remove one and keep a
single, consistent constraint (e.g., consolidate to the newer compatible version
platformdirs==4.9.4 or whichever version is verified against your dependency
set), update any nearby comment/metadata that referenced the removed entry, and
re-generate or re-validate the constraints so only one platformdirs==... line
remains (also ensure the duplicate in the later block around the 244-249 region
is removed or unified).
In `@requirements/constraints_py3.9_pydantic_1.txt`:
- Around line 11-14: The constraints file contains duplicate conflicting entries
for the same package (platformdirs==4.3.6 and platformdirs==4.4.0); locate all
occurrences of "platformdirs" in the constraints file and consolidate them to a
single, correct version (choose either 4.3.6 or 4.4.0 consistent with the
project/pyproject.toml requirements), remove the other duplicate entry, and
update any nearby comment annotations (the "# via" dependency notes) so they
still accurately reflect the source of that constraint; ensure no other sections
later in the file reintroduce the old version.
---
Nitpick comments:
In `@pyproject.toml`:
- Around line 20-21: The TOML fragment splits the classifier string and its
trailing comma across two lines; consolidate them so the classifier entry is a
single line (e.g., merge the line containing "Programming Language :: Python ::
3" with the following line that only contains a comma) ensuring the comma stays
immediately after the string; locate the classifier array where "Programming
Language :: Python :: 3" appears and fix the formatting to a conventional
single-line entry.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0d489480-35e7-44bd-a81e-972501c45aa5
📒 Files selected for processing (13)
package/PartSeg/state_store.pypyproject.tomlrequirements/constraints_py3.10.txtrequirements/constraints_py3.10_pydantic_1.txtrequirements/constraints_py3.11.txtrequirements/constraints_py3.11_pydantic_1.txtrequirements/constraints_py3.12.txtrequirements/constraints_py3.12_docs.txtrequirements/constraints_py3.12_pydantic_1.txtrequirements/constraints_py3.13.txtrequirements/constraints_py3.13_pydantic_1.txtrequirements/constraints_py3.9.txtrequirements/constraints_py3.9_pydantic_1.txt
| platformdirs==4.3.6 | ||
| # via | ||
| # partseg (pyproject.toml) | ||
| # napari |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check for duplicate platformdirs entries in all constraint files
fd 'constraints.*\.txt$' requirements/ --exec sh -c '
echo "=== {} ==="
grep -n "^platformdirs==" "{}" || echo "No platformdirs found"
echo
'Repository: 4DNucleome/PartSeg
Length of output: 1131
Critical: Duplicate platformdirs entries with conflicting versions across all constraint files.
All constraint files in requirements/ contain platformdirs twice with different versions (e.g., platformdirs==4.3.6 and platformdirs==4.9.4 in most files), creating unsolvable dependency conflicts. This affects:
constraints_py3.9.txtandconstraints_py3.9_pydantic_1.txt(versions 4.3.6 and 4.4.0)constraints_py3.10.txt,constraints_py3.11.txt,constraints_py3.12.txt,constraints_py3.12_docs.txt,constraints_py3.12_pydantic_1.txt,constraints_py3.13.txt, andconstraints_py3.13_pydantic_1.txt(versions 4.3.6 and 4.9.4)constraints_py3.10_pydantic_1.txtandconstraints_py3.11_pydantic_1.txt(versions 4.3.6 and 4.9.4)
All constraint files must be regenerated to resolve to a single version of platformdirs per file.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@requirements/constraints_py3.12.txt` around lines 13 - 16, Multiple
requirements/constraints files contain duplicate platformdirs pins with
conflicting versions; regenerate each constraints file so it contains only a
single resolved platformdirs entry. For each listed constraints file
(constraints_py3.9.txt, constraints_py3.9_pydantic_1.txt,
constraints_py3.10*.txt, constraints_py3.11*.txt, constraints_py3.12*.txt,
constraints_py3.13*.txt) re-run your constraints generation pipeline (the script
or tool that produced these files) ensuring dependency resolution yields one
platformdirs==<version> line per file, remove the older duplicate entry, and
commit the regenerated constraint files so every constraints_* file has a
single, consistent platformdirs pin.
| platformdirs==4.3.6 | ||
| # via | ||
| # partseg (pyproject.toml) | ||
| # napari |
There was a problem hiding this comment.
Duplicate platformdirs entries with conflicting versions.
Same duplicate entry pattern as other constraints files:
- Line 11:
platformdirs==4.3.6 - Line 244:
platformdirs==4.9.4
Also applies to: 244-249
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@requirements/constraints_py3.13_pydantic_1.txt` around lines 11 - 14, The
constraints file contains duplicate platformdirs entries with conflicting
versions (platformdirs==4.3.6 and platformdirs==4.9.4); search for the symbol
"platformdirs==" and consolidate to a single version across the file (pick the
correct version for your environment, e.g., platformdirs==4.9.4), remove the
other duplicate entry, and ensure any related grouped comment blocks (the
surrounding "# via" lines) remain consistent after the change so the file has
only one platformdirs==... line.
| platformdirs==4.3.6 | ||
| # via | ||
| # partseg (pyproject.toml) | ||
| # napari |
There was a problem hiding this comment.
Duplicate platformdirs entries with conflicting versions.
Same issue as in constraints_py3.9.txt - this file has two platformdirs entries:
- Line 13:
platformdirs==4.3.6 - Line 246:
platformdirs==4.9.4
Consider regenerating the constraints files to ensure consistent pinning.
Also applies to: 246-251
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@requirements/constraints_py3.13.txt` around lines 13 - 16,
constraints_py3.13.txt contains duplicate pins for the same package
"platformdirs" with conflicting versions (e.g., 4.3.6 and 4.9.4); locate all
occurrences of "platformdirs==" in the constraints files and remove or reconcile
the duplicates by choosing the correct pinned version and regenerating the
constraints file(s) so the same version is consistently pinned (apply the same
fix to constraints_py3.9.txt as well).
| platformdirs==4.3.6 | ||
| # via | ||
| # partseg (pyproject.toml) | ||
| # napari |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check for duplicate platformdirs entries in constraints files
echo "Checking for duplicate platformdirs entries:"
for f in requirements/constraints_*.txt; do
echo "=== $f ==="
grep -n "^platformdirs==" "$f" || echo "No platformdirs entry found"
doneRepository: 4DNucleome/PartSeg
Length of output: 1165
Duplicate platformdirs entries with conflicting versions.
This constraints file contains two separate platformdirs pinned versions:
- Line 13:
platformdirs==4.3.6 - Line 254:
platformdirs==4.4.0
Having conflicting versions for the same package in a single constraints file may cause unexpected installation behavior. Since this file is autogenerated by uv pip compile, regenerate it to ensure only one consistent version is pinned.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@requirements/constraints_py3.9.txt` around lines 13 - 16, The constraints
file contains duplicate conflicting pins for platformdirs (platformdirs==4.3.6
and platformdirs==4.4.0); regenerate the autogenerated constraints by re-running
the lock/compile step (uv pip compile) so the file contains a single consistent
platformdirs version and commit the updated constraints file, ensuring
references to platformdirs in the generated output are resolved to one pin.



Summary by Sourcery
Replace usage of the deprecated appdirs package with platformdirs across configuration and runtime settings handling.
Enhancements:
Build:
Chores:
Summary by CodeRabbit