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

Remove dependency on obsolete third-party package #47

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

Conversation

claui
Copy link

@claui claui commented Dec 22, 2024

The third-party package future is no longer maintained and considered obsolete due to the end-of-life status of Python 2:

Python 2 reached its end of life in 2020 and the python-future package should no longer be necessary. Use it to help with porting legacy code to Python 3 but don't depend on it for new code.

This PR changes all call sites to use Python 3’s native implementation and removes the future dependency.

Tests

Small self-contained example to prove that the updated code works:

from pygreat import comms

backend = comms.CommsBackend()
core = backend.apis['core']
core.get_available_verbs()

Result:

Traceback (most recent call last):
  File "/home/claudia/Documents/dev/libgreat/test.py", line 5, in <module>
    core.get_available_verbs()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/pygreat/comms.py", line 1123, in method
    return self.execute_command(verb_number, in_format, out_format, name=name, class_name=class_name,
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            timeout=timeout, max_response_length=max_response_length, encoding=encoding, *arguments)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/pygreat/comms.py", line 1278, in execute_command
    return self.comms_backend.execute_command(self.CLASS_NUMBER, verb, in_format,
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            out_format, *arguments, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/pygreat/comms.py", line 777, in execute_command
    raise outer_exception.with_traceback(e.__traceback__) from None
  File "/usr/lib/python3.13/site-packages/pygreat/comms.py", line 770, in execute_command
    payload = self.pack(in_format, *arguments)
  File "/usr/lib/python3.13/site-packages/pygreat/comms.py", line 581, in pack
    result += struct.pack(subformat, *args_consumed)
              ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: invalid arguments in call to RPC `get_available_verbs`; innner message: pack expected 1 items for packing (got 0); format: <I

With syntax highlighting:

image

On Python 3, `future.utils.raise_from` is equivalent to the
`raise … from …` statement. [1]

Replace all invocations so the code depends less on the obsolete [2]
`future` third-party package.

[1]: https://github.com/PythonCharmers/python-future/blob/v1.0.0/src/future/utils/__init__.py#L389-L397

[2]: https://github.com/PythonCharmers/python-future/blob/v1.0.0/README.rst#status
On Python 3, `future.utils.raise_with_traceback` is equivalent to
calling the `with_traceback` method built into `BaseException`. [1] [2]

Replace all invocations so the code has no more dependencies on the
obsolete [3] `future` third-party package.

[1]: https://github.com/PythonCharmers/python-future/blob/v1.0.0/src/future/utils/__init__.py#L446-L449

[2]: https://github.com/PythonCharmers/python-future/blob/v1.0.0/docs/compatible_idioms.rst#raising-exceptions

[3]: https://github.com/PythonCharmers/python-future/blob/v1.0.0/README.rst#status
@antoinevg antoinevg self-requested a review January 6, 2025 14:09
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.

1 participant