Skip to content
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

Use old upload endpoint until quetz release #9

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test-readme.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/test-readme.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies:
- sphinx
- sphinxcontrib-apidoc
- sphinx_rtd_theme
- quetz >=0.4.0
- pytest-mock
- requests-mock
- httpx
Expand Down
19 changes: 6 additions & 13 deletions src/quetz_client/client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
8 changes: 2 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re

import pytest

from quetz_client.client import Channel, ChannelMember, QuetzClient
Expand Down Expand Up @@ -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",
Expand Down