-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update blob.py #390
base: master
Are you sure you want to change the base?
Update blob.py #390
Conversation
This fix works for any installation of ZODB on unspecified platforms like Android. It is proposed for the termux version of ZODB. While a pip install zodb within the termux distro for Android completes without incident, it fails to run since any attempts to import ZODB within termux's python fails. This is because their python's os.link has been disabled for some cross platform reason related to Windows. The only ZODB library code which uses os.link is in ZODB.blob.py where it is selected as the value for the link_or_copy name on Posix systems. On Windows systems, it is mapped to shutil.copy. This pull request extends the mapping of link_or_copy to shutil.copy for Android, not by attempting to identify the platform as Android, but by attempting a try:except snippet.
src/ZODB/blob.py
Outdated
try: | ||
link_or_copy = shutil.copy | ||
except AttributeError: #pragma: no cover | ||
link_or_copy = shutil.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, this cannot be the correct spot for the try: .. except: ...
bit: it is inside the if sys.platform == "win32":
block. The correct location should be below (line 950).
Second, the two parts of the try: ... except: ...
test must not have the same content. Line 950 below should be changed to:
try:
link_or_copy = os.link
except AttributeError: #pragma: no cover
link_or_copy = shutil.copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. You are correct. The changes were meant for line 950
This change fixes the location for the try: except clause. I meant to place it after the if win32 check.
src/ZODB/blob.py
Outdated
@@ -942,13 +942,14 @@ def remove_committed_dir(path): | |||
filename = os.path.join(dirpath, filename) | |||
remove_committed(filename) | |||
shutil.rmtree(path) | |||
|
|||
link_or_copy = shutil.copy | |||
link_or_copy = shutil.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment must be at the same indentation level as the function definitions: it is not part of the function.
link_or_copy = shutil.copy | |
link_or_copy = shutil.copy |
src/ZODB/blob.py
Outdated
except AttributeError: #pragma: no cover | ||
link_or_copy = shutil.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment indicating why we fall back to shutil.copy
here, e.g.:
except AttributeError: #pragma: no cover | |
link_or_copy = shutil.copy | |
except AttributeError: #pragma: no cover | |
# FBO termux on Android. | |
# See https://github.com/zopefoundation/ZODB/issues/257 | |
link_or_copy = shutil.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Just added those comments. I tried to see how the proposed change to blob.py within ZODB works with other python implementations like for iSH for IOS which has Alpine linux as it's underpinnings. Unfortunately, their python is so broken with many dependencies not available that libraries such as ZODB won't even install.
Added notes that point to issue 257. This change is required in order for ZODB to be imported on termux's python implementation which has disables os.link due to compatibility issues with their win32 implementation.
Please take a look at the GitHub Actions test run. There's some linting issues and this PR breaks all Windows tests. |
fixed the two lint errors wrt incorrect usage of # - added space: #pragma to: # pragma - removed extra space: after # see https:// to: # see https://
- fixed the lint errors wrt the use of '#' comments - fixed link_or_copy not being set for any python on Windows, possibly due to the check for sys.platform == 'win32' failing because maybe the sys.platform == 'win64' as an example, rather than 'win32'.
missed the 2 blank lines, lint error
Fixed indent error within if sys.platform == 'win32' for the link_or_copy variable. This should fix the failing python on windows Indented the try: except statements again for the 'else"
There's still a linter failure:
|
whitespace removed from line 954
shutil.rmtree(path) | ||
|
||
link_or_copy = shutil.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last niggle: the empty line separates a function definition from the assignment, so please restore it.
Line added.
blank space removed from empty line.
Why would a 5 line fix that is nothing more than a try/except wrapper around the setting of a variable, trigger a Sphinx extension loading error like this one? Could not import extension sphinxcontrib.zopeext.autointerface (exception: cannot import name 'ObjectMembers' from 'sphinx.ext.autodoc' (/home/runner/work/ZODB/ZODB/.tox/docs/lib/python3.9/site-packages/sphinx/ext/autodoc/init.py)) What if I were to destroy my fork of zodb , create another fork, create a pull request on the new fork which includes the recommended change as one clean commit? Could it be that the fork is the problem? |
Bandung wrote at 2023-8-26 20:36 -0700:
Why would a 5 line fix that is nothing more than a try/except wrapper around the setting of a variable, trigger a Sphinx extension loading error like this one?
Could not import extension sphinxcontrib.zopeext.autointerface (exception: cannot import name 'ObjectMembers' from 'sphinx.ext.autodoc' (/home/runner/work/ZODB/ZODB/.tox/docs/lib/python3.9/site-packages/sphinx/ext/autodoc/__init__.py))
This looks like a version mismatch problem.
A missing "version pin" is the main cause for such problems.
The missing version pin can result in the installation of different
versions in different environments.
Without a version pin, incompatibilities between a newer and an
older version occasionally let newer test runs fail that
have succeeded earlier.
The test failure you observe has nothing to do with your change.
It affects only the documentation generation. The cause is likely
an incompatibility of a newer `sphinx` version (the documentation
generation tool).
When I hit such a case and do not see an obvious fix, I (mostly) ignore
the error, write a PR comment for people more familiar with
the respective failure area and then continue in the normal PR process.
|
This fix works for any installation of ZODB on unspecified platforms like Android. It is proposed for the termux version of ZODB.
While a pip install zodb within the termux distro for Android completes without incident, it fails to run since any attempts to import ZODB within termux's python fails. This is because their python's os.link has been disabled for some cross platform reason related to Windows.
The only ZODB library code which uses os.link is in ZODB.blob.py where it is selected as the value for the link_or_copy name on Posix systems. On Windows systems, it is mapped to shutil.copy.
This pull request extends the mapping of link_or_copy to shutil.copy for Android, not by attempting to identify the platform as Android, but by attempting a try:except snippet.
Closes #257.