-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for pulling from http location. #61
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7fd444e
Add support for pulling from http location.
plietar 005d056
Fix old pythons
plietar a3bfd4a
Fix test
plietar 752c527
Fix old pythons
plietar 33913cc
test new python versions
plietar dc67c65
Remove 3.8 support
plietar 2474305
Install outpack_server in CI.
plietar 9cfb458
Remove leftover log
plietar dac2f05
Use pre-resolved binary
plietar 4953d4a
Remove leftover log
plietar cba3db2
Fix on Windows.
plietar 2c950a1
Improve coverage
plietar 7706baf
fix format
plietar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ name = "pyorderly" | |
| dynamic = ["version"] | ||
| description = "Reproducible and collaborative reporting" | ||
| readme = "README.md" | ||
| requires-python = ">=3.7" | ||
| requires-python = ">=3.9" | ||
| license = "MIT" | ||
| keywords = [] | ||
| authors = [ | ||
|
|
@@ -16,11 +16,12 @@ authors = [ | |
| classifiers = [ | ||
| "Development Status :: 4 - Beta", | ||
| "Programming Language :: Python", | ||
| "Programming Language :: Python :: 3.7", | ||
| "Programming Language :: Python :: 3.8", | ||
| "Programming Language :: Python :: 3.9", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Programming Language :: Python :: Implementation :: CPython", | ||
| "Programming Language :: Python :: Implementation :: PyPy", | ||
| ] | ||
|
|
@@ -33,6 +34,8 @@ dependencies = [ | |
| "humanize", | ||
| "tblib", | ||
| "paramiko", | ||
| "requests", | ||
| "typing-extensions", | ||
| ] | ||
|
|
||
| [project.urls] | ||
|
|
@@ -46,15 +49,16 @@ path = "src/pyorderly/__about__.py" | |
| [tool.hatch.envs.default] | ||
| dependencies = [ | ||
| "coverage[toml]>=6.5", | ||
| "myst-parser", | ||
| "pytest", | ||
| "pytest_mock", | ||
| "pytest-unordered", | ||
| "pytest-cov", | ||
| "pytest-unordered", | ||
| "pytest_mock", | ||
| "responses", | ||
| "sphinx", | ||
| "sphinx-rtd-theme", | ||
| "myst-parser", | ||
| "sphinx-autoapi", | ||
| "sphinx-copybutton", | ||
| "sphinx-autoapi" | ||
| "sphinx-rtd-theme", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really need to get the docs up to spec at some point :( |
||
| ] | ||
| [tool.hatch.envs.default.scripts] | ||
| test = "pytest {args:tests}" | ||
|
|
@@ -75,7 +79,7 @@ generate-docs = [ | |
| ] | ||
|
|
||
| [[tool.hatch.envs.all.matrix]] | ||
| python = ["3.7", "3.8", "3.9", "3.10", "3.11"] | ||
| python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | ||
|
|
||
| [tool.hatch.envs.lint] | ||
| extra-dependencies = [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import shutil | ||
| from typing import Dict, List | ||
| from urllib.parse import urljoin | ||
|
|
||
| import requests | ||
| from typing_extensions import override | ||
|
|
||
| from pyorderly.outpack.location_driver import LocationDriver | ||
| from pyorderly.outpack.metadata import MetadataCore, PacketFile, PacketLocation | ||
|
|
||
|
|
||
| def raise_http_error(response: requests.Response): | ||
| if response.headers.get("Content-Type") == "application/json": | ||
| result = response.json() | ||
| # Unfortunately the schema is a bit inconsistent. Packit uses a | ||
| # singular `error` whereas outpack_server uses a list of | ||
| # `errors`. | ||
| if "error" in result: | ||
| detail = result["error"]["detail"] | ||
| else: | ||
| detail = result["errors"][0]["detail"] | ||
|
|
||
| msg = f"{response.status_code} Error: {detail}" | ||
| raise requests.HTTPError(msg) | ||
| else: | ||
| response.raise_for_status() | ||
|
|
||
|
|
||
| class OutpackHTTPClient(requests.Session): | ||
| def __init__(self, url: str, authentication=None): | ||
| super().__init__() | ||
| self._base_url = url | ||
| self._authentication = authentication | ||
|
|
||
| @override | ||
| def request(self, method, path, *args, **kwargs): | ||
| if self._authentication is not None: | ||
| headers = kwargs.setdefault("headers", {}) | ||
| headers.update(self._authentication()) | ||
|
|
||
| url = urljoin(self._base_url, path) | ||
| response = super().request(method, url, *args, **kwargs) | ||
| if not response.ok: | ||
| raise_http_error(response) | ||
| return response | ||
|
|
||
|
|
||
| class OutpackLocationHTTP(LocationDriver): | ||
| def __init__(self, url: str, authentication=None): | ||
| self._base_url = url | ||
| self._client = OutpackHTTPClient(url, authentication) | ||
|
|
||
| def __enter__(self): | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *args): | ||
| self._client.__exit__(*args) | ||
|
|
||
| @override | ||
| def list(self) -> Dict[str, PacketLocation]: | ||
| response = self._client.get("metadata/list").json() | ||
| data = response["data"] | ||
| return { | ||
| entry["packet"]: PacketLocation.from_dict(entry) for entry in data | ||
| } | ||
|
|
||
| @override | ||
| def metadata(self, ids: List[str]) -> Dict[str, str]: | ||
| result = {} | ||
| for i in ids: | ||
| result[i] = self._client.get(f"metadata/{i}/text").text | ||
|
|
||
| return result | ||
|
|
||
| @override | ||
| def fetch_file(self, packet: MetadataCore, file: PacketFile, dest: str): | ||
| response = self._client.get(f"file/{file.hash}", stream=True) | ||
| with open(dest, "wb") as f: | ||
| shutil.copyfileobj(response.raw, f) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice!