From ad91b7ce4b7e9da15592d759d8cfabdddb437a33 Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 15:41:26 +0000 Subject: [PATCH 1/6] use old endpoint --- src/quetz_client/client.py | 19 ++++++------------- tests/test_client.py | 8 ++------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/quetz_client/client.py b/src/quetz_client/client.py index b0106fc..7b6a815 100644 --- a/src/quetz_client/client.py +++ b/src/quetz_client/client.py @@ -1,8 +1,7 @@ -import hashlib from dataclasses import dataclass from itertools import count from pathlib import Path -from typing import Dict, Iterator, List, Mapping, Optional, Union +from typing import BinaryIO, Dict, Iterator, List, Mapping, Optional, Tuple, Union import requests @@ -164,18 +163,12 @@ def yield_packages( yield Package(**user_json) def post_file_to_channel(self, channel: str, file: Path, force: bool = False): - url = f"{self.url}/api/channels/{channel}/upload/{file.name}" - body = open(file, "rb") - - upload_hash = hashlib.sha256(body.read()).hexdigest() - - params: Dict[str, Union[str, int]] = { - "force": force, - "sha256": upload_hash, - } + url = f"{self.url}/api/channels/{channel}/files/" + files: List[Tuple[str, Union[BinaryIO, Tuple]]] = [("files", open(file, "rb"))] + if force: + files.append(("force", (None, "true"))) response = self.session.post( url=url, - data=body, - params=params, + files=files, # type: ignore ) response.raise_for_status() diff --git a/tests/test_client.py b/tests/test_client.py index 32e2f3c..c3ab0b0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,3 @@ -import re - import pytest from quetz_client.client import Channel, ChannelMember, QuetzClient @@ -183,10 +181,8 @@ def test_post_file_to_channel( ): channel = "a" - url_matcher = re.compile( - f"{test_url}/api/channels/{channel}/upload/\\w*\\?force=False&sha256=\\w*" - ) - requests_mock.register_uri("POST", url_matcher, json=None) + url = f"{test_url}/api/channels/{channel}/files/" + requests_mock.post(url, json=None) requests_mock.register_uri( "GET", From c30e92f666de16976e20eea17eb682029ca24e5e Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 15:47:10 +0000 Subject: [PATCH 2/6] add readme script --- .github/workflows/test-readme.sh | 25 +++++++++++++++++++++++++ .github/workflows/test-readme.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/test-readme.sh create mode 100644 .github/workflows/test-readme.yml diff --git a/.github/workflows/test-readme.sh b/.github/workflows/test-readme.sh new file mode 100644 index 0000000..65a557f --- /dev/null +++ b/.github/workflows/test-readme.sh @@ -0,0 +1,25 @@ +set -e + +# Run the steps described in the quetz README.md for uploading and installing a sample package + +git clone https://github.com/mamba-org/quetz.git + +pip install -e ./quetz-client +# micromamba uninstall -y quetz +micromamba install -y sqlalchemy=1.4.46 +pip install -e ./quetz + +quetz run test_quetz --copy-conf ./quetz/dev_config.toml --dev --reload > quetz.log & +sleep 10 +export QUETZ_API_KEY=$(sed -n 's/.*key created for user.*: \(.*\)/\1/p' quetz.log) +# echo "PRINTING API KEY" +# echo $QUETZ_API_KEY +export QUETZ_SERVER_URL=http://localhost:8000 + +bash ./quetz/download-test-package.sh + +quetz-client post_file_to_channel channel0 xtensor/linux-64/xtensor-0.16.1-0.tar.bz2 xtensor/osx-64/xtensor-0.16.1-0.tar.bz2 + +sleep 2 + +micromamba install --override-channels --strict-channel-priority -c http://localhost:8000/get/channel0 -c conda-forge xtensor \ No newline at end of file diff --git a/.github/workflows/test-readme.yml b/.github/workflows/test-readme.yml new file mode 100644 index 0000000..7c64cb8 --- /dev/null +++ b/.github/workflows/test-readme.yml @@ -0,0 +1,27 @@ +name: Run quetz README + +on: + pull_request: + +defaults: + run: + shell: bash -l {0} + +jobs: + test-readme: + name: Run quetz README + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.3.0 + with: + path: quetz-client + + - name: Install mamba & create environment + uses: mamba-org/provision-with-micromamba@v15 + with: + cache-env: true + environment-file: quetz-client/environment.yml + + - name: Run README script + run: | + bash ./quetz-client/.github/workflows/test-readme.sh From 3fe0bf3b9d8c11893d859d5aad2cf71bbdf826a3 Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 15:52:14 +0000 Subject: [PATCH 3/6] use quetz release version --- .github/workflows/test-readme.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-readme.sh b/.github/workflows/test-readme.sh index 65a557f..224df78 100644 --- a/.github/workflows/test-readme.sh +++ b/.github/workflows/test-readme.sh @@ -5,9 +5,8 @@ set -e git clone https://github.com/mamba-org/quetz.git pip install -e ./quetz-client -# micromamba uninstall -y quetz +micromamba install quetz micromamba install -y sqlalchemy=1.4.46 -pip install -e ./quetz quetz run test_quetz --copy-conf ./quetz/dev_config.toml --dev --reload > quetz.log & sleep 10 From 6b489120680964e4641efa1173dab3285aa75085 Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 15:54:17 +0000 Subject: [PATCH 4/6] change ci trigger --- .github/workflows/test-readme.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-readme.yml b/.github/workflows/test-readme.yml index 7c64cb8..f2eec10 100644 --- a/.github/workflows/test-readme.yml +++ b/.github/workflows/test-readme.yml @@ -1,7 +1,7 @@ name: Run quetz README on: - pull_request: + workflow_dispatch: defaults: run: From 6f9521898fb99985a244c65508f418eecdab1a7c Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 16:30:33 +0000 Subject: [PATCH 5/6] remove quetz as requirement and add compat notice --- README.md | 10 +++++++++- environment.yml | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65dee4f..4d090d8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ # quetz-client -A Python client to interact with a Quetz server. +A Python client to interact with a Quetz server. Compatible with `quetz>=0.4.0`. ## Installation +### From conda-forge + +```bash +mamba install quetz-client +``` + +### From this repo + You can install the package in development mode using: ```bash diff --git a/environment.yml b/environment.yml index 54171f8..c902bbf 100644 --- a/environment.yml +++ b/environment.yml @@ -14,7 +14,6 @@ dependencies: - sphinx - sphinxcontrib-apidoc - sphinx_rtd_theme - - quetz >=0.4.0 - pytest-mock - requests-mock - httpx From fb91b4c1735b216d300193b1984be5c346a367bb Mon Sep 17 00:00:00 2001 From: Simon Bohnen Date: Mon, 13 Feb 2023 16:32:27 +0000 Subject: [PATCH 6/6] add newline --- .github/workflows/test-readme.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-readme.sh b/.github/workflows/test-readme.sh index 224df78..aee8fbf 100644 --- a/.github/workflows/test-readme.sh +++ b/.github/workflows/test-readme.sh @@ -21,4 +21,4 @@ quetz-client post_file_to_channel channel0 xtensor/linux-64/xtensor-0.16.1-0.tar sleep 2 -micromamba install --override-channels --strict-channel-priority -c http://localhost:8000/get/channel0 -c conda-forge xtensor \ No newline at end of file +micromamba install --override-channels --strict-channel-priority -c http://localhost:8000/get/channel0 -c conda-forge xtensor