fix: use Path(str()) instead of resources.as_file() for alembic dir on Python < 3.12#303
Open
octo-patch wants to merge 1 commit into
Conversation
…n Python < 3.12 (fixes PySpur-Dev#273) resources.as_file() only supports files in Python < 3.12. When called with a MultiplexedPath representing a directory, it raises TypeError: 'MultiplexedPath(...) is not a file'. Convert via Path(str(resource)) instead, which returns the underlying filesystem path for installed packages and works on Python 3.11. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #273
Problem
Running
pyspur servewith a PostgreSQL database fails with:importlib.resources.as_file()only supports individual files in Python < 3.12. When called with aMultiplexedPathrepresenting a directory (the alembic scripts folder), it raises:Python 3.12 extended
as_file()to support directories, but PySpur supports Python 3.11+.Solution
Replace
resources.as_file(script_location)withPath(str(script_location)).For packages installed to the filesystem (i.e. regular
pip install),str(MultiplexedPath)returns the underlying filesystem path directly, so we can pass it toshutil.copytree()without needing the context manager.Testing
Verified the changed code path no longer uses
as_file()on a directory. The fix is a one-line change that removes the incompatible Python < 3.12 code path while preserving the same copy-to-temp-dir behavior.