-
Notifications
You must be signed in to change notification settings - Fork 30
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
Issue #103: util.state: Implement __await__ and .future #104
Conversation
`.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+).
…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.
@sjlongland it was tagged as "draft" , can we merge ? |
On 1/12/20 11:28 am, Christian Tremblay wrote:
@sjlongland it was tagged as "draft" , can we merge ?
I'd like to try and get some unit tests in there first. Make sure it
works as it should.
|
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.
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!
36bd18a
to
2beebcb
Compare
Keeping state.py for compatibility ? Not sure how this will be called (I don't get the assert...) |
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 ? |
On 20/12/20 7:02 am, Christian Tremblay wrote:
Keeping state.py for compatibility ? Not sure how this will be called (I don't get the assert...)
Well, sort-of. I tried to do it all in `state.py`, but Python 2 threw a
hissy fit over the `await` and `async` keywords. This is primarily a
Python 3 feature, but I don't want to break Python 2 yet (even though
I've told my workplace I won't be writing Py2 code from 2020 onwards).
So I was forced to put it in a separate "module" to "hide" it. It
checks what version of Python is before importing. That said, just
realised I should try actually installing the package too.
Same deal with the tests, you'll see I did the same thing there.
All the `assert` does is keep `pyflakes` from complaining that a symbol
is imported but not used.
|
On 20/12/20 7:04 am, Christian Tremblay wrote:
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 ?
Yeah, that's the other half of the equation, asynchronous HTTP client
glue logic. There's `aiohttp` on Python 3.4+. Tornado also has an
`async` client we could wrap.
Again, I'll put these in their own modules so that they're "hidden" from
Python installs that can't understand the syntax (`yield from`/`await`).
My primary aim in this PR was to make the operations in `ipython` shell
more "natural" by making its `async` support handle `pyhaystack`'s way
of doing async operations.
|
… 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.
Okay, so that last commit takes care of this:
I've moved |
Going forward.... it is a tremendous improvement for what will happen next ! |
.future
returns aFuture
object (either a nativeasyncio
Future
,or a Tornado
Future
), which can beyield
-ed (Tornado on Python <3.4)or
await
-ed (Python 3.5+).TODO: Some unit tests.