Skip to content

Commit 837bc0b

Browse files
authored
Merge pull request #2 from UCSB-VRL/charvi/upgrade_python_version
Merge : Charvi/upgrade python version
2 parents 73d906d + db5022b commit 837bc0b

30 files changed

Lines changed: 1646 additions & 5745 deletions

.github/workflows/lint.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Lint Code
2+
on: [push, pull_request]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: chartboost/ruff-action@v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/__pycache__/**
2+
*.bak
3+
**/.ruff_cache/**

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[tool.ruff]
2+
# Follow Flake8's behavior
3+
lint.select = ["E", "F", "W", "C90"] # Enables Flake8-compatible rules
4+
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

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
keywords='API Bisque',
1313
url='https://github.com/UCSB-VRL/bisqueUCSB',
1414
install_requires=[
15-
'six',
16-
'lxml',
17-
'requests==2.10.0',
18-
'requests-toolbelt',
19-
],
15+
'six', 'lxml', 'requests==2.32.3', 'requests-toolbelt',
16+
],
2017
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#empty
1+
#empty

src/bqapi/RequestsMonkeyPatch/monkeypatch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ def monkeypatch_method(cls):
22
def decorator(func):
33
setattr(cls, func.__name__, func)
44
return func
5+
56
return decorator
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
"""
2-
A patch to format_header_param in urllib3
2+
A patch to format_header_param in urllib3
33
4-
If a value has unicode the header will be returned
5-
as 'name="value"; name*=utf-8''value' else
6-
'name="value"'
4+
If a value has unicode the header will be returned
5+
as 'name="value"; name*=utf-8''value' else
6+
'name="value"'
77
"""
88

9-
109
import email.utils
11-
#import mimetypes
10+
11+
# import mimetypes
1212
import warnings
1313

1414
import requests
1515
import requests.packages.urllib3 as urllib3
16-
from requests.packages.urllib3.packages import six
16+
import six
1717
from .monkeypatch import monkeypatch_method
1818

1919

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

21-
REQUESTS_V = [int(s) for s in requests.__version__.split('.')]
22-
23-
if REQUESTS_V < [2, 4, 0] or REQUESTS_V > [2, 19, 0]:
22+
print(REQUESTS_V)
23+
if REQUESTS_V < [2, 4, 0] or REQUESTS_V > [2, 32, 3]:
2424
warnings.warn("""\
25-
We need to patch requests 2.4.0 up to 2.19.0, make sure your version of requests \
26-
needs this patch, greater than 2.4.3 we do not know if this patch applys."""
27-
)
28-
raise ImportError('Requests 2.4.0 to 2.10.0 is required!')
29-
#elif requests_v > [3, 0, 0]:
25+
We need to patch requests 2.4.0 up to 2.32.3, make sure your version of
26+
requests needs this patch, greater than 2.4.3 we do not know if this
27+
patch applys.""")
28+
raise ImportError("Requests 2.4.0 to 2.32.3 is required!")
29+
# elif requests_v > [3, 0, 0]:
3030
# #does not require this patch
3131
# pass
3232
else:
33+
3334
@monkeypatch_method(urllib3.fields)
3435
def format_header_param(name, value):
3536
"""
@@ -47,18 +48,20 @@ def format_header_param(name, value):
4748
if not any(ch in value for ch in '"\\\r\n'):
4849
result = '%s="%s"' % (name, value)
4950
try:
50-
result.encode('ascii')
51+
result.encode("ascii")
5152
except UnicodeEncodeError:
5253
pass
5354
else:
5455
return result
5556

5657
value_encode = value
57-
if not six.PY3: # Python 2:
58-
value_encode = value.encode('utf-8')
58+
if not six.PY3: # Python 2:
59+
value_encode = value.encode("utf-8")
5960

6061
value = '%s="%s"; %s*=%s' % (
61-
name, value,
62-
name, email.utils.encode_rfc2231(value_encode, 'utf-8')
62+
name,
63+
value,
64+
name,
65+
email.utils.encode_rfc2231(value_encode, "utf-8"),
6366
)
6467
return value

src/bqapi/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#
2-
3-
from .comm import *
4-
from .types import *
5-
1+
from comm import BQSession
2+
import comm
3+
import types
64

5+
__all__ = ["comm", "types", "BQSession"]

src/bqapi/blockable_module.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,58 @@
77
import logging
88

99

10+
# logging.basicConfig(filename='BlockableModule.log',level=logging.DEBUG) #!!!
11+
log = logging.getLogger("bqapi.blockable_module")
1012

11-
#logging.basicConfig(filename='BlockableModule.log',level=logging.DEBUG) #!!!
12-
log = logging.getLogger('bqapi.blockable_module')
1313

1414
class BlockableModule(object):
1515
"""Base class for module that can run over blocks of parameters"""
16-
17-
def main(self, mex_url=None, auth_token=None, bq=None, **kw):
16+
17+
def main(self, mex_url=None, auth_token=None, bq=None, **kw):
1818
# Allow for testing by passing an alreay initialized session
1919
if bq is None:
2020
bq = BQSession().init_mex(mex_url, auth_token)
21-
21+
2222
# check for list parameters
2323
params = bq.get_mex_inputs()
24-
if isinstance(params, dict) or not isinstance(params, collections.Iterable):
24+
if isinstance(params, dict) or not isinstance(
25+
params, collections.Iterable
26+
):
2527
params = [params]
2628
# pass values directly as args
2729
for single_params in params:
2830
for param_name in single_params:
29-
if 'value' in single_params[param_name]:
30-
single_params[param_name] = single_params[param_name].get('value')
31-
31+
if "value" in single_params[param_name]:
32+
single_params[param_name] = single_params[param_name].get(
33+
"value"
34+
)
35+
3236
# TODO: measure block startup time
3337
self.start_block(bq, params)
34-
38+
3539
for kw in params:
3640
# TODO: measure single item time
3741
# TODO: run in parallel
38-
if 'mex_url' in kw:
42+
if "mex_url" in kw:
3943
# set (innermost) single item mex
40-
sub_bq = BQSession().init_mex(kw['mex_url'], auth_token)
44+
sub_bq = BQSession().init_mex(kw["mex_url"], auth_token)
4145
else:
4246
sub_bq = bq
4347
self.process_single(sub_bq, **kw)
44-
if 'mex_url' in kw:
48+
if "mex_url" in kw:
4549
sub_bq.close()
46-
50+
4751
# TODO: measure block teardown time
4852
self.end_block(bq)
49-
53+
5054
sys.exit(0)
51-
#bq.close()
52-
55+
# bq.close()
56+
5357
def start_block(self, bq, all_kw):
5458
pass
55-
59+
5660
def end_block(self, bq):
5761
pass
58-
62+
5963
def process_single(self, bq, **kw):
6064
pass

0 commit comments

Comments
 (0)