Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Update blob.py #390

wants to merge 11 commits into from

Conversation

BandungBB
Copy link

@BandungBB BandungBB commented Aug 10, 2023

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.

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
Comment on lines 945 to 948
try:
link_or_copy = shutil.copy
except AttributeError: #pragma: no cover
link_or_copy = shutil.copy
Copy link
Member

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

Copy link
Author

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
Copy link
Member

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.

Suggested change
link_or_copy = shutil.copy
link_or_copy = shutil.copy

src/ZODB/blob.py Outdated
Comment on lines 951 to 952
except AttributeError: #pragma: no cover
link_or_copy = shutil.copy
Copy link
Member

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

Suggested change
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

Copy link
Author

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.
@dataflake
Copy link
Member

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"
@dataflake
Copy link
Member

There's still a linter failure:

lint: commands[1]> flake8 src setup.py
src/ZODB/blob.py:945:1: W293 blank line contains whitespace
src/ZODB/blob.py:954:64: W291 trailing whitespace

whitespace removed from line 954
src/ZODB/blob.py Outdated Show resolved Hide resolved
Comment on lines 944 to 945
shutil.rmtree(path)

link_or_copy = shutil.copy
Copy link
Member

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.
@BandungBB
Copy link
Author

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?

@d-maurer
Copy link
Contributor

d-maurer commented Aug 27, 2023 via email

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.

zodb install on termux linux for Android doesn't work due to no os.link
5 participants