Skip to content
Merged
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
8 changes: 0 additions & 8 deletions .github/workflows/lint.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pre-commit Checks

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Install pre-commit if not already available in your dependencies
pip install pre-commit
# Optionally install your API package dependencies if needed
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Run pre-commit checks
run: pre-commit run
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/__pycache__/**
*.bak
**/.ruff_cache/**
**/.ruff_cache/**
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0 # Use the latest stable version available
hooks:
- id: black
language_version: python3

- repo: https://github.com/PyCQA/isort
rev: 5.12.0 # Update as appropriate
hooks:
- id: isort
language_version: python3

# - repo: https://github.com/PyCQA/flake8
# rev: 6.1.0 # Update as needed
# hooks:
# - id: flake8
# additional_dependencies: [flake8-bugbear] # optional extra checks

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # Update as needed
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# Bisque API for Python 3

[![Upload Python Package](https://github.com/UCSB-VRL/bqapi/actions/workflows/python-publish.yml/badge.svg)](https://github.com/UCSB-VRL/bqapi/actions/workflows/python-publish.yml)
[![Pre-commit Checks](https://github.com/UCSB-VRL/bqapi/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/UCSB-VRL/bqapi/actions/workflows/pre-commit.yml)
[![PyPI](https://img.shields.io/pypi/v/bqapi-ucsb?style=flat-square)](https://pypi.org/project/bqapi-ucsb/)
[![Documentation](https://img.shields.io/badge/Documentation-View%20here-brightgreen?style=flat-square)](https://bisque.gitbook.io/docs)
[![PyPi Installs](https://pepy.tech/badge/bqapi-ucsb?style=flat-square)](https://pepy.tech/project/bqapi-ucsb)

[Full Documentation](https://github.com/UCSB-VRL/bisqueUCSB)

For development, follow [this guide](https://towardsdatascience.com/how-to-upload-your-python-package-to-pypi-de1b363a1b3) and [this repo](https://github.com/gmyrianthous/example-publish-pypi).

# Installing
## Install
```
pip install bqapi-ucsb
```

[Pypi link](https://pypi.org/project/bqapi-ucsb)
## Usage

# Usage
```python
from bqapi.comm import BQSession
from bqapi.util import fetch_blob
```
### Upload Image

Upload your first image to BisQue using our tutorial!

# Development
[Upload an Image to BisQue](https://bisque.gitbook.io/docs/bisque-api/upload-an-image)


## Development

For development, follow [this guide](https://towardsdatascience.com/how-to-upload-your-python-package-to-pypi-de1b363a1b3) and [this repo](https://github.com/gmyrianthous/example-publish-pypi).

## Added GitHub Action

### Summary
## Contribute

1. Clone repo
2. Make any necessary changes to source code, setup.py, and setup.cfg
Expand All @@ -34,4 +36,3 @@ For development, follow [this guide](https://towardsdatascience.com/how-to-uploa
5. Make sure to have PyPi account credentials
6. run `twine upload dist/*` from main folder
7. Enter username and password

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Follow Flake8's behavior
lint.select = ["E", "F", "W", "C90"] # Enables Flake8-compatible rules
lint.ignore = [] # Add rules to ignore
line-length = 79
exclude = ["venv", ".git", "__pycache__", "**/tests/**"]
lint.mccabe.max-complexity = 25 # Set your desired threshold
line-length = 79
exclude = ["venv", ".git", "__pycache__", "**/tests/**"]
lint.mccabe.max-complexity = 25 # Set your desired threshold
24 changes: 13 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from setuptools import setup, find_packages

from setuptools import find_packages, setup

setup(
name='bqapi-ucsb',
version='1.0.6',
name="bqapi-ucsb",
version="1.0.6",
author="Bisque Team",
author_email='amil@ucsb.edu',
author_email="amil@ucsb.edu",
description="""Python API for interacting with BisQue""",
packages=find_packages('src'),
package_dir={'': 'src'},
keywords='API Bisque',
url='https://github.com/UCSB-VRL/bisqueUCSB',
packages=find_packages("src"),
package_dir={"": "src"},
keywords="API Bisque",
url="https://github.com/UCSB-VRL/bisqueUCSB",
install_requires=[
'six', 'lxml', 'requests==2.32.3', 'requests-toolbelt',
],
"six",
"lxml",
"requests==2.32.3",
"requests-toolbelt",
],
)
2 changes: 1 addition & 1 deletion src/bqapi/RequestsMonkeyPatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#empty
# empty
13 changes: 7 additions & 6 deletions src/bqapi/RequestsMonkeyPatch/requests_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
"""

import email.utils

# import mimetypes
import warnings

import requests
import requests.packages.urllib3 as urllib3
import six
from .monkeypatch import monkeypatch_method

from .monkeypatch import monkeypatch_method

REQUESTS_V = [int(s) for s in requests.__version__.split(".")]

print(REQUESTS_V)
if REQUESTS_V < [2, 4, 0] or REQUESTS_V > [2, 32, 3]:
warnings.warn("""\
warnings.warn(
"""\
We need to patch requests 2.4.0 up to 2.32.3, make sure your version of
requests needs this patch, greater than 2.4.3 we do not know if this
patch applys.""")
patch applys."""
)
raise ImportError("Requests 2.4.0 to 2.32.3 is required!")
# elif requests_v > [3, 0, 0]:
# #does not require this patch
Expand All @@ -46,7 +47,7 @@ def format_header_param(name, value):
The value of the parameter, provided as a unicode string.
"""
if not any(ch in value for ch in '"\\\r\n'):
result = '%s="%s"' % (name, value)
result = '{}="{}"'.format(name, value)
try:
result.encode("ascii")
except UnicodeEncodeError:
Expand All @@ -58,7 +59,7 @@ def format_header_param(name, value):
if not six.PY3: # Python 2:
value_encode = value.encode("utf-8")

value = '%s="%s"; %s*=%s' % (
value = '{}="{}"; {}*={}'.format(
name,
value,
name,
Expand Down
15 changes: 4 additions & 11 deletions src/bqapi/blockable_module.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sys
import collections

from bqapi import BQSession


import logging
import sys

from bqapi import BQSession

# logging.basicConfig(filename='BlockableModule.log',level=logging.DEBUG) #!!!
log = logging.getLogger("bqapi.blockable_module")
Expand All @@ -21,17 +18,13 @@ def main(self, mex_url=None, auth_token=None, bq=None, **kw):

# check for list parameters
params = bq.get_mex_inputs()
if isinstance(params, dict) or not isinstance(
params, collections.Iterable
):
if isinstance(params, dict) or not isinstance(params, collections.Iterable):
params = [params]
# pass values directly as args
for single_params in params:
for param_name in single_params:
if "value" in single_params[param_name]:
single_params[param_name] = single_params[param_name].get(
"value"
)
single_params[param_name] = single_params[param_name].get("value")

# TODO: measure block startup time
self.start_block(bq, params)
Expand Down
28 changes: 10 additions & 18 deletions src/bqapi/bqclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@
__version__ = "0.1"
__revision__ = "$Rev$"
__date__ = "$Date$"
__copyright__ = (
"Center for BioImage Informatics, University California, Santa Barbara"
)
__copyright__ = "Center for BioImage Informatics, University California, Santa Barbara"

import os
import sys
import math
import io
import collections
import inspect
import io
import logging
import math
import os
import sys
import tempfile
import collections

try:
from lxml import etree
except ImportError:
import xml.etree.ElementTree as etree
from .xmldict import xml2nv

from .xmldict import xml2nv

log = logging.getLogger("bqapi.class")

Expand Down Expand Up @@ -148,9 +146,7 @@ def __repr__(self):
def __str__(self):
return "(%s:%s)" % (
self.xmltag,
",".join(
["%s=%s" % (f, getattr(self, f, "")) for f in self.xmlfields]
),
",".join(["%s=%s" % (f, getattr(self, f, "")) for f in self.xmlfields]),
)

def toTuple(self):
Expand Down Expand Up @@ -429,9 +425,7 @@ def fetch(self, path=None, stream=False):
response = image_service.fetch(url, stream=stream)
if path is not None:
with open(path, "wb") as fb:
for block in response.iter_content(
chunk_size=16 * 1024 * 1024
): # 16MB
for block in response.iter_content(chunk_size=16 * 1024 * 1024): # 16MB
fb.write(block)
response.close()
else:
Expand Down Expand Up @@ -476,9 +470,7 @@ def asarray(self):
# response.raw.decode_content = True
return tifffile.imread(io.BytesIO(response.content))

def savearray(
self, fname, imdata=None, imshape=None, dtype=None, **kwargs
):
def savearray(self, fname, imdata=None, imshape=None, dtype=None, **kwargs):
try:
import tifffile
except ImportError:
Expand Down
Loading