Skip to content

Commit cef0824

Browse files
committed
Changed the way we load the version in setup.py in order to properly perform coverage.
Also added fallback on add_attachment for the case where we do not have the filestreamer module.
1 parent ee96af6 commit cef0824

8 files changed

+57
-20
lines changed

.coveragerc

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[run]
22
data_file = .coverage
33
source = jira
4+
branch = True
45

56
[report]
67
exclude_lines =
@@ -9,3 +10,5 @@ exclude_lines =
910
raise AssertionError
1011
raise NotImplementedError
1112
if __name__ == .__main__.:
13+
14+
ignore_errors = True

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Feeling impatient? I like your style.
4141

4242
.. code-block:: python
4343
44-
from jira.client import JIRA
44+
from jira import JIRA
4545
4646
jira = JIRA('https://jira.atlassian.com')
4747

examples/basic_auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This script shows how to connect to a JIRA instance with a
22
# username and password over HTTP BASIC authentication.
33

4-
from jira.client import JIRA
4+
from jira import JIRA
55

66
# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK.
77
# See

examples/basic_use.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This script shows how to use the client in anonymous mode
22
# against jira.atlassian.com.
33

4-
from jira.client import JIRA
4+
from jira import JIRA
55

66
# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK
77
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).

jira/client.py

+38-11
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727

2828
from six import string_types, integer_types
2929
from six.moves import html_parser
30-
from requests_toolbelt import MultipartEncoder
3130
import requests
31+
try:
32+
from requests_toolbelt import MultipartEncoder
33+
except:
34+
pass
3235

3336
# JIRA specific resources
3437
from jira.resources import Resource, Issue, Comment, Project, Attachment, Component, Dashboard, Filter, Votes, Watchers, \
@@ -37,6 +40,7 @@
3740
# GreenHopper specific resources
3841
from jira.resources import GreenHopperResource, Board, Sprint
3942
from jira.resilientsession import ResilientSession
43+
from jira import __version__
4044
from .utils import threaded_requests, json_loads, JIRAError, CaseInsensitiveDict
4145

4246
try:
@@ -52,6 +56,9 @@
5256
# if encoding != 'UTF8':
5357
# 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)
5458

59+
# we do want to log warrning from our code
60+
logging.captureWarnings(True)
61+
5562

5663
def translate_resource_args(func):
5764
"""
@@ -205,6 +212,20 @@ def __init__(self, server=None, options=None, basic_auth=None, oauth=None, valid
205212
globals()['logging'].error("invalid server_info: %s", si)
206213
raise e
207214

215+
self._check_update_()
216+
217+
def _check_update_(self):
218+
# check if the current version of the library is outdated
219+
import json
220+
import urllib2
221+
response = urllib2.urlopen(
222+
"http://pypi.python.org/pypi/jira/json")
223+
data = json.load(response)
224+
released_version = data['info']['version']
225+
if released_version > __version__:
226+
warnings.warn("You are running an outdated version of JIRA Python %s. Current version is %s. Do not file any bugs against older versions." % (
227+
__version__, released_version))
228+
208229
def __del__(self):
209230
session = getattr(self, "_session", None)
210231
if session is not None:
@@ -355,14 +376,21 @@ def add_attachment(self, issue, attachment, filename=None):
355376
if not fname:
356377
fname = os.path.basename(attachment.name)
357378

358-
def file_stream():
359-
return MultipartEncoder(
360-
fields={
361-
'file': (fname, attachment, 'text/plain')}
362-
)
363-
m = file_stream()
364-
r = self._session.post(
365-
url, data=m, headers=CaseInsensitiveDict({'content-type': m.content_type}), retry_data=file_stream) # 'multipart/form-data'
379+
if 'MultipartEncoder' not in globals():
380+
r = self._session.post(
381+
url,
382+
files={
383+
'file': (fname, attachment, 'application/octet-stream')},
384+
headers=CaseInsensitiveDict({'content-type': None}))
385+
else:
386+
def file_stream():
387+
return MultipartEncoder(
388+
fields={
389+
'file': (fname, attachment, 'text/plain')}
390+
)
391+
m = file_stream()
392+
r = self._session.post(
393+
url, data=m, headers=CaseInsensitiveDict({'content-type': m.content_type}), retry_data=file_stream)
366394

367395
attachment = Attachment(self._options, self._session, json_loads(r)[0])
368396
return attachment
@@ -2402,8 +2430,7 @@ def create_sprint(self, name, board_id, startDate=None, endDate=None):
24022430
"remoteLinks": []
24032431
}"""
24042432

2405-
payload = {}
2406-
payload['name'] = name
2433+
payload = {'name': name}
24072434
if startDate:
24082435
payload["startDate"] = startDate
24092436
if endDate:

jira/jirashell.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from requests_oauthlib import OAuth1
2424

2525
import webbrowser
26-
from jira.client import JIRA
27-
from jira import __version__
26+
from jira import JIRA, __version__
2827

2928
CONFIG_PATH = os.path.join(
3029
os.path.expanduser('~'), '.jira-python', 'jirashell.ini')

jira/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# 1) we don't load dependencies by storing it in __init__.py
44
# 2) we can import it in setup.py for the same reason
55
# 3) we can import it into the jira module
6-
__version__ = '0.35'
6+
__version__ = '0.36'

setup.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/usr/bin/env python
22
import logging
33
import os
4+
import re
45
import sys
56
import warnings
67

78
from setuptools import setup, find_packages, Command
89
from setuptools.command.test import test as TestCommand
910

1011
NAME = "jira"
11-
from jira import __version__
1212

13+
# Get the version - do not use normal import because it does break coverage
14+
base_path = os.path.dirname(__file__)
15+
fp = open(os.path.join(base_path, NAME, 'version.py'))
16+
__version__ = re.compile(r".*__version__ = '(.*?)'",
17+
re.S).match(fp.read()).group(1)
18+
fp.close()
1319

1420

1521
# this should help getting annoying warnings from inside distutils
1622
warnings.simplefilter('ignore', UserWarning)
1723

24+
1825
class PyTest(TestCommand):
1926
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
2027

@@ -47,6 +54,7 @@ def initialize_options(self):
4754
try:
4855
import coveralls
4956
self.pytest_args.append("--cov=%s" % NAME)
57+
self.pytest_args.extend(["--cov-report", "term"])
5058
self.pytest_args.extend(["--cov-report", "xml"])
5159

5260
except ImportError:
@@ -133,7 +141,7 @@ def run(self):
133141
bugtrack_url='https://github.com/pycontribs/jira/issues',
134142
home_page='https://github.com/pycontribs/jira',
135143
keywords='jira atlassian rest api',
136-
144+
137145
classifiers=[
138146
'Programming Language :: Python',
139147
'Programming Language :: Python :: 2.5',
@@ -146,7 +154,7 @@ def run(self):
146154
'License :: OSI Approved :: BSD License',
147155
'Operating System :: OS Independent',
148156
'Topic :: Software Development :: Libraries :: Python Modules',
149-
'Programming Language :: Python :: 2.6',
157+
'Programming Language :: Python :: 2.6',
150158
'Programming Language :: Python :: 2.7',
151159
'Programming Language :: Python :: 3.3',
152160
'Programming Language :: Python :: 3.4',

0 commit comments

Comments
 (0)