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

Issue #103: util.state: Implement __await__ and .future #104

Conversation

sjlongland
Copy link
Collaborator

.future returns a Future object (either a native asyncio Future,
or a Tornado Future), which can be yield-ed (Tornado on Python <3.4)
or await-ed (Python 3.5+).

TODO: Some unit tests.

`.future` returns a `Future` object (either a native `asyncio` `Future`,
or a Tornado `Future`), which can be `yield`-ed (Tornado on Python <3.4)
or `await`-ed (Python 3.5+).
@sjlongland sjlongland linked an issue Nov 24, 2020 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Nov 24, 2020

Coverage Status

Coverage increased (+0.6%) to 40.148% when pulling 5a5d85a on sjlongland:feature/awaitable-operation into db6406b on ChristianTremblay:develop.

…hon.

Python older than v3.3 does not understand `yield from`, and won't
ignore it inspite of it being in a code path that won't be run for older
releases.

So instead, we have to put it in a completely separate file and convince
Python to hopefully not import it when running on older Python releases.
@ChristianTremblay ChristianTremblay marked this pull request as ready for review December 1, 2020 01:27
@ChristianTremblay
Copy link
Owner

@sjlongland it was tagged as "draft" , can we merge ?

@sjlongland
Copy link
Collaborator Author

sjlongland commented Dec 1, 2020 via email

There are some "extra" features, which are not required for `pyhaystack`
to run, but may make its use more pleasant.

- `pandas`: Installing this drags in a _lot_ of X11-related dependencies
  on Linux-based platforms, so it makes sense to make this "optional"
  for "embedded" use cases where advanced computation is not being
  performed.
- `tornado`: Support for the Tornado IO loop.  Mostly this only matters
  for Python 2.7 users who may still want to drive `pyhaystack`
  asynchronously.
Some of these branches are impossible to test since unless Shrödinger
starts writing Python packages, we can't have a package simultaneously
"installed" and "uninstalled" at the same time.
@sjlongland
Copy link
Collaborator Author

Okay, let's see what Travis CI makes of this. Works fine on Gentoo with Python 2.7.18 and Python 3.8.6.

…low copy.

This allows for objects to be shallow-copied using `__copy__`, instead
of relying on the object having a `.copy` method.
With wrapper to "hide" the tests from Python < 3.5.
`extras_require` should be a `dict` not a `list`, Duh!
@ChristianTremblay
Copy link
Owner

Keeping state.py for compatibility ? Not sure how this will be called (I don't get the assert...)

@ChristianTremblay
Copy link
Owner

Another question, just to be sure, if we want this to work, we'll need an async requests gizmo ? You set up the base, right ?

@sjlongland
Copy link
Collaborator Author

sjlongland commented Dec 19, 2020 via email

@sjlongland
Copy link
Collaborator Author

sjlongland commented Dec 19, 2020 via email

… hide from Python 2.

At the moment, installing `pyhaystack` on Python 2 works, but it throws
an error (which it then ignores) when it tries to "compile" the `.py`
file to `.pyo`.

Since these files have no use in a Python 2 install, let's move them
into a sub-package which we can selectively import if and only if Python
3 is in use.
@sjlongland
Copy link
Collaborator Author

Okay, so that last commit takes care of this:

byte-compiling build/bdist.linux-x86_64/egg/pyhaystack/util/filterbuilder.py to filterbuilder.pyc
byte-compiling build/bdist.linux-x86_64/egg/pyhaystack/util/asyncexc.py to asyncexc.pyc
byte-compiling build/bdist.linux-x86_64/egg/pyhaystack/util/tools.py to tools.pyc
byte-compiling build/bdist.linux-x86_64/egg/pyhaystack/util/awaitableop.py to awaitableop.pyc
  File "build/bdist.linux-x86_64/egg/pyhaystack/util/awaitableop.py", line 20
    res = yield from self.future
                   ^
SyntaxError: invalid syntax

I've moved awaitableop into the pyhaystack.util.awaitable sub-package. Python 2.7 users, it'll omit pyhaystack.util.awaitable, everyone else, it includes it.

@ChristianTremblay ChristianTremblay merged commit 59b28b2 into ChristianTremblay:develop Feb 26, 2021
@ChristianTremblay
Copy link
Owner

Going forward.... it is a tremendous improvement for what will happen next !

@sjlongland sjlongland deleted the feature/awaitable-operation branch June 9, 2021 07:30
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.

Implement __await__ on operation classes
3 participants