Skip to content

Commit

Permalink
Removal of gevents as it is incompatible with Python 2.7.8 and becaus…
Browse files Browse the repository at this point in the history
…e we can use requests threading for the same purpose.
  • Loading branch information
ssbarnea committed Jan 5, 2015
1 parent 5c845da commit 3148a8b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
27 changes: 15 additions & 12 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@
except ImportError:
import random

if 'pydevd' not in sys.modules:
try:
import grequests
except ImportError:
pass
except NotImplementedError:
pass

#warnings.simplefilter('default')
# warnings.simplefilter('default')

#encoding = sys.getdefaultencoding()
# if encoding != 'UTF8':
# warnings.warn("Python default encoding is '%s' instead of 'UTF8' which means that there is a big change of having problems. Possible workaround http://stackoverflow.com/a/17628350/99834" % encoding)


def threaded_requests(requests):
for fn, url, request_args in requests:
th = threading.Thread(
target=fn, args=(url,), kwargs=request_args, name=url,
)
th.start()

for th in threading.enumerate():
if th.name.startswith('http'):
th.join()


def translate_resource_args(func):
"""
Decorator that converts Issue and Project resources to their keys when used as arguments.
Expand Down Expand Up @@ -244,7 +248,7 @@ def async_do(self, size=10):
"""
if hasattr(self._session, '_async_jobs'):
logging.info("Executing async %s jobs found in queue by using %s threads..." % (len(self._session._async_jobs), size))
grequests.map(self._session._async_jobs, size=size)
threaded_requests.map(self._session._async_jobs, size=size)

# Application properties

Expand Down Expand Up @@ -1791,7 +1795,7 @@ def rename_user(self, old_user, new_user):
:param old_user: string with username login
:param new_user: string with username login
"""

if self._version >= (6, 0, 0):

url = self._options['server'] + '/rest/api/2/user'
Expand All @@ -1807,7 +1811,6 @@ def rename_user(self, old_user, new_user):
r = self._session.put(url, params=params, headers={'content-type': 'application/json'}, data=json.dumps(payload))
raise_on_error(r)


else:
# old implementation needed the ScripRunner plugin
merge = "true"
Expand Down
6 changes: 3 additions & 3 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def update(self, async=None, jira=None, **kwargs):
# data['fields']['assignee'] = {'name': self._options['autofix']}
# EXPERIMENTAL --->
# import grequests
if async and 'grequests' in sys.modules:
if async:
if not hasattr(self._session, '_async_jobs'):
self._session._async_jobs = set()
self._session._async_jobs.add(grequests.put(self.self, headers={'content-type': 'application/json'}, data=json.dumps(data)))
self._session._async_jobs.add(threaded_requests.put(self.self, headers={'content-type': 'application/json'}, data=json.dumps(data)))
else:
r = self._session.put(self.self, headers={'content-type': 'application/json'}, data=json.dumps(data))
raise_on_error(r)
Expand All @@ -181,7 +181,7 @@ def delete(self, params=None):
if self._options['async']:
if not hasattr(self._session, '_async_jobs'):
self._session._async_jobs = set()
self._session._async_jobs.add(grequests.delete(self.self, params=params))
self._session._async_jobs.add(threaded_requests.delete(self.self, params=params))
else:
r = self._session.delete(self.self, params=params)
raise_on_error(r)
Expand Down
2 changes: 1 addition & 1 deletion jira/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into the jira module
__version__ = '0.32'
__version__ = '0.33'
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
extras_require={
'magic': ['filemagic>=1.6'],
'shell': ['ipython>=0.13'],
'parallel': ['grequests'],
},
entry_points={
'console_scripts':
Expand Down

0 comments on commit 3148a8b

Please sign in to comment.