Skip to content

Commit 8f9fbec

Browse files
committed
codestyle
1 parent a04beeb commit 8f9fbec

File tree

2 files changed

+62
-32
lines changed

2 files changed

+62
-32
lines changed

qiita_client/plugin.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,44 @@ def __init__(self, name, description, can_be_submitted_to_ebi,
136136

137137

138138
class BaseQiitaPlugin(object):
139-
_ALLOWED_PLUGIN_COUPLINGS = ['filesystem', 'https'] # default must be first element
140-
def __init__(self, name, version, description, publications=None, plugincoupling=_ALLOWED_PLUGIN_COUPLINGS[0]):
139+
# default must be first element
140+
_ALLOWED_PLUGIN_COUPLINGS = ['filesystem', 'https']
141+
142+
def __init__(self, name, version, description, publications=None,
143+
plugincoupling=_ALLOWED_PLUGIN_COUPLINGS[0]):
141144
logger.debug('Entered BaseQiitaPlugin.__init__()')
142145
self.name = name
143146
self.version = version
144147
self.description = description
145148
self.publications = dumps(publications) if publications else ""
146149

147-
# Depending on your compute architecture, there are multiple options available how
148-
# "thight" plugins are coupled to the central Qiita master/workers
150+
# Depending on your compute architecture, there are multiple options
151+
# available how "thight" plugins are coupled to the central
152+
# Qiita master/workers
149153
# --- filesystem ---
150-
# The default scenario is "filesystem", i.e. plugins as well as master/worker have
151-
# unrestricted direct access to a shared filesystem, e.g. a larger volume / directory,
152-
# defined in the server configuration as base_data_dir
154+
# The default scenario is "filesystem", i.e. plugins as well as
155+
# master/worker have unrestricted direct access to a shared filesystem,
156+
# e.g. a larger volume / directory, defined in the server configuration
157+
# as base_data_dir
153158
# --- https ---
154-
# A second scenario is that your plugins execute as independent jobs on another machine,
155-
# e.g. as docker containers or other cloud techniques. Intentionally, you don't want to
156-
# use a shared filesystem, but you have to make sure necessary input files are
157-
# provided to the containerized plugin before execution and resulting files are
158-
# transfered back to the central Qiita master/worker. In this case, files are
159-
# pulled / pushed through functions qiita_client.fetch_file_from_central and
159+
# A second scenario is that your plugins execute as independent jobs on
160+
# another machine, e.g. as docker containers or other cloud techniques.
161+
# Intentionally, you don't want to use a shared filesystem, but you
162+
# have to make sure necessary input files are provided to the
163+
# containerized plugin before execution and resulting files are
164+
# transfered back to the central Qiita master/worker. In this case,
165+
# files are pulled / pushed through functions
166+
# qiita_client.fetch_file_from_central and
160167
# qiita_client.push_file_to_central, respectivey.
161-
# Actually, all files need to be decorated with this function. The decision how
162-
# data are transferred is then made within these two functions according to the
163-
# "plugincoupling" setting.
168+
# Actually, all files need to be decorated with this function.
169+
# The decision how data are transferred is then made within these two
170+
# functions according to the "plugincoupling" setting.
164171
if plugincoupling not in self._ALLOWED_PLUGIN_COUPLINGS:
165-
raise ValueError("valid plugincoupling values are ['%s'], but you provided %s" % ("', '".join(self._ALLOWED_PLUGIN_COUPLINGS), plugincoupling))
172+
raise ValueError(
173+
("valid plugincoupling values are ['%s'], but you "
174+
"provided %s") % (
175+
"', '".join(self._ALLOWED_PLUGIN_COUPLINGS),
176+
plugincoupling))
166177
self.plugincoupling = plugincoupling
167178

168179
# Will hold the different commands
@@ -173,7 +184,8 @@ def __init__(self, name, version, description, publications=None, plugincoupling
173184
'QIITA_PLUGINS_DIR', join(expanduser('~'), '.qiita_plugins'))
174185
self.conf_fp = join(conf_dir, "%s_%s.conf" % (self.name, self.version))
175186

176-
def generate_config(self, env_script, start_script, server_cert=None, plugin_couling=_ALLOWED_PLUGIN_COUPLINGS[0]):
187+
def generate_config(self, env_script, start_script, server_cert=None,
188+
plugin_couling=_ALLOWED_PLUGIN_COUPLINGS[0]):
177189
"""Generates the plugin configuration file
178190
179191
Parameters
@@ -188,7 +200,7 @@ def generate_config(self, env_script, start_script, server_cert=None, plugin_cou
188200
path to the Qiita certificate so the plugin can connect over
189201
HTTPS to it
190202
plugin_coupling : str
191-
Type of coupling of plugin to central for file exchange.
203+
Type of coupling of plugin to central for file exchange.
192204
Valid values are 'filesystem' and 'https'.
193205
"""
194206
logger.debug('Entered BaseQiitaPlugin.generate_config()')
@@ -214,7 +226,8 @@ def _register_command(self, command):
214226
command: QiitaCommand
215227
The command to be added to the plugin
216228
"""
217-
logger.debug('Entered BaseQiitaPlugin._register_command(%s)' % command.name)
229+
logger.debug('Entered BaseQiitaPlugin._register_command(%s)' %
230+
command.name)
218231
self.task_dict[command.name] = command
219232

220233
def _register(self, qclient):
@@ -277,7 +290,8 @@ def __call__(self, server_url, job_id, output_dir):
277290
# from validating the server's cert using
278291
# certifi's pem cache.
279292
ca_cert=config.get('oauth2', 'SERVER_CERT'),
280-
plugincoupling=config.get('network', 'PLUGINCOUPLING'))
293+
plugincoupling=config.get('network',
294+
'PLUGINCOUPLING'))
281295

282296
if job_id == 'register':
283297
self._register(qclient)

qiita_client/qiita_client.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ class QiitaClient(object):
183183
get
184184
post
185185
"""
186-
def __init__(self, server_url, client_id, client_secret, ca_cert=None, plugincoupling='filesystem'):
186+
def __init__(self, server_url, client_id, client_secret, ca_cert=None,
187+
plugincoupling='filesystem'):
187188
self._server_url = server_url
188189
self._session = requests.Session()
189190

@@ -367,7 +368,8 @@ def _request_retry(self, req, url, rettype='json', **kwargs):
367368
retries = MAX_RETRIES
368369
while retries > 0:
369370
retries -= 1
370-
r = self._request_oauth2(req, rettype, url, verify=self._verify, **kwargs)
371+
r = self._request_oauth2(
372+
req, rettype, url, verify=self._verify, **kwargs)
371373
r.close()
372374
# There are some error codes that the specification says that they
373375
# shouldn't be retried
@@ -389,7 +391,10 @@ def _request_retry(self, req, url, rettype='json', **kwargs):
389391
if rettype == 'content':
390392
return r.content
391393
else:
392-
raise ValueError("return type rettype='%s' cannot be understand. Choose from 'json' (default) or 'content!" % rettype)
394+
raise ValueError(
395+
("return type rettype='%s' cannot be "
396+
"understand. Choose from 'json' (default) "
397+
"or 'content!") % rettype)
393398
except ValueError:
394399
return None
395400
stime = randint(MIN_TIME_SLEEP, MAX_TIME_SLEEP)
@@ -420,7 +425,8 @@ def get(self, url, rettype='json', **kwargs):
420425
The JSON response from the server
421426
"""
422427
logger.debug('Entered QiitaClient.get()')
423-
return self._request_retry(self._session.get, url, rettype=rettype, **kwargs)
428+
return self._request_retry(
429+
self._session.get, url, rettype=rettype, **kwargs)
424430

425431
def post(self, url, **kwargs):
426432
"""Execute a post request against the Qiita server
@@ -438,7 +444,8 @@ def post(self, url, **kwargs):
438444
The JSON response from the server
439445
"""
440446
logger.debug('Entered QiitaClient.post(%s)' % url)
441-
return self._request_retry(self._session.post, url, rettype='json', **kwargs)
447+
return self._request_retry(
448+
self._session.post, url, rettype='json', **kwargs)
442449

443450
def patch(self, url, op, path, value=None, from_p=None, **kwargs):
444451
"""Executes a JSON patch request against the Qiita server
@@ -497,7 +504,8 @@ def patch(self, url, op, path, value=None, from_p=None, **kwargs):
497504
# we made sure that data is correctly formatted here
498505
kwargs['data'] = data
499506

500-
return self._request_retry(self._session.patch, url, rettype='json', **kwargs)
507+
return self._request_retry(
508+
self._session.patch, url, rettype='json', **kwargs)
501509

502510
# The functions are shortcuts for common functionality that all plugins
503511
# need to implement.
@@ -520,7 +528,8 @@ def http_patch(self, url, **kwargs):
520528
The JSON response from the server
521529
"""
522530
logger.debug('Entered QiitaClient.http_patch()')
523-
return self._request_retry(self._session.patch, url, rettype='json', **kwargs)
531+
return self._request_retry(
532+
self._session.patch, url, rettype='json', **kwargs)
524533

525534
def start_heartbeat(self, job_id):
526535
"""Create and start a thread that would send heartbeats to the server
@@ -741,7 +750,9 @@ def fetch_file_from_central(self, filepath):
741750
logger.debug('Requesting file %s from qiita server.' % filepath)
742751

743752
# actual call to Qiita central to obtain file content
744-
content = self.get('/cloud/fetch_file_from_central/' + filepath, rettype='content')
753+
content = self.get(
754+
'/cloud/fetch_file_from_central/' + filepath,
755+
rettype='content')
745756

746757
# create necessary directory locally
747758
os.makedirs(os.path.dirname(filepath), exist_ok=True)
@@ -752,7 +763,9 @@ def fetch_file_from_central(self, filepath):
752763

753764
return filepath
754765

755-
raise ValueError("File communication protocol '%s' as defined in plugins configuration is NOT defined." % self._plugincoupling)
766+
raise ValueError(
767+
("File communication protocol '%s' as defined in plugins "
768+
"configuration is NOT defined.") % self._plugincoupling)
756769

757770
def push_file_to_central(self, filepath):
758771
if self._plugincoupling == 'filesystem':
@@ -761,9 +774,12 @@ def push_file_to_central(self, filepath):
761774
if self._plugincoupling == 'https':
762775
logger.debug('Submitting file %s to qiita server.' % filepath)
763776

764-
self.post('/cloud/push_file_to_central/',
777+
self.post(
778+
'/cloud/push_file_to_central/',
765779
files={os.path.dirname(filepath): open(filepath, 'rb')})
766780

767781
return filepath
768782

769-
raise ValueError("File communication protocol '%s' as defined in plugins configuration is NOT defined." % self._plugincoupling)
783+
raise ValueError(
784+
("File communication protocol '%s' as defined in plugins "
785+
"configuration is NOT defined.") % self._plugincoupling)

0 commit comments

Comments
 (0)