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

[#480] Remove Python2 compatibility from code base #640

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

Conversation

d-w-moore
Copy link
Collaborator

With this change, we remove all code meant explicitly to deal with the possibility of the PRC's running under Python 2. Especially the awkward (and sometimes voluminous) parts that interfere with a ready understanding of the code base as a whole.

@d-w-moore d-w-moore marked this pull request as draft October 15, 2024 20:24
@trel
Copy link
Member

trel commented Oct 16, 2024

looking good so far. please assert here how testing goes.

irods/message/__init__.py Outdated Show resolved Hide resolved
@d-w-moore
Copy link
Collaborator Author

looking good so far. please assert here how testing goes.

have already done some piecemeal testing with good results. will run a full test later.

@korydraughn
Copy link
Contributor

Excellent! Keep pushing.

@d-w-moore d-w-moore marked this pull request as ready for review October 17, 2024 15:24
@d-w-moore
Copy link
Collaborator Author

There may still be a few points I haven't thought of, but presently the code is exclusively Python3-compatible (python2 -c"import irods" fails !!) and passes all tests in the suite.

@d-w-moore
Copy link
Collaborator Author

.... now with minimal squashing

@korydraughn
Copy link
Contributor

Amazing work!

We'll start the review process.

Copy link
Contributor

@korydraughn korydraughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Let's get another set of eyes on this before squashing/merging.

Good stuff!

irods/test/data_obj_test.py Show resolved Hide resolved
@korydraughn
Copy link
Contributor

There may still be a few points I haven't thought of, but presently the code is exclusively Python3-compatible (python2 -c"import irods" fails !!) and passes all tests in the suite.

How much does python2 -c"import irods" actually catch? Do you know?

I'm just curious.

rename message.property module to avoid naming conflict

introduce attribute irods.message.property at module EOF.

this avoids corrupting the @Property facility used earlier in the module source file,
and prevents possibility of breaking changes.
All Python3 classes are of the so called new style, ie directly
subclassing "object".  Old-style classes are a Python2 relic.
@d-w-moore
Copy link
Collaborator Author

d-w-moore commented Oct 17, 2024

There may still be a few points I haven't thought of, but presently the code is exclusively Python3-compatible (python2 -c"import irods" fails !!) and passes all tests in the suite.

How much does python2 -c"import irods" actually catch? Do you know?

I'm just curious.

Here's what happens if you try importing the PRC at tip of this branch currently:

Python 2.7.18 (default, Jan 31 2024, 16:23:13) 
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import irods
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/daniel/ppy3/prc/irods/__init__.py", line 85, in <module>
    from . import client_configuration
  File "/home/daniel/ppy3/prc/irods/client_configuration/__init__.py", line 40
    class ConnectionsProperties(iRODSConfiguration, metaclass = iRODSConfigAliasMetaclass):
                                                              ^
SyntaxError: invalid syntax
>>> irods
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'irods' is not defined
>>> 

As a result of the errors evoked, not the irods namespace, nor module, nor any submodules will be imported (as you might well intuit by that last command). Which means all code in the PRC is unavailable to the interpreter under Python2

@d-w-moore
Copy link
Collaborator Author

d-w-moore commented Oct 17, 2024

Amazing work!

We'll start the review process.

Great!...
Btw, I didn't mean to put the" laugh" emoji there. Joy is more what I wanted to express.

@trel
Copy link
Member

trel commented Oct 18, 2024

Can we... be kinder to anyone who might stumble into this by accident...

like...

import sys

if sys.version_info[0] < 3:
    raise RuntimeError("This library is only supported on Python 3 and above.")

But also check the minor version while we're there...

@d-w-moore
Copy link
Collaborator Author

d-w-moore commented Oct 18, 2024

Can we... be kinder to anyone who might stumble into this by accident...

like...

import sys

if sys.version_info[0] < 3:
    raise RuntimeError("This library is only supported on Python 3 and above.")

But also check the minor version while we're there...

Good point. We'll put that into irods/__init__.py . It will work fine even if sub-namespaces are (naively) preferentially imported, because in order to import those, Python needs to import the parent modules first. (In other words, import irods.manager.data_object_manager has to import irods as the first step.

@trel
Copy link
Member

trel commented Oct 18, 2024

nice and clean.

@@ -1,3 +1,8 @@
import sys
if sys.version_info[0] < 3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also check minor version... aka that we're 3.8+.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we settled on 3.8 as a minimum, then? Sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t have to be 3.8. But that feels about right for a new floor. Discush.

Copy link

@FifthPotato FifthPotato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pretty complete to me. Couldn't find anything wrong, so I think it looks good!

setup.py Outdated
@@ -43,7 +43,6 @@
packages=find_packages(),
include_package_data=True,
install_requires=[
'six>=1.10.0',
'PrettyTable>=0.7.2',
'defusedxml',
# - the new syntax:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines following this one read...

                        # - the new syntax:
                        #'futures; python_version == "2.7"'
                        ],
      # - the old syntax:
      extras_require={ ':python_version == "2.7"': ['futures'],
                       'tests': ['unittest-xml-reporting']  # for xmlrunner
                     }

Can we remove all of this now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants