Repository navigation
fix: refuse bw2data 4 next to bw2io < 0.9 before opening a project - #1
Merged
Merged
Conversation
bw2data 4 applies automatic project updates on set_current, and one of
them (fix_migrations_filename) imports bw2io. bw2io 0.8.x was written for
legacy bw2data and dies at import against bw2data 4 with
BW2 = bd.__version__ < (4,)
TypeError: '<' not supported between instances of 'str' and 'tuple'
A user hit this running `sentier-brightway db --project X` with bw2data
4.7 and bw2io 0.8.12 on an existing project. The mix is common in
Activity Browser environments where bw2data was upgraded on its own.
New preflight.check_environment() reads the installed bw2io version from
package metadata (never imports it) and raises IncompatibleEnvironmentError
naming the fix, pip install -U "bw2io>=0.9.3". writer.write() calls it
before set_current, so nothing is created. Six unit tests cover string
and tuple versions, dev suffixes, absent bw2io and the legacy stack; a
writer test asserts the project is never created. README documents the
two supported generations and the refused mix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A user running
uv run sentier-brightway db --project Xwith Python 3.11, bw2data 4.7 and bw2io 0.8.12 got:The line is in bw2io 0.8.12 (
remote.py), not here. bw2io 0.8.x expects the tuple__version__of legacy bw2data; against bw2data 4 it fails at import time. bw2data 4 reaches it on its own: opening a project runs the automatic updatefix_migrations_filename, which doesimport bw2io. The update fires on projects last touched by an older bw2data, so an existing Activity Browser project triggers it while a fresh one (our tests) does not.This PR adds
sentier_brightway.preflight:check_environment(bd)reads the installed bw2io version from package metadata (never imports it) and raisesIncompatibleEnvironmentErrorwhen bw2data >= 4 sits next to bw2io < 0.9. The message names the fix:pip install -U "bw2io>=0.9.3".writer.write()calls it beforeprojects.set_current, so no project is created.Legacy stacks (bw2data 3.x + bw2io 0.8.x, stock Activity Browser 2.11) and bw2data 4 + bw2io 0.9 are untouched. bw2io absent is fine too, bw2data only warns then.
Test plan
tests/test_preflight.py: 6 unit cases (string/tuple versions,4.7.dev1, absent bw2io, legacy stack, bw2io 0.9.3/0.9.17)tests/test_writer.py: the guard fires beforeset_current, project never created, fix nameduv run --extra testing pytest: 295 passeduv run --extra dev pre-commit run --all-files: clean