-
Notifications
You must be signed in to change notification settings - Fork 6
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 support for Galaxy v3 API #45
Conversation
CC @samccann |
Turns out the v3 API of beta-galaxy.ansible.com is incredibly slow. A simple |
The Galaxy v3 API versions list test is disabled since it is so incredibly slow. Just listing the first page takes 30 seconds (!). The total listing takes > 100 seconds.
@@ -7,9 +7,11 @@ | |||
|
|||
from __future__ import annotations | |||
|
|||
import asyncio | |||
import os.path | |||
import shutil | |||
import typing as t |
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.
There's some instances of old type hinting syntax. Do you have a reason for keeping those or should I point them all out?
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.
The main reason is that this needs to be backported to stable-1, so it's easier to keep them and remove them later (after backporting). Otherwise I have to do the work twice.
cache_path = tmp_path_factory.mktemp('cache') | ||
downloader = CollectionDownloader( | ||
aio_session, | ||
str(download_path), |
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.
Note to self: we should change this API to accept PathLike objects as well in a separate PR.
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.
Fixed in ea50a8d.
class GalaxyContext: | ||
server: str | ||
version: GalaxyVersion | ||
base_url: str | ||
|
||
def __init__(self, server: str, version: GalaxyVersion, base_url: str) -> None: | ||
self.server = server | ||
self.version = version | ||
self.base_url = base_url |
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.
This would be a good candidate for a dataclass. After adding import dataclasses
:
class GalaxyContext: | |
server: str | |
version: GalaxyVersion | |
base_url: str | |
def __init__(self, server: str, version: GalaxyVersion, base_url: str) -> None: | |
self.server = server | |
self.version = version | |
self.base_url = base_url | |
@dataclasses.dataclass | |
class GalaxyContext: | |
server: str | |
version: GalaxyVersion | |
base_url: str |
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.
This is 3.7+, so not backportable. We can do this in a follow-up PR.
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.
Ack. For what it's worth, there's a backport on PyPI that we could add for python_version<'3.7'
, but I don't think that's worth it.
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.
Ack. Thanks!
class GalaxyContext: | ||
server: str | ||
version: GalaxyVersion | ||
base_url: str | ||
|
||
def __init__(self, server: str, version: GalaxyVersion, base_url: str) -> None: | ||
self.server = server | ||
self.version = version | ||
self.base_url = base_url |
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.
Ack. For what it's worth, there's a backport on PyPI that we could add for python_version<'3.7'
, but I don't think that's worth it.
return cls(galaxy_server, version, base_url) | ||
|
||
|
||
_GALAXY_CONTEXT_CACHE: dict[str, t.Union[GalaxyContext, asyncio.Future]] = {} |
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.
This will need to be changed to t.Dict
when backporting.
I forgot to mention this before but it's a known issue that the galaxy beta site is slow. That's one reason they haven't broadcast the announcement yet of things switching over. They are working on improving the performance for sure. |
The curl request from above is down to 10 seconds now, BTW. Still way too slow, but hey, three times faster than a week ago... |
Backport to stable-1: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply af8f28d on top of patchback/backports/stable-1/af8f28d394c63996909c8c7f1caa7f78a7994dc6/pr-45 Backporting merged PR #45 into main
🤖 @patchback |
@gotmax23 thanks for reviewing this! |
* Add support for Galaxy v3 API. * Add integration tests for the Galaxy API. The Galaxy v3 API versions list test is disabled since it is so incredibly slow. Just listing the first page takes 30 seconds (!). The total listing takes > 100 seconds. * Reorganize imports. * Improve docstrings; validate context.server == galaxy_server. * Fix check, update docstring. * According to ansible-galaxy CLI code, the result value can sometimes be called 'results' also for v3. (cherry picked from commit af8f28d)
* Add support for Galaxy v3 API. * Add integration tests for the Galaxy API. The Galaxy v3 API versions list test is disabled since it is so incredibly slow. Just listing the first page takes 30 seconds (!). The total listing takes > 100 seconds. * Reorganize imports. * Improve docstrings; validate context.server == galaxy_server. * Fix check, update docstring. * According to ansible-galaxy CLI code, the result value can sometimes be called 'results' also for v3. (cherry picked from commit af8f28d)
* Add support for Galaxy v3 API (#45) * Add support for Galaxy v3 API. * Add integration tests for the Galaxy API. The Galaxy v3 API versions list test is disabled since it is so incredibly slow. Just listing the first page takes 30 seconds (!). The total listing takes > 100 seconds. * Reorganize imports. * Improve docstrings; validate context.server == galaxy_server. * Fix check, update docstring. * According to ansible-galaxy CLI code, the result value can sometimes be called 'results' also for v3. (cherry picked from commit af8f28d) * Make work with older environments.
Tested by building docs (with antsibull-docs) from a collection on Galaxy where
galaxy_url = "https://beta-galaxy.ansible.com"
is in antsibull-docs.cfg.