Fix ruff errors and modernize project config and build - #205
Conversation
A recent update to Ruff caused some new errors. This addresses them.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #205 +/- ##
==========================================
+ Coverage 94.52% 96.17% +1.65%
==========================================
Files 7 6 -1
Lines 1133 1361 +228
Branches 148 154 +6
==========================================
+ Hits 1071 1309 +238
+ Misses 52 43 -9
+ Partials 10 9 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the codebase to satisfy new Ruff lint findings after a Ruff upgrade, primarily by tightening exception handling patterns, simplifying control flow, and making time handling explicit/consistent.
Changes:
- Adds targeted
noqaannotations for intentional broad exceptions and modernizesraiseusage to preserve tracebacks. - Refactors small logic/style patterns flagged by Ruff (flattened conditionals, generator usage, assertion call fixes).
- Updates datetime usage in runtime and tests (UTC-aware timestamps) and tweaks packaging version-loading in
setup.py.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils.py | Lint-driven test adjustments (noqa annotations, simplified bool mocks, UTC-aware date expectations, formatting). |
| tests/test_transform.py | Import ordering tweak to satisfy linting. |
| tests/test_extract.py | Test cleanups (assertion call fix, context manager formatting, range simplifications, UTC-aware datetime usage, expected exception type). |
| src/palletjack/utils.py | Lint fixes and small refactors (bare raise, iteration simplification, expression assignment, chunking simplification, UTC-aware layer naming). |
| src/palletjack/transform.py | Uses UTC-aware timing for logging duration. |
| src/palletjack/load.py | Uses UTC-aware timing; improves exception logging via .exception() usage. |
| src/palletjack/extract.py | Minor refactors, adds UTC-aware datetime operations for token validation, refines raised exception type for unexpected JSON. |
| setup.py | Replaces exec-based version extraction with runpy.run_path. |
| README.md | Normalizes quotes in example snippets. |
| docs/README.md | Normalizes quotes in logging examples. |
| docs/examples.py | Minor formatting and narrows example exception type. |
So that the PR upload comparison is up-to-date
Also add python version requirement
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.
Suppressed comments (4)
tests/test_utils.py:1896
- Same flakiness risk here:
expected_out_layeris derived from a freshnow()call, butsave_to_gdb()computes its ownnow()internally. Freezingpalletjack.utils.datetime.datetime.nowin the test avoids intermittent failures at a UTC date boundary.
expected_out_path = Path("foo", "backup.gdb")
expected_out_layer = f"table_{datetime.datetime.now(datetime.UTC).strftime('%Y_%m_%d')}"
tests/test_utils.py:1922
- This test can also be flaky around a UTC date rollover for the same reason:
expected_erroris computed using anow()call that can disagree with thenow()insidesave_to_gdb(). Freeze the time inpalletjack.utilsto ensure a stable expected message.
gdb_path = Path("/foo/bar/backup.gdb")
date = datetime.datetime.now(datetime.UTC).strftime("%Y_%m_%d")
expected_error = f"Error writing flayer_{date} to {gdb_path}. Verify {gdb_path.parent} exists and is writable."
tests/test_utils.py:1879
- This test can be flaky around a UTC date rollover because it calls
datetime.datetime.now(datetime.UTC)to buildexpected_out_layer, andsave_to_gdb()independently callsnow()again. If the date changes between those calls, the assertion can fail intermittently. Patchpalletjack.utils.datetime.datetime.nowto a fixed value within the test so both sides use the same timestamp.
This issue also appears in the following locations of the same file:
- line 1894
- line 1920
expected_out_path = Path("foo", "backup.gdb")
expected_out_layer = f"flayer_{datetime.datetime.now(datetime.UTC).strftime('%Y_%m_%d')}"
pyproject.toml:9
- With
src/palletjack/version.pyremoved, there is no longer a programmatic version constant (e.g.,palletjack.version.__version__). If this was part of the public API, consider restoring a compatibility shim (for example, a smallversion.pythat reads fromimportlib.metadata) and/or exporting__version__frompalletjack.__init__to avoid breaking downstream imports.
[project]
name = "ugrc-palletjack"
version = "6.0.4"
description = "Updating AGOL feature services with data from external tables."
readme = { file = "README.md", content-type = "text/markdown" }
A recent update to Ruff caused some new errors. This addresses them.