-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add events task #76
Conversation
aiodocker/docker.py
Outdated
@@ -86,8 +86,8 @@ def __init__(self, | |||
self.images = DockerImages(self) | |||
self.volumes = DockerVolumes(self) | |||
|
|||
async def close(self): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d82456b
to
d278c31
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@cecton just ping when the PR is ready for the review. |
5e31d94
to
20965e0
Compare
@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 I also made a lot of changes in the requirements files:
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 |
Hmmm.... I just spotted something fishy with a try...except: pass... there will be more fixes in this PR. Done. |
aiodocker/docker.py
Outdated
@@ -42,7 +42,23 @@ def __init__(self, | |||
connector=None, | |||
session=None, | |||
ssl_context=None, | |||
api_version='v1.26'): | |||
api_version='v1.26', | |||
loop=None): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also python/asyncio#452
requirements.txt
Outdated
@@ -0,0 +1,2 @@ | |||
aiohttp==2.2.3 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Yes, setuptools is not needed in requirements |
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget await
?
There was a problem hiding this comment.
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
tests/test_docker.py
Outdated
import asyncio | ||
|
||
import pytest | ||
|
There was a problem hiding this comment.
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
tests/test_images.py
Outdated
from io import BytesIO | ||
from aiodocker import utils | ||
from aiodocker.exceptions import DockerError | ||
|
||
|
||
def _random_name(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx ^_^
tests/test_images.py
Outdated
@@ -1,21 +1,25 @@ | |||
import pytest | |||
import uuid |
There was a problem hiding this comment.
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
tests/test_images.py
Outdated
async for output in stream: | ||
if "Successfully tagged image:1.0\n" in output: | ||
break | ||
async for _ in stream: # noqa: F841 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
tests/test_images.py
Outdated
@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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
f1778d7
to
f151ffa
Compare
@asvetlov @barrachri okay, ready for review. |
try: | ||
await self.json_stream.close() | ||
except: | ||
pass |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@cecton I plan to close the review tomorrow, I didn't find time during the weekend :/ |
@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. |
@barrachri please feel free to merge if the PR looks good to you. BTW we can raise election of @cecton to aiodocker team. |
@cecton I re-run the tests after the last merges, there seems to be some errors. Can you have a look? |
@barrachri okay I just checked and close() on |
Yes, thanks! |
@barrachri done |
Thanks @cecton ! |
What These Changes Do
Explicit loop