Skip to content

Commit 682bc7e

Browse files
d-w-mooretrel
authored andcommitted
[#3] codacy corrections
1 parent 67c228e commit 682bc7e

11 files changed

+56
-34
lines changed

irods/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
def client_logging(flag=True,handler=None):
99
"""
10+
Example of use:
11+
1012
import irods
1113
# Enable / Disable general client logging
1214
irods.client_logging(True[,handler]) -> handler

irods/data_object.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import sys
44
import logging
55
import six
6-
import json
76
import os
87
import ast
98

10-
import xml.etree.ElementTree as ET
119
from irods.models import DataObject
1210
from irods.meta import iRODSMetaCollection
1311
import irods.keywords as kw
1412
from irods.api_number import api_number
15-
from irods.message import (StringStringMap, FileOpenRequest, JSON_Message, iRODSMessage)
13+
from irods.message import (JSON_Message, iRODSMessage)
1614

1715
logger = logging.getLogger(__name__)
1816

@@ -111,7 +109,17 @@ def replicate(self, resource=None, **options):
111109

112110
class iRODSDataObjectFileRaw(io.RawIOBase):
113111

112+
"""The raw object supporting file-like operations (read/write/seek) for the
113+
iRODSDataObject."""
114+
114115
def __init__(self, conn, descriptor, finalize_on_close = True, **options):
116+
"""
117+
Constructor needs a connection and an iRODS data object descriptor. If the
118+
finalize_on_close flag evaluates False, close() will invoke the REPLICA_CLOSE
119+
API instead of closing and finalizing the object (useful for parallel
120+
transfers using multiple threads).
121+
"""
122+
super(iRODSDataObjectFileRaw,self).__init__()
115123
self.conn = conn
116124
self.desc = descriptor
117125
self.options = options
@@ -128,7 +136,7 @@ def replica_access_info(self):
128136
result = self.conn.recv()
129137
except Exception as e:
130138
logger.warning('''Couldn't receive or process response to GET_FILE_DESCRIPTOR_INFO_APN -- '''
131-
'''caught: {0!r}'''.format(e))
139+
'''caught: %r''',e)
132140
raise
133141
dobj_info = result.get_json_encoded_struct()
134142
replica_token = dobj_info.get("replica_token","")
@@ -142,14 +150,13 @@ def _close_replica(self):
142150
"send_notification": False,
143151
"update_size": False,
144152
"update_status": False,
145-
"send_notification": False,
146153
"compute_checksum": False },
147154
server_version = self.conn.server_version )
148155
self.conn.send( iRODSMessage('RODS_API_REQ', msg = message_body,
149156
int_info=api_number['REPLICA_CLOSE_APN']) )
150157
try:
151158
self.conn.recv().int_info
152-
except Exception as e:
159+
except Exception:
153160
logger.warning ('** ERROR on closing replica **')
154161
raise
155162
return True

irods/manager/data_object_manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def put(self, local_path, irods_path, return_data_object = False, num_threads =
111111
with open(local_path, 'rb') as f, self.open(obj, 'w', **options) as o:
112112

113113
if self.should_parallelize_transfer (num_threads, f):
114-
f.close();
114+
f.close()
115115
if not self.parallel_put( local_path, (obj,o), num_threads = num_threads,
116116
target_resource_name = options.get(kw.RESC_NAME_KW,'') or
117117
options.get(kw.DEST_RESC_NAME_KW,'')):
@@ -205,9 +205,9 @@ def create(self, path, resource=None, force=False, **options):
205205
return self.get(path)
206206

207207

208-
def open_with_FileRaw(self, *arg, **kw):
208+
def open_with_FileRaw(self, *arg, **kw_options):
209209
holder = []
210-
handle = self.open(*arg,_raw_fd_holder=holder,**kw)
210+
handle = self.open(*arg,_raw_fd_holder=holder,**kw_options)
211211
return (handle, holder[-1])
212212

213213
def open(self, path, mode, create = True, finalize_on_close = True, **options):

irods/message/__init__.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import base64
1+
"""Define objects related to communication with iRODS server API endpoints."""
2+
23
import struct
34
import logging
45
import socket
@@ -252,7 +253,9 @@ class AuthPluginOut(Message):
252253
# define InxIvalPair_PI "int iiLen; int *inx(iiLen); int *ivalue(iiLen);"
253254

254255
class JSON_Binary_Request(BinBytesBuf):
256+
255257
"""A message body whose payload is BinBytesBuf containing JSON."""
258+
256259
def __init__(self,msg_struct):
257260
"""Initialize with a Python data structure that will be converted to JSON."""
258261
super(JSON_Binary_Request,self).__init__()
@@ -261,16 +264,19 @@ def __init__(self,msg_struct):
261264
self.buflen = len(string)
262265

263266
class BytesBuf(Message):
267+
268+
"""A generic structure carrying text content"""
269+
264270
_name = 'BytesBuf_PI'
265271
buflen = IntegerProperty()
266272
buf = StringProperty()
267273
def __init__(self,string,*v,**kw):
268-
super(BytesBuf,self).__init__(*v,**kw)
269-
_buf = StringProperty.escape_xml_string( string )
270-
self.buf = string
271-
self.buflen = len(self.buf)
274+
super(BytesBuf,self).__init__(*v,**kw)
275+
self.buf = string
276+
self.buflen = len(self.buf)
272277

273278
class JSON_XMLFramed_Request(BytesBuf):
279+
274280
"""A message body whose payload is a BytesBuf containing JSON."""
275281
def __init__(self, msg_struct):
276282
"""Initialize with a Python data structure that will be converted to JSON."""
@@ -408,7 +414,10 @@ class FileOpenRequest(Message):
408414
KeyValPair_PI = SubmessageProperty(StringStringMap)
409415

410416
class DataObjChksumRequest(FileOpenRequest):
417+
"""Report and/or generate a data object's checksum."""
418+
411419
def __init__(self,path,**chksumOptions):
420+
"""Construct the request using the path of a data object."""
412421
super(DataObjChksumRequest,self).__init__()
413422
for attr,prop in vars(FileOpenRequest).items():
414423
if isinstance(prop, (IntegerProperty,LongProperty)):

irods/parallel.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import os
55
import ssl
6-
import json
76
import time
87
import sys
98
import logging
@@ -13,14 +12,9 @@
1312
import multiprocessing
1413
import six
1514

16-
import irods
17-
import irods.data_object
18-
from irods.data_object import iRODSDataObjectFileRaw, iRODSDataObject
15+
from irods.data_object import iRODSDataObject
1916
from irods.exception import DataObjectDoesNotExist
20-
from irods.message import ( StringStringMap, FileOpenRequest, iRODSMessage )
21-
from irods.api_number import api_number
2217
import irods.keywords as kw
23-
from collections import OrderedDict
2418
from six.moves.queue import Queue,Full,Empty
2519

2620

@@ -44,6 +38,7 @@ def __init__(self, n):
4438
self.barrier = threading.Semaphore(0)
4539
def wait(self):
4640
"""Per-thread wait function.
41+
4742
As in Python3.2 threading, returns 0 <= wait_serial_int < n
4843
"""
4944
self.mutex.acquire()
@@ -58,6 +53,7 @@ def wait(self):
5853
@contextlib.contextmanager
5954
def enableLogging(handlerType,args,level_ = logging.INFO):
6055
"""Context manager for temporarily enabling a logger. For debug or test.
56+
6157
Usage Example -
6258
with irods.parallel.enableLogging(logging.FileHandler,('/tmp/logfile.txt',)):
6359
# parallel put/get code here
@@ -98,6 +94,10 @@ def set_transfer_done_callback( self, callback ):
9894
self.done_callback = callback
9995

10096
def __init__(self, futuresList, callback = None, progress_Queue = None, total = None, keep_ = ()):
97+
"""AsyncNotify initialization (used internally to the io.parallel library).
98+
The casual user will only be concerned with the callback parameter, called when all threads
99+
of the parallel PUT or GET have been terminated and the data object closed.
100+
"""
101101
self._futures = set(futuresList)
102102
self._futures_done = dict()
103103
self.keep = dict(keep_)
@@ -173,15 +173,21 @@ def futures_done(self): return dict(self._futures_done)
173173

174174

175175
class Oper(object):
176-
177176
"""A custom enum-type class with utility methods. """
178177

179178
GET = 0
180179
PUT = 1
181180
NONBLOCKING = 2
182181

183-
def __int__(self): return self._opr
184-
def __init__(self, rhs): self._opr = int(rhs)
182+
def __int__(self):
183+
"""Return the stored flags as an integer bitmask. """
184+
return self._opr
185+
186+
def __init__(self, rhs):
187+
"""Initialize with a bit mask of flags ie. whether Operation PUT or GET,
188+
and whether NONBLOCKING."""
189+
self._opr = int(rhs)
190+
185191
def isPut(self): return 0 != (self._opr & self.PUT)
186192
def isGet(self): return not self.isPut()
187193
def isNonBlocking(self): return 0 != (self._opr & self.NONBLOCKING)
@@ -290,7 +296,6 @@ def _io_multipart_threaded(operation_ , dataObj_and_IO, replica_token, hier_str,
290296
total_size, num_threads = 0, **extra_options):
291297
"""Called by _io_main.
292298
Carve up (0,total_size) range into `num_threads` parts and initiate a transfer thread for each one."""
293-
294299
(D, Io) = dataObj_and_IO
295300
Operation = Oper( operation_ )
296301

irods/test/data_obj_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import irods.keywords as kw
2323
from irods.manager import data_object_manager
2424
from datetime import datetime
25-
from tempfile import NamedTemporaryFile, mkdtemp
25+
from tempfile import NamedTemporaryFile
2626
from irods.test.helpers import (unique_name, my_function_name)
2727
import irods.parallel
2828

irods/test/extended_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def tearDown(self):
3030

3131
@classmethod
3232
def tearDownClass(cls):
33-
'''Remove test data
34-
'''
33+
"""Remove test data."""
3534
# once only (after all tests), delete large collection
3635
print ("Deleting the large collection...", file = sys.stderr)
3736
with helpers.make_session() as sess:

irods/test/force_create.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def tearDown(self):
1919
# This test should pass whether or not federation is configured:
2020
def test_force_create(self):
2121
if self.sess.server_version > (4, 2, 8):
22-
self.skipTest('force flag unneeded for create in iRODS > 4.2.8')
22+
self.skipTest('force flag unneeded for create in iRODS > 4.2.8')
2323
session = self.sess
2424
FILE = '/{session.zone}/home/{session.username}/a.txt'.format(**locals())
2525
try:

irods/test/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020

2121
def my_function_name():
22-
'''Returns the name of the calling function or method'''
22+
"""Returns the name of the calling function or method"""
2323
return inspect.getframeinfo(inspect.currentframe().f_back).function
2424

2525
_thrlocal = threading.local()
2626

2727
def unique_name(*seed_tuple):
2828
'''For deterministic pseudo-random identifiers based on function/method name
2929
to prevent e.g. ICAT collisions within and between tests. Example use:
30+
3031
def f(session):
3132
seq_num = 1
3233
a_name = unique_name( my_function_name(), seq_num # [, *optional_further_args]
@@ -44,7 +45,6 @@ def f(session):
4445
IRODS_SHARED_REG_RESC_VAULT = os.path.join(IRODS_SHARED_DIR,'reg_resc')
4546

4647
IRODS_REG_RESC = 'MyRegResc'
47-
Reg_Resc_Name = ''
4848

4949
def irods_shared_tmp_dir():
5050
pth = IRODS_SHARED_TMP_DIR

irods/test/query_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from irods.meta import iRODSMeta
2424
from irods.rule import Rule
2525
from irods import MAX_SQL_ROWS
26-
from irods.test.helpers import (irods_shared_reg_resc_vault, get_register_resource)
26+
from irods.test.helpers import irods_shared_reg_resc_vault
2727
import irods.test.helpers as helpers
2828
from six.moves import range as py3_range
2929
import irods.keywords as kw

run_python_tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ cd repo/irods/test
66
export PYTHONUNBUFFERED="Y"
77

88
if [ -z "${TESTS_TO_RUN}" ] ; then
9-
python${PY_N} runner.py 2>&1 | tee ${LOG_OUTPUT_DIR}/prc_test_logs.txt
9+
python"${PY_N}" runner.py 2>&1 | tee "${LOG_OUTPUT_DIR}"/prc_test_logs.txt
1010
else
11-
python${PY_N} -m unittest -v ${TESTS_TO_RUN} 2>&1 | tee ${LOG_OUTPUT_DIR}/prc_test_logs.txt
11+
python"${PY_N}" -m unittest -v ${TESTS_TO_RUN} 2>&1 | tee "${LOG_OUTPUT_DIR}"/prc_test_logs.txt
1212
fi
1313

0 commit comments

Comments
 (0)