From 2b43395c0ed53059559c6d85ace41e74d1ae86b1 Mon Sep 17 00:00:00 2001 From: alaskowski <alaskowski@ethz.ch> Date: Mon, 24 Jul 2023 16:34:19 +0200 Subject: [PATCH] SSDM-13735: fixes to dataset upload, PyBIS-1.36.0 --- api-openbis-python3-pybis/src/python/CHANGELOG.md | 3 ++- .../src/python/pybis/__init__.py | 2 +- api-openbis-python3-pybis/src/python/pybis/dataset.py | 11 +++-------- api-openbis-python3-pybis/src/python/pybis/pybis.py | 9 ++++++++- api-openbis-python3-pybis/src/python/setup.cfg | 2 +- api-openbis-python3-pybis/src/python/setup.py | 3 +-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/api-openbis-python3-pybis/src/python/CHANGELOG.md b/api-openbis-python3-pybis/src/python/CHANGELOG.md index ba02912c3e9..3e9f63a035a 100644 --- a/api-openbis-python3-pybis/src/python/CHANGELOG.md +++ b/api-openbis-python3-pybis/src/python/CHANGELOG.md @@ -1,6 +1,7 @@ ## Changes with pybis-1.36.0 -- Added dependency to requests-toolbelt +- Reverted breaking changes to dataset upload functionality +- Performance improvements to get_sample and get_samples methods ## Changes with pybis-1.35.11 diff --git a/api-openbis-python3-pybis/src/python/pybis/__init__.py b/api-openbis-python3-pybis/src/python/pybis/__init__.py index 82c03f6cb41..8a25c785035 100644 --- a/api-openbis-python3-pybis/src/python/pybis/__init__.py +++ b/api-openbis-python3-pybis/src/python/pybis/__init__.py @@ -15,7 +15,7 @@ name = "pybis" __author__ = "ID SIS • ETH Zürich" __email__ = "openbis-support@id.ethz.ch" -__version__ = "1.36.0rc1" +__version__ = "1.36.0" from . import pybis from .pybis import DataSet diff --git a/api-openbis-python3-pybis/src/python/pybis/dataset.py b/api-openbis-python3-pybis/src/python/pybis/dataset.py index e845406e9af..9ba2f319b59 100644 --- a/api-openbis-python3-pybis/src/python/pybis/dataset.py +++ b/api-openbis-python3-pybis/src/python/pybis/dataset.py @@ -29,7 +29,6 @@ from urllib.parse import urljoin, quote import requests from pandas import DataFrame from requests import Session -from requests_toolbelt.multipart.encoder import MultipartEncoder from tabulate import tabulate from .definitions import ( @@ -1246,13 +1245,9 @@ class DataSetUploadQueue: file_size = os.path.getsize(filename) if self.multipart is True: - with open(filename, "rb") as f: - m = MultipartEncoder( - fields={filename: (filename, f, 'application/octet-stream')}) - headers = {'Content-Type': m.content_type} - r = requests.post(upload_url, data=m, headers=headers, - verify=verify_certificates) - r.raise_for_status() + file = {filename: open(filename, "rb")} + resp = requests.post(upload_url, files=file, verify=verify_certificates) + resp.raise_for_status() else: # upload the file to our DSS session workspace with open(filename, "rb") as f: diff --git a/api-openbis-python3-pybis/src/python/pybis/pybis.py b/api-openbis-python3-pybis/src/python/pybis/pybis.py index a0b8674fe58..12e50318f81 100644 --- a/api-openbis-python3-pybis/src/python/pybis/pybis.py +++ b/api-openbis-python3-pybis/src/python/pybis/pybis.py @@ -2380,6 +2380,7 @@ class Openbis: attrs=None, props=None, where=None, + raw_response=False, **properties, ): """Returns a DataFrame of all samples for a given space/project/experiment (or any combination). @@ -2512,6 +2513,8 @@ class Openbis: resp = self._post_request(self.as_v3, request) parse_jackson(resp) + if raw_response: + return resp response = resp["objects"] @@ -4663,7 +4666,8 @@ class Openbis: ) def get_sample( - self, sample_ident, only_data=False, withAttachments=False, props=None, withDataSetIds=False, **kvals + self, sample_ident, only_data=False, withAttachments=False, props=None, + withDataSetIds=False, raw_response=False, **kvals ): """Retrieve metadata for the sample. Get metadata for the sample and any directly connected parents of the sample to allow access @@ -4729,6 +4733,9 @@ class Openbis: data=resp[sample_ident], ) else: + if raw_response: + parse_jackson(resp) + return resp return self._sample_list_for_response( response=list(resp.values()), props=props, parsed=False ) diff --git a/api-openbis-python3-pybis/src/python/setup.cfg b/api-openbis-python3-pybis/src/python/setup.cfg index 4b809868084..ae2a809cf65 100644 --- a/api-openbis-python3-pybis/src/python/setup.cfg +++ b/api-openbis-python3-pybis/src/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = PyBIS -version = 1.36.0rc1 +version = 1.36.0 author = ID SIS • ETH Zürich author_email = openbis-support@id.ethz.ch license = Apache Software License Version 2.0 diff --git a/api-openbis-python3-pybis/src/python/setup.py b/api-openbis-python3-pybis/src/python/setup.py index dbd0fada902..0efb031a3d7 100644 --- a/api-openbis-python3-pybis/src/python/setup.py +++ b/api-openbis-python3-pybis/src/python/setup.py @@ -26,7 +26,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setup( name="PyBIS", - version="1.36.0rc1", + version="1.36.0", author="ID SIS • ETH Zürich", author_email="openbis-support@id.ethz.ch", description="openBIS connection and interaction, optimized for using with Jupyter", @@ -38,7 +38,6 @@ setup( install_requires=[ "pytest", "requests", - "requests_toolbelt", "urllib3", "pandas", "texttable", -- GitLab