diff --git a/.github/workflows/test-readme.sh b/.github/workflows/test-readme.sh new file mode 100644 index 0000000..aee8fbf --- /dev/null +++ b/.github/workflows/test-readme.sh @@ -0,0 +1,24 @@ +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 install quetz +micromamba install -y sqlalchemy=1.4.46 + +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 diff --git a/.github/workflows/test-readme.yml b/.github/workflows/test-readme.yml new file mode 100644 index 0000000..f2eec10 --- /dev/null +++ b/.github/workflows/test-readme.yml @@ -0,0 +1,27 @@ +name: Run quetz README + +on: + workflow_dispatch: + +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 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 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",