Skip to content

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
PySpur-Dev:mainfrom
octo-patch:fix/issue-273-migration-multiplexedpath-not-a-file
Open

fix: use Path(str()) instead of resources.as_file() for alembic dir on Python < 3.12#303
octo-patch wants to merge 1 commit into
PySpur-Dev:mainfrom
octo-patch:fix/issue-273-migration-multiplexedpath-not-a-file

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #273

Problem

Running pyspur serve with a PostgreSQL database fails with:

Error running migrations: 
MultiplexedPath('/home/user/llm/lib/python3.11/site-packages/pyspur/models/management/alembic') is not a file

importlib.resources.as_file() only supports individual files in Python < 3.12. When called with a MultiplexedPath representing a directory (the alembic scripts folder), it raises:

TypeError: MultiplexedPath('...') is not a file

Python 3.12 extended as_file() to support directories, but PySpur supports Python 3.11+.

Solution

Replace resources.as_file(script_location) with Path(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 to shutil.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.

…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>
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.

Error running migrations: MultiplexedPath()

1 participant