Skip to content

Conversation

@jwhonce
Copy link
Member

@jwhonce jwhonce commented May 11, 2018

  • More pythonic
  • Leverage context managers to help with socket leaks
  • Add system unittest's
  • Add image unittest's
  • Add container unittest's
  • Add models for system, containers and images, and their collections
  • Add helper functions for datetime parsing/formatting
  • GetInfo() implemented will need updated when actual code on master
  • setuptools support added for packaging

Todo:

  • coverage
  • documentation
  • remove test/varlink

Signed-off-by: Jhon Honce jhonce@redhat.com

@jwhonce jwhonce requested review from baude and mheon May 11, 2018 00:57
@jwhonce jwhonce self-assigned this May 11, 2018
@mheon
Copy link
Member

mheon commented May 11, 2018

@jwhonce I'll give it a review, but I warn you it's been years since I did serious work in Python 😄

Copy link
Contributor

@wking wking left a comment

Choose a reason for hiding this comment

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

I've only made it up to libs/images.py, but here are some initial suggestions. I'm not a maintainer, so feel free to ignore anything that doesn't seem useful ;).

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just call it libpod, and have it's Python-ness implied by it's presence in PyPI? import libpod, called from Python, is not going to pull in a Go library by mistake ;).

Copy link
Member Author

Choose a reason for hiding this comment

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

@wking I cargo-culted that from pypi where there are a lot of libraries that are so named. I would be game for calling the git directory pylibpod and the python module libpod. @baude votes?

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a relative link:

See [libpod](../../).

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use SemVer and start with 0.1.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen __title__ before. Can you link to docs or such discussing it? I'd expect the package name to be sufficient without repeating it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@wking pkutils use it. If the final packager we use doesn't support this then I'll remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@wking pkutils use it.

I've filed reubano/pkutils#2 to make it optional ;).

Copy link
Contributor

Choose a reason for hiding this comment

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

I find these imports easier to maintain if you put each imported symbol on its own line:

from .libs.errors import (
    ContainerNotFound,
    ErrorOccurred,
    ImageNotFound,
    RuntimeError,
)

That way it's easier to use your editor to alphabetize and you don't have to worry about re-wrapping as you add/remove symbols.

Alternatively, you could stay DRY by defining __all__ in these subpackages and then using a wildcard import here:

from .libs.errors import *

Copy link
Member

Choose a reason for hiding this comment

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

++

Copy link
Member Author

@jwhonce jwhonce May 11, 2018

Choose a reason for hiding this comment

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

@wking My IDE (atom/python-ide) already sorts imported objects, unfortunately the formatter won't keep them as a list. I'll take a todo to research this. IDE too productive to dump. :)

I missed I had all vs __all__ defined. Fixed that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ellipsis a TODO?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

Choose a reason for hiding this comment

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

You have 'returncode' here and exitcode below. POSIX isn't always consistent about this, but they use "exit status" in several places (e.g. here and here). Maybe we should use:

Wait for the container to finish and return its exit status.

here?

Copy link
Member Author

@jwhonce jwhonce May 11, 2018

Choose a reason for hiding this comment

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

I chose returncode here because that is what the subprocess module uses.

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like something that is going to need arguments (e.g. whether or not to follow a stream, or whether to only get the last n lines). But maybe those aren't supported by the varlink API yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

@wking Correct, once we have streaming there will be changes. I added *args, **kwargs to better future proof this method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to pass *args and **kwargs through here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@wking They are on the method signature waiting on this varlink method to be implemented. A bit of future-proofing.

Copy link
Contributor

Choose a reason for hiding this comment

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

If data contains an id key, why bother with _id and __init__'s separate id argument/

Copy link
Member Author

Choose a reason for hiding this comment

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

@wking I had intended it as a check that the data passed in matched the requested id. I'm on the fence whether this paranoia is worth the hassle. @baude thoughts?

Makefile Outdated
Copy link
Member

Choose a reason for hiding this comment

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

is this change needed?

Copy link
Member Author

@jwhonce jwhonce May 11, 2018

Choose a reason for hiding this comment

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

I removed the pushd/popd calls.

Copy link
Member

Choose a reason for hiding this comment

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

add model for consistency

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

does it make sense to combine these two into a return? dealers choice

Copy link
Member Author

Choose a reason for hiding this comment

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

@baude I've kept them separate for two reasons:

  1. the client socket connection is open for the duration of the with statement. So I've coded that to be the minimum number statements for the day when we go remote. processes() could have yielded within the with, but then the connection to podman would be open until the caller exhausted the list of processes.
  2. I personally don't like the style of method()[0] unless the method call is trivial. :)

@baude
Copy link
Member

baude commented May 11, 2018

@jwhonce big undertaking, good work!

@jwhonce
Copy link
Member Author

jwhonce commented May 11, 2018

@wking @baude Thanks for taking the time for the initial review!

@mheon
Copy link
Member

mheon commented May 11, 2018

@jwhonce Gitvalidation is complaining about whitespace errors in one of your commits

@jwhonce jwhonce force-pushed the wip/python_client branch 3 times, most recently from f673797 to 0666aba Compare May 12, 2018 05:14
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called CrioTestCase? Does this require Crio?

@rhatdan
Copy link
Member

rhatdan commented May 12, 2018

Jhon great work, love all of the tests. Only question is why call this stuff Crio?

@jwhonce jwhonce force-pushed the wip/python_client branch from 0666aba to cfa81f2 Compare May 12, 2018 21:13
@jwhonce
Copy link
Member Author

jwhonce commented May 12, 2018

@rhatdan History. Named changed to reflect current usage.

@TomasTomecek
Copy link
Contributor

Really nice work! Will this be a dedicated library?

Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph should not be indented. And you might want to just copy the root LICENSE file here anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want a terminal . here.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be:

```console
$ python3 setup.py clean -a && python3 setup.py bdist_wheel
```

or

```sh
python3 setup.py clean -a && python3 setup.py bdist_wheel
```

The python syntax highlighting is for content that can be parsed as valid Python, but your line is POSIX shell syntax invoking Python.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, my editor autofilled something wrong and then I corrected it to something wrong. :)

Copy link
Member

Choose a reason for hiding this comment

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

Typo: hanlded -> handled

Copy link
Member

@mheon mheon left a comment

Choose a reason for hiding this comment

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

Weak LGTM - I'm not comfortable enough with Python to really do a proper review.

@jwhonce jwhonce force-pushed the wip/python_client branch from cfa81f2 to 4d689ba Compare May 14, 2018 15:14
@rhatdan
Copy link
Member

rhatdan commented May 14, 2018

My biggest request is the library needs to be named podman

import podman

No one knows what libpod is, and libpod means something different. I would figure libpod python bindings would give me access to some of the internals or databases of libpod.

Change the name to podman and we can merge this. (Although I like the idea of calling it podcast, but that would confuse users.)

@jwhonce jwhonce force-pushed the wip/python_client branch from 4d689ba to 348f920 Compare May 14, 2018 21:58
@jwhonce jwhonce changed the title Refactor libpod python varlink bindings Refactor podman python varlink bindings May 14, 2018
@jwhonce jwhonce force-pushed the wip/python_client branch from 348f920 to c31a69b Compare May 14, 2018 22:18
@mheon mheon mentioned this pull request May 14, 2018
@jwhonce jwhonce force-pushed the wip/python_client branch 5 times, most recently from 2144a03 to aa21e08 Compare May 15, 2018 01:01
@jwhonce
Copy link
Member Author

jwhonce commented May 15, 2018

@rh-atomic-bot retry

@giuseppe
Copy link
Member

giuseppe commented May 15, 2018

bot, please retest

@baude
Copy link
Member

baude commented May 15, 2018

bot, retest this please

@mheon
Copy link
Member

mheon commented May 15, 2018

@jwhonce Are the Travis failures flakes, or actual misconfiguration? It looks like it's throwing errors in the Python tests for the varlink bindings?

- More pythonic
- Leverage context managers to help with socket leaks
- Add system unittest's
- Add image unittest's
- Add container unittest's
- Add models for system, containers and images, and their collections
- Add helper functions for datetime parsing/formatting
- GetInfo() implemented
- Add support for setuptools
- Update documentation
- Support for Python 3.4-3.6

Signed-off-by: Jhon Honce <jhonce@redhat.com>
@jwhonce jwhonce force-pushed the wip/python_client branch from aa21e08 to 814c6af Compare May 15, 2018 22:31
@jwhonce
Copy link
Member Author

jwhonce commented May 15, 2018

@mheon Python version support issue. Code downgraded for Python 3.4 support.

@mheon
Copy link
Member

mheon commented May 15, 2018

Tests seem to be green. I'll leave final decision on merge to @baude as our resident varlink expert.

@baude
Copy link
Member

baude commented May 16, 2018

@rh-atomic-bot r+

@rh-atomic-bot
Copy link
Collaborator

📌 Commit 814c6af has been approved by baude

@rh-atomic-bot
Copy link
Collaborator

⌛ Testing commit 814c6af with merge 1aaf8df...

@rh-atomic-bot
Copy link
Collaborator

☀️ Test successful - status-papr
Approved by: baude
Pushing 1aaf8df to master...

@wking wking mentioned this pull request May 16, 2018
@jwhonce jwhonce deleted the wip/python_client branch January 28, 2020 21:16
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants