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

Add events task #76

Merged
merged 2 commits into from
Aug 1, 2017
Merged

Add events task #76

merged 2 commits into from
Aug 1, 2017

Conversation

cecton
Copy link
Contributor

@cecton cecton commented Jul 25, 2017

What These Changes Do

  1. Explicit loop
  2. Fix a problem with ClientResponse is not a coroutine
  3. DockerEvents automatically create and cancel a background task by default (breaking change)

@@ -86,8 +86,8 @@ def __init__(self,
self.images = DockerImages(self)
self.volumes = DockerVolumes(self)

async def close(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please revert it back.
session.close() is a coroutine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov sorry it's a work in progress, don't waste your time looking at it at the moment. Thanks for the remark though I was totally mistaking.

@cecton cecton force-pushed the add-events-task branch 3 times, most recently from d82456b to d278c31 Compare July 25, 2017 13:52
@codecov
Copy link

codecov bot commented Jul 25, 2017

Codecov Report

Merging #76 into master will increase coverage by 0.63%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
+ Coverage   76.92%   77.56%   +0.63%     
==========================================
  Files          12       12              
  Lines         715      722       +7     
==========================================
+ Hits          550      560      +10     
+ Misses        165      162       -3
Impacted Files Coverage Δ
aiodocker/jsonstream.py 94.28% <100%> (+2.85%) ⬆️
aiodocker/docker.py 69.46% <100%> (+1.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5defebb...18ba173. Read the comment docs.

@barrachri
Copy link

@cecton just ping when the PR is ready for the review.

@cecton cecton force-pushed the add-events-task branch 3 times, most recently from 5e31d94 to 20965e0 Compare July 26, 2017 09:24
@cecton
Copy link
Contributor Author

cecton commented Jul 26, 2017

@barrachri ping

So here is the idea I had in #34 : 20965e0

But to do that I had to add the event loop to the Docker instance: 7097cb1

And I also installed tox, removed the need of Docker Compose and made all the test in test_images.py unrelated to each other (so you can run them seperately): bb24437

I also made a lot of changes in the requirements files:

  • I added requirements.txt: a single place where you put only the library's requirements
  • I added requirements/test.txt: a single place where you put only the requirements for running the tests
  • I replaced requirements/ci.txt: it is now a single place without versions where you put the requirements for the CI (codecov)

But I have no idea why setuptools is in the requirements to be honest. I saw that the bot is updating its version but setuptools is only used in the CI itself. It doesn't make much sense to me, I would remove it if I were you.

Also I'm a bit concerned about how the event monitoring is closed. Is the user supposed to call stop() before closing the Docker instance? Why it's not in the close() of the Docker class directly? In the test in integration you just don't call it and it seems work but when I removed the task handling I noticed that the task is destroyed. So I suppose the json_stream was never closed properly explicitly.

@cecton
Copy link
Contributor Author

cecton commented Jul 26, 2017

Hmmm.... I just spotted something fishy with a try...except: pass... there will be more fixes in this PR.

Done.

@cecton cecton changed the title WIP Add events task Add events task Jul 27, 2017
@@ -42,7 +42,23 @@ def __init__(self,
connector=None,
session=None,
ssl_context=None,
api_version='v1.26'):
api_version='v1.26',
loop=None):
Copy link
Member

Choose a reason for hiding this comment

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

Using implicit loop is preferable technique starting from python 3.5.3
aiodocker is a new library, we don't need to pass loop everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know that... look what I found on the web when trying to find more information: https://groups.google.com/forum/#!topic/python-tulip/yF9C-rFpiKk

Copy link
Member

Choose a reason for hiding this comment

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

requirements.txt Outdated
@@ -0,0 +1,2 @@
aiohttp==2.2.3
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this file.
If you need new requirement -- please put it into requirements folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

requirements.txt is more generally used in Python projects when you look for the requirements. I expect most Python developers to expect either a requirements.txt or no requirements.txt at all because the dependencies are in the setup.py.

My true goal here is only to get one place to maintain the dependencies. I can move it to requirements/base.txt or something if you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

Our requirements are for aiodocker developers, users install the library by pip install aiodocker without explicitly looking into requirement files at all.
Thus doesn't matter where we do place the file.
If we have everything in requirements folder -- let's put base requirements there.
requirements/base.txt sounds pretty good.

setup.py Outdated
extras_require={
'test': ['pytest', 'pytest-asyncio', 'flake8'],
}
install_requires=requirements,
Copy link
Member

Choose a reason for hiding this comment

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

I suspect the library should not pin own requirements -- otherwise we need publish new aiodocker on every yarl/aiohttp update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevertheless the lib work with some versions but not all. For aiohttp I suppose we are following semantic versioning so maybe we could use <2.3. What do you think would be best? Simply removing any version restriction?

Copy link
Member

Choose a reason for hiding this comment

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

Relax it to non-strict check, e.g. aiohttp>=2.0 where 2.0 is minimal supported version.
Sorry, I don't follow what minimal aiohttp version is supported by aiodocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will figure that out easily with tox

Copy link
Contributor Author

@cecton cecton Jul 27, 2017

Choose a reason for hiding this comment

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

2.0.0 works, 1.3.5 failed

@asvetlov
Copy link
Member

Yes, setuptools is not needed in requirements

@asvetlov
Copy link
Member

Other thing: I think better to split new feature (a task for events monitoring) and improvements of existing infrastructure.

@@ -42,7 +42,7 @@ def __aiter__(self):
# (see https://github.com/KeepSafe/aiohttp/issues/739)

# response error , it has been closed
await self._response.close()
self._response.close()
Copy link

@barrachri barrachri Jul 26, 2017

Choose a reason for hiding this comment

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

Did you forget await?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I actually fixed it. This is no coroutine apparently and the try...except...pass on the top level was hiding the exception. Commit message: 1d3abd8

import asyncio

import pytest

Choose a reason for hiding this comment

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

import asyncio

import aiohttp
import aiodocker
import pytest

from io import BytesIO
from aiodocker import utils
from aiodocker.exceptions import DockerError


def _random_name():

Choose a reason for hiding this comment

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

Great idea 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx ^_^

@@ -1,21 +1,25 @@
import pytest
import uuid

Choose a reason for hiding this comment

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

import uuid
from io import BytesIO

import pytest
from aiodocker import utils
from aiodocker.exceptions import DockerError

async for output in stream:
if "Successfully tagged image:1.0\n" in output:
break
async for _ in stream: # noqa: F841

Choose a reason for hiding this comment

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

why looping if you don't check also the output of the stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the funny part of this PR. If you don't loop, you're image will not finish to build and the code will break. Maybe that only happens if the stream=True is active though. I know it's the case for docker-py and I just checked with a big image with aiodocker and it behaves the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the funny part is that the previous code has problems too. I first tried to use it and catch from the output and assert on the output. But I realized that the "output" is no string, it's a dict, and my assert failed. The actual log line is in output['stream'].

So I updated the code and then the test failed because depending on the version of Docker, you may get an upper case, a lower case here and there, etc...

So in the end I felt like the only interesting thing to do here is to wait for the build to complete because this for loop doesn't actually do anything else than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So actually we can remove the for loop with the stream=True and it will behave the same.

@pytest.mark.asyncio
async def test_build_from_remote_file(docker):
remote = ("https://raw.githubusercontent.com/aio-libs/"
"aiodocker/master/tests/docker/Dockerfile")

tag = "image:1.0"
tag = "%s:1.0" % _random_name()

Choose a reason for hiding this comment

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

Can you switch to "".format()?

I just like to be consistent around the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked that in the past and apparently the devs at Python don't want to drop the % syntax because is handy and small to use. Plus they even added a new one:

you = "barrachri"
print(f"Hello {you}")

So.... well I disagree but I really don't mind at all changing it for consistency sake.

Copy link

@barrachri barrachri Jul 27, 2017

Choose a reason for hiding this comment

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

As I said it just a matter of consistency :)
Remember that is .format() and not f"", that is available only from python 3.6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but % is not going to be deprecated and is available ^_^ but anyway...

@cecton cecton force-pushed the add-events-task branch 3 times, most recently from f1778d7 to f151ffa Compare July 29, 2017 08:25
@cecton
Copy link
Contributor Author

cecton commented Jul 29, 2017

@asvetlov @barrachri okay, ready for review.

try:
await self.json_stream.close()
except:
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@barrachri the error in the close() used to be hidden by this try...except: pass

Choose a reason for hiding this comment

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

Ok, it seems harmless, I'll check this .close() in the future PRs.

@barrachri
Copy link

@cecton I plan to close the review tomorrow, I didn't find time during the weekend :/

@cecton
Copy link
Contributor Author

cecton commented Aug 1, 2017

@barrachri no problem for me! :) Thanks.

To be honest, at this point I'm more evaluating aiodocker to see if I can replace my own one. I'm still very dubious about it especially since I discovered how I can properly override the methods in docker-py.

@asvetlov
Copy link
Member

asvetlov commented Aug 1, 2017

@barrachri please feel free to merge if the PR looks good to you.

BTW we can raise election of @cecton to aiodocker team.
She is a member of aiohttp already, why not?

@barrachri
Copy link

@cecton I re-run the tests after the last merges, there seems to be some errors.

Can you have a look?

@cecton
Copy link
Contributor Author

cecton commented Aug 1, 2017

@barrachri okay I just checked and close() on _JsonStreamResult has been renamed to _close. Should I simply use that one?

@barrachri
Copy link

Yes, thanks!

@cecton
Copy link
Contributor Author

cecton commented Aug 1, 2017

@barrachri done

@barrachri barrachri merged commit db74893 into aio-libs:master Aug 1, 2017
@barrachri
Copy link

Thanks @cecton !

@cecton cecton deleted the add-events-task branch August 1, 2017 20:27
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.

3 participants