Skip to content

Commit efac5d0

Browse files
committed
🚀 Added pre-commit config for gh workflow
1 parent 847c2d3 commit efac5d0

25 files changed

Lines changed: 341 additions & 387 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
**/__pycache__/**
22
*.bak
3-
**/.ruff_cache/**
3+
**/.ruff_cache/**

.pre-commit-config.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ repos:
1111
- id: isort
1212
language_version: python3
1313

14-
- repo: https://github.com/PyCQA/flake8
15-
rev: 6.1.0 # Update as needed
16-
hooks:
17-
- id: flake8
18-
additional_dependencies: [flake8-bugbear] # optional extra checks
14+
# - repo: https://github.com/PyCQA/flake8
15+
# rev: 6.1.0 # Update as needed
16+
# hooks:
17+
# - id: flake8
18+
# additional_dependencies: [flake8-bugbear] # optional extra checks
1919

2020
- repo: https://github.com/pre-commit/pre-commit-hooks
2121
rev: v4.6.0 # Update as needed
2222
hooks:
2323
- id: trailing-whitespace
2424
- id: end-of-file-fixer
2525
- id: check-yaml
26-
- id: debug-statements # Optional: fails if there are print() or debugger statements
27-

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from bqapi.util import fetch_blob
2323

2424
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).
2525

26-
## Added GitHub Action
26+
## Added GitHub Action
2727

2828
### Summary
2929

@@ -34,4 +34,3 @@ For development, follow [this guide](https://towardsdatascience.com/how-to-uploa
3434
5. Make sure to have PyPi account credentials
3535
6. run `twine upload dist/*` from main folder
3636
7. Enter username and password
37-

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Follow Flake8's behavior
33
lint.select = ["E", "F", "W", "C90"] # Enables Flake8-compatible rules
44
lint.ignore = [] # Add rules to ignore
5-
line-length = 79
6-
exclude = ["venv", ".git", "__pycache__", "**/tests/**"]
7-
lint.mccabe.max-complexity = 25 # Set your desired threshold
5+
line-length = 79
6+
exclude = ["venv", ".git", "__pycache__", "**/tests/**"]
7+
lint.mccabe.max-complexity = 25 # Set your desired threshold

setup.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
from setuptools import setup, find_packages
2-
1+
from setuptools import find_packages, setup
32

43
setup(
5-
name='bqapi-ucsb',
6-
version='1.0.6',
4+
name="bqapi-ucsb",
5+
version="1.0.6",
76
author="Bisque Team",
8-
author_email='amil@ucsb.edu',
7+
author_email="amil@ucsb.edu",
98
description="""Python API for interacting with BisQue""",
10-
packages=find_packages('src'),
11-
package_dir={'': 'src'},
12-
keywords='API Bisque',
13-
url='https://github.com/UCSB-VRL/bisqueUCSB',
9+
packages=find_packages("src"),
10+
package_dir={"": "src"},
11+
keywords="API Bisque",
12+
url="https://github.com/UCSB-VRL/bisqueUCSB",
1413
install_requires=[
15-
'six', 'lxml', 'requests==2.32.3', 'requests-toolbelt',
16-
],
14+
"six",
15+
"lxml",
16+
"requests==2.32.3",
17+
"requests-toolbelt",
18+
],
1719
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#empty
1+
# empty

src/bqapi/RequestsMonkeyPatch/requests_patch.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
"""
88

99
import email.utils
10-
1110
# import mimetypes
1211
import warnings
1312

1413
import requests
1514
import requests.packages.urllib3 as urllib3
1615
import six
17-
from .monkeypatch import monkeypatch_method
1816

17+
from .monkeypatch import monkeypatch_method
1918

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

2221
print(REQUESTS_V)
2322
if REQUESTS_V < [2, 4, 0] or REQUESTS_V > [2, 32, 3]:
24-
warnings.warn("""\
23+
warnings.warn(
24+
"""\
2525
We need to patch requests 2.4.0 up to 2.32.3, make sure your version of
2626
requests needs this patch, greater than 2.4.3 we do not know if this
27-
patch applys.""")
27+
patch applys."""
28+
)
2829
raise ImportError("Requests 2.4.0 to 2.32.3 is required!")
2930
# elif requests_v > [3, 0, 0]:
3031
# #does not require this patch

src/bqapi/blockable_module.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import sys
21
import collections
3-
4-
from bqapi import BQSession
5-
6-
72
import logging
3+
import sys
84

5+
from bqapi import BQSession
96

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

2219
# check for list parameters
2320
params = bq.get_mex_inputs()
24-
if isinstance(params, dict) or not isinstance(
25-
params, collections.Iterable
26-
):
21+
if isinstance(params, dict) or not isinstance(params, collections.Iterable):
2722
params = [params]
2823
# pass values directly as args
2924
for single_params in params:
3025
for param_name in single_params:
3126
if "value" in single_params[param_name]:
32-
single_params[param_name] = single_params[param_name].get(
33-
"value"
34-
)
27+
single_params[param_name] = single_params[param_name].get("value")
3528

3629
# TODO: measure block startup time
3730
self.start_block(bq, params)

src/bqapi/bqclass.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,23 @@
5151
__version__ = "0.1"
5252
__revision__ = "$Rev$"
5353
__date__ = "$Date$"
54-
__copyright__ = (
55-
"Center for BioImage Informatics, University California, Santa Barbara"
56-
)
54+
__copyright__ = "Center for BioImage Informatics, University California, Santa Barbara"
5755

58-
import os
59-
import sys
60-
import math
61-
import io
56+
import collections
6257
import inspect
58+
import io
6359
import logging
60+
import math
61+
import os
62+
import sys
6463
import tempfile
65-
import collections
6664

6765
try:
6866
from lxml import etree
6967
except ImportError:
7068
import xml.etree.ElementTree as etree
71-
from .xmldict import xml2nv
7269

70+
from .xmldict import xml2nv
7371

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

@@ -148,9 +146,7 @@ def __repr__(self):
148146
def __str__(self):
149147
return "(%s:%s)" % (
150148
self.xmltag,
151-
",".join(
152-
["%s=%s" % (f, getattr(self, f, "")) for f in self.xmlfields]
153-
),
149+
",".join(["%s=%s" % (f, getattr(self, f, "")) for f in self.xmlfields]),
154150
)
155151

156152
def toTuple(self):
@@ -429,9 +425,7 @@ def fetch(self, path=None, stream=False):
429425
response = image_service.fetch(url, stream=stream)
430426
if path is not None:
431427
with open(path, "wb") as fb:
432-
for block in response.iter_content(
433-
chunk_size=16 * 1024 * 1024
434-
): # 16MB
428+
for block in response.iter_content(chunk_size=16 * 1024 * 1024): # 16MB
435429
fb.write(block)
436430
response.close()
437431
else:
@@ -476,9 +470,7 @@ def asarray(self):
476470
# response.raw.decode_content = True
477471
return tifffile.imread(io.BytesIO(response.content))
478472

479-
def savearray(
480-
self, fname, imdata=None, imshape=None, dtype=None, **kwargs
481-
):
473+
def savearray(self, fname, imdata=None, imshape=None, dtype=None, **kwargs):
482474
try:
483475
import tifffile
484476
except ImportError:

src/bqapi/bqfeature.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# import threading
2-
from threading import Thread
3-
import socket
42
import errno
5-
import tempfile
6-
import urllib.request
7-
import urllib.parse
8-
import urllib.error
3+
import logging
94
import os
10-
from math import ceil
115
import queue
12-
import logging
6+
import socket
7+
import tempfile
8+
import urllib.error
9+
import urllib.parse
10+
import urllib.request
1311
import warnings
1412
from collections import namedtuple
13+
from math import ceil
14+
from threading import Thread
15+
16+
from .exception import BQCommError
1517

1618
# import numpy as np
1719

18-
from .exception import BQCommError
1920

2021
try: # checks for lxml if not found uses python xml
2122
from lxml import etree
@@ -36,11 +37,13 @@
3637
FeatureResource = namedtuple("FeatureResource", ["image", "mask", "gobject"])
3738
FeatureResource.__new__.__defaults__ = (None, None, None)
3839

40+
3941
class FeatureError(Exception):
4042
"""
4143
Feature Communication Exception
4244
"""
4345

46+
4447
class Feature(object):
4548
def fetch(self, session, name, resource_list, path=None):
4649
"""
@@ -74,8 +77,7 @@ def fetch(self, session, name, resource_list, path=None):
7477
query = "&".join(query)
7578
sub.attrib["uri"] = "%s?%s" % (url, query)
7679

77-
log.debug("Fetch Feature %s for %s resources" % (name,
78-
len(resource_list)))
80+
log.debug("Fetch Feature %s for %s resources" % (name, len(resource_list)))
7981

8082
if path is None:
8183
f = tempfile.NamedTemporaryFile(
@@ -130,8 +132,7 @@ def fetch_vector(self, session, name, resource_list):
130132
status = status[index[0]][0]
131133
hdf5.close()
132134
os.remove(hdf5.filename) # remove file from temp directory
133-
raise FeatureError("%s:Error occured during feature calculations"
134-
% status)
135+
raise FeatureError("%s:Error occured during feature calculations" % status)
135136
table = hdf5.root.values
136137
# status_table = hdf5.root.status # to get the status
137138
feature_vector = table[:]["feature"]
@@ -150,8 +151,8 @@ def length(session, name):
150151
@return: feature length
151152
"""
152153
xml = session.fetchxml("/features/%s" % name)
153-
return int(xml.find(
154-
'feature/tag[@name="feature_length"]').attrib.get("value"))
154+
return int(xml.find('feature/tag[@name="feature_length"]').attrib.get("value"))
155+
155156

156157
class ParallelFeature(Feature):
157158
MaxThread = 8
@@ -200,8 +201,7 @@ def run(self):
200201
else:
201202
break
202203

203-
def request_thread_pool(self, request_queue, errorcb=None,
204-
thread_count=MaxThread):
204+
def request_thread_pool(self, request_queue, errorcb=None, thread_count=MaxThread):
205205
"""
206206
Runs the BQRequestThread
207207
@@ -293,8 +293,7 @@ def fetch(self, session, name, resource_list, path=None):
293293
log.warning("Warning no resources were provided")
294294
return
295295

296-
log.debug("Exctracting %s on %s resources" % (name,
297-
len(resource_list)))
296+
log.debug("Exctracting %s on %s resources" % (name, len(resource_list)))
298297

299298
if path is None:
300299
f = tempfile.TemporaryFile(suffix=".h5", dir=tempfile.gettempdir())
@@ -338,8 +337,7 @@ def run(self):
338337
temp_status_table = hdf5temp.root.status
339338
if not hasattr(hdf5.root, "values"):
340339
temp_table.copy(hdf5.root, "values")
341-
temp_status_table.copy(hdf5.root,
342-
"status")
340+
temp_status_table.copy(hdf5.root, "status")
343341
else:
344342
table = hdf5.root.values
345343
status_table = hdf5.root.status
@@ -420,8 +418,7 @@ def request():
420418
else:
421419
thread_num, chunk_size = self.calculate_request_plan(resource_list)
422420

423-
for partial_resource_list in self.chunk(resource_list,
424-
int(chunk_size)):
421+
for partial_resource_list in self.chunk(resource_list, int(chunk_size)):
425422
request_queue.put(request_factory(partial_resource_list))
426423

427424
w = WriteHDF5Thread(write_queue)
@@ -462,5 +459,4 @@ def fetch_vector(self, session, name, resource_list):
462459
463460
@return: a list of features as numpy array
464461
"""
465-
return super(ParallelFeature, self).fetch_vector(session, name,
466-
resource_list)
462+
return super(ParallelFeature, self).fetch_vector(session, name, resource_list)

0 commit comments

Comments
 (0)