Skip to content

Commit c641d2a

Browse files
committed
Adopt pbr
Change-Id: Iad928d789ce7acf2e07e56c2b0b8a2a659c5d193
1 parent 1c45a17 commit c641d2a

25 files changed

+142
-126
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ lib/
2121
*.sw?
2222
/jenkinsapi_tests/systests/coverage.xml
2323
/.cache
24+
/AUTHORS
25+
/ChangeLog

.travis.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,32 @@ env:
1111
before_install:
1212
- jdk_switcher use oraclejdk8
1313
install:
14-
- pip install -r requirements/dev-requirements.txt
15-
- python setup.py develop
14+
- pip install tox-travis
15+
- python setup.py -q sdist bdist_wheel
1616
script:
17-
- make lint
18-
- make coverage
17+
- tox
1918
after_success:
2019
- codecov
20+
branches:
21+
only:
22+
- master
23+
- develop
24+
- /^(\d+)\.(\d+)\.(\d+)$/
25+
jobs:
26+
include:
27+
- stage: release
28+
python: 2.7
29+
script: python setup.py -q sdist bdist_wheel
30+
deploy:
31+
provider: releases
32+
api_key:
33+
secure: Ac6anfwQu0WyVj7q9GqD1OJI3WTM3Lk0xO42oJwh4EphXpRCFGvgE4XjaPxh4qVHlgIw8AQ4Phpm0UYal/XTLVNuJDPHOdOUUxUJdJYQkW3hT2odOSCPU47Xa0/pGHIrgX3gEOTO0hAjziL5c41cGR2wMWFp6/CObIg3+gqtrzk=
34+
file_glob: true
35+
file:
36+
- dist/*
37+
- ChangeLog
38+
- AUTHORS
39+
skip_cleanup: true
40+
on:
41+
repo: pycontribs/jenkinsapi
42+
tags: true

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test:
44
py.test -sv jenkinsapi_tests
55

66
lint:
7-
pep8
7+
pycodestyle
88
pylint jenkinsapi/*.py
99

1010
tox:

examples/how_to/create_credentials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
def get_private_key_from_file():
3535
return '-----BEGIN RSA PRIVATE KEY-----'
3636

37+
3738
my_private_key = get_private_key_from_file()
3839

3940
creds_description2 = 'My_ssh_cred1'

examples/low_level/example_param_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ def foo():
1616
response = requests.post(url, data=form, headers=headers)
1717
print(response.text.encode('UTF-8'))
1818

19+
1920
if __name__ == '__main__':
2021
foo()

examples/low_level/post_watcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import cgi
2323

2424
PORT = 8081 # <-- change this to be the actual port you want to run on
25-
I = "localhost"
25+
INTERFACE = "localhost"
2626

2727

2828
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
@@ -55,6 +55,6 @@ def do_POST(self):
5555
print(
5656
"Serving at: http://%(interface)s:%(port)s" %
5757
dict(
58-
interface=I or "localhost",
58+
interface=INTERFACE or "localhost",
5959
port=PORT))
6060
httpd.serve_forever()

jenkinsapi/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
About this library
33
==================
44
5-
Jenkins is the market leading continuous integration system, originally created by Kohsuke Kawaguchi.
6-
This API makes Jenkins even easier to use by providing an easy to use conventional python interface.
7-
8-
Jenkins (and It's predecessor Hudson) are fantastic projects - but they are somewhat Java-centric.
9-
Thankfully the designers have provided an excellent and complete REST interface. This library
10-
wraps up that interface as more conventional python objects in order to make most Jenkins oriented
5+
Jenkins is the market leading continuous integration system, originally created
6+
by Kohsuke Kawaguchi. This API makes Jenkins even easier to use by providing an
7+
easy to use conventional python interface.
8+
9+
Jenkins (and It's predecessor Hudson) are fantastic projects - but they are
10+
somewhat Java-centric. Thankfully the designers have provided an excellent and
11+
complete REST interface. This library wraps up that interface as more
12+
conventional python objects in order to make most Jenkins oriented
1113
tasks simpler.
1214
1315
This library can help you:
@@ -24,8 +26,8 @@
2426
Installing JenkinsAPI
2527
=====================
2628
27-
Egg-files for this project are hosted on PyPi. Most Python users should be able to use pip or distribute
28-
to automatically install this project.
29+
Egg-files for this project are hosted on PyPi. Most Python users should be able
30+
to use pip or distribute to automatically install this project.
2931
3032
Most users can do the following:
3133
@@ -52,14 +54,16 @@
5254
utils,
5355

5456
# Files
55-
api, artifact, build, config, constants, custom_exceptions, fingerprint, executors, executor,
57+
api, artifact, build, config, constants, custom_exceptions,
58+
fingerprint, executors, executor,
5659
jenkins, jenkinsbase, job, node, result_set, result, view
5760
)
5861

5962
__all__ = [
6063
"command_line", "utils",
61-
"api", "artifact", "build", "config", "constants", "custom_exceptions", "executors", "executor",
62-
"fingerprint", "jenkins", "jenkinsbase", "job", "node", "result_set", "result", "view"
64+
"api", "artifact", "build", "config", "constants", "custom_exceptions",
65+
"executors", "executor", "fingerprint", "jenkins", "jenkinsbase",
66+
"job", "node", "result_set", "result", "view"
6367
]
6468
__docformat__ = "epytext"
6569
# In case of jenkinsapi is not installed in 'develop' mode

jenkinsapi/artifact.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,12 @@ def _md5sum(self, fspath, chunksize=2 ** 20):
111111
used by Jenkins.
112112
"""
113113
md5 = hashlib.md5()
114-
try:
115-
with open(fspath, 'rb') as f:
116-
for chunk in iter(lambda: f.read(chunksize), ''):
117-
if chunk:
118-
md5.update(chunk)
119-
else:
120-
break
121-
except:
122-
raise
114+
with open(fspath, 'rb') as f:
115+
for chunk in iter(lambda: f.read(chunksize), ''):
116+
if chunk:
117+
md5.update(chunk)
118+
else:
119+
break
123120
return md5.hexdigest()
124121

125122
def save_to_dir(self, dirpath, strict_validation=False):

jenkinsapi/command_line/jenkinsapi_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
def main():
88
sys.stdout.write(version)
99

10+
1011
if __name__ == '__main__':
1112
main()

jenkinsapi/job.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def invoke(self, securitytoken=None, block=False,
184184
params['token'] = securitytoken
185185

186186
# Either copy the params dict or make a new one.
187-
build_params = dict(build_params.items()) if build_params else {} # Via POSTed JSON
187+
build_params = dict(build_params.items()) \
188+
if build_params else {} # Via POSTed JSON
188189

189190
url = self.get_build_triggerurl()
190191
if cause:
@@ -719,7 +720,8 @@ def has_queued_build(self, build_params):
719720
@staticmethod
720721
def get_full_name_from_url_and_baseurl(url, baseurl):
721722
"""
722-
Get the full name for a job (including parent folders) from the job URL.
723+
Get the full name for a job (including parent folders) from the
724+
job URL.
723725
"""
724726
path = url.replace(baseurl, '')
725727
split = path.split('/')

jenkinsapi/jobs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def __getitem__(self, job_name):
8080
if job_name in self:
8181
job_data = [job_row for job_row in self._data
8282
if job_row['name'] == job_name or
83-
Job.get_full_name_from_url_and_baseurl(job_row['url'], self.jenkins.baseurl) == job_name][0]
83+
Job.get_full_name_from_url_and_baseurl(
84+
job_row['url'],
85+
self.jenkins.baseurl) == job_name][0]
8486
return Job(job_data['url'], job_data['name'], self.jenkins)
8587
else:
8688
raise UnknownJob(job_name)
@@ -108,8 +110,11 @@ def iterkeys(self):
108110
self._data = self.poll().get('jobs', [])
109111
for row in self._data:
110112
yield row['name']
111-
if row['name'] != Job.get_full_name_from_url_and_baseurl(row['url'], self.jenkins.baseurl):
112-
yield Job.get_full_name_from_url_and_baseurl(row['url'], self.jenkins.baseurl)
113+
if row['name'] != \
114+
Job.get_full_name_from_url_and_baseurl(row['url'],
115+
self.jenkins.baseurl):
116+
yield Job.get_full_name_from_url_and_baseurl(
117+
row['url'], self.jenkins.baseurl)
113118

114119
def itervalues(self):
115120
"""

jenkinsapi/utils/krb_requester.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def __init__(self, ssl_verify=None, baseurl=None, mutual_auth=OPTIONAL):
1717
:param ssl_verify: flag indicating if server certificate in HTTPS requests should be
1818
verified
1919
:param baseurl: Jenkins' base URL
20-
:param mutual_auth: type of mutual authentication, use one of REQUIRED, OPTIONAL or DISABLED
20+
:param mutual_auth: type of mutual authentication, use one of
21+
REQUIRED, OPTIONAL or DISABLED
2122
from requests_kerberos package
2223
"""
2324
args = {}
@@ -30,8 +31,11 @@ def __init__(self, ssl_verify=None, baseurl=None, mutual_auth=OPTIONAL):
3031

3132
def get_request_dict(
3233
self, params=None, data=None, files=None, headers=None, **kwargs):
33-
req_dict = super(KrbRequester, self).get_request_dict(params=params, data=data, files=files,
34-
headers=headers)
34+
req_dict = super(KrbRequester, self) \
35+
.get_request_dict(params=params,
36+
data=data,
37+
files=files,
38+
headers=headers)
3539
if self.mutual_auth:
3640
auth = HTTPKerberosAuth(self.mutual_auth)
3741
else:

jenkinsapi_tests/systests/job_configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
</hudson.tasks.Fingerprinter>
269269
</publishers>
270270
<buildWrappers/>
271-
</project>""".strip()
271+
</project>""".strip() # noqa
272272

273273
JOB_WITH_FILE_AND_PARAMS = """
274274
<?xml version='1.0' encoding='UTF-8'?>

jenkinsapi_tests/test_utils/random_strings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ def random_string(length=10):
88
return ''.join(random.choice(string.ascii_lowercase)
99
for i in range(length))
1010

11+
1112
if __name__ == '__main__':
1213
print(random_string())

jenkinsapi_tests/unittests/test_artifact.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ def test_save_has_valid_local_copy(self, mock_exists):
163163
artifact = self._artifact
164164
artifact._verify_download = Mock(return_value=True)
165165

166-
assert artifact.save('/tmp/artifact.zip') == \
167-
'/tmp/artifact.zip'
166+
assert artifact.save('/tmp/artifact.zip') == '/tmp/artifact.zip'
168167

169168
mock_exists.assert_called_once_with('/tmp/artifact.zip')
170169
artifact._verify_download.assert_called_once_with(
@@ -176,8 +175,7 @@ def test_save_has_invalid_local_copy_dl_again(self, mock_exists):
176175
artifact._verify_download = Mock(side_effect=[ArtifactBroken, True])
177176
artifact._do_download = Mock(return_value='/tmp/artifact.zip')
178177

179-
assert artifact.save('/tmp/artifact.zip', True) == \
180-
'/tmp/artifact.zip'
178+
assert artifact.save('/tmp/artifact.zip', True) == '/tmp/artifact.zip'
181179

182180
mock_exists.assert_called_once_with('/tmp/artifact.zip')
183181
artifact._do_download.assert_called_once_with('/tmp/artifact.zip')
@@ -206,8 +204,7 @@ def test_save_has_no_local_copy(self, mock_exists):
206204
artifact._do_download = Mock(return_value='/tmp/artifact.zip')
207205
artifact._verify_download = Mock(return_value=True)
208206

209-
assert artifact.save('/tmp/artifact.zip') == \
210-
'/tmp/artifact.zip'
207+
assert artifact.save('/tmp/artifact.zip') == '/tmp/artifact.zip'
211208

212209
mock_exists.assert_called_once_with('/tmp/artifact.zip')
213210
artifact._do_download.assert_called_once_with('/tmp/artifact.zip')

jenkinsapi_tests/unittests/test_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ def test_only_ParametersAction_parameters_considered(build):
156156
params = build.get_params()
157157
assert params == expected
158158

159+
159160
def test_build_env_vars(monkeypatch, build):
160161
def fake_get_data(cls, tree=None, params=None):
161162
return configs.BUILD_ENV_VARS
162163
monkeypatch.setattr(Build, 'get_data', fake_get_data)
163164
assert build.get_env_vars() == configs.BUILD_ENV_VARS['envMap']
164165

166+
165167
def test_build_env_vars_wo_injected_env_vars_plugin(monkeypatch, build):
166168
def fake_get_data(cls, tree=None, params=None):
167169
raise requests.HTTPError('404')
@@ -176,6 +178,7 @@ def fake_get_data(cls, tree=None, params=None):
176178
'plugin is installed.')
177179
assert str(record[0].message) == str(expected)
178180

181+
179182
def test_build_env_vars_other_exception(monkeypatch, build):
180183
def fake_get_data(cls, tree=None, params=None):
181184
raise ValueError()
@@ -186,4 +189,3 @@ def fake_get_data(cls, tree=None, params=None):
186189
build.get_env_vars()
187190
assert '' == str(excinfo.value)
188191
assert len(record) == 0
189-

jenkinsapi_tests/unittests/test_job_get_all_builds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def test_get_build_dict(self):
192192
@mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree)
193193
def test_incomplete_builds_list_will_call_jenkins_twice(self):
194194
# The job data contains only one build, so we expect that the
195-
# remaining jobs will be fetched automatically, and to have two calls to
196-
# the Jenkins API
195+
# remaining jobs will be fetched automatically, and to have two calls
196+
# to the Jenkins API
197197
TestJobGetAllBuilds.__get_data_call_count = 0
198198
self.j = Job('http://halob:8080/job/foo/', 'foo', self.J)
199199
self.assertEquals(TestJobGetAllBuilds.__get_data_call_count, 2)

jenkinsapi_tests/unittests/test_misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def test_jenkinsapi_version():
66
package's __version__ property.
77
"""
88
version = jenkinsapi.__version__
9-
parts = [int(x) for x in version.split('.')]
9+
# only first two parts must be interger, 1.0.dev5 being a valid version.
10+
parts = [int(x) for x in version.split('.')[0:2]]
1011
for part in parts:
1112
assert part >= 0, "Implausible version number: %r" % version

jenkinsapi_tests/unittests/test_result_set.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class TestResultSet(unittest.TestCase):
1616
'passCount': 0,
1717
'skipCount': 0,
1818
'suites': [{'cases': [{'age': 1,
19-
'className': '<nose.suite.ContextSuite context=jenkinsapi_tests',
19+
'className': '<nose.suite.ContextSuite context=jenkinsapi_tests', # noqa
2020
'duration': 0.0,
21-
'errorDetails': 'Timeout error occured while waiting for Jenkins start.',
22-
'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 208, in run\n self.setUp()\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 291, in setUp\n self.setupContext(ancestor)\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 314, in setupContext\n try_run(context, names)\n File "/usr/lib/python2.7/dist-packages/nose/util.py", line 478, in try_run\n return func()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 54, in setUpPackage\n launcher = JenkinsLauncher(update_war=True, launch=True)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 20, in __init__\n self.launch()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 41, in launch\n raise Timeout(\'Timeout error occured while waiting for Jenkins start.\')\nTimeout: Timeout error occured while waiting for Jenkins start.\n',
21+
'errorDetails': 'Timeout error occured while waiting for Jenkins start.', # noqa
22+
'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 208, in run\n self.setUp()\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 291, in setUp\n self.setupContext(ancestor)\n File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 314, in setupContext\n try_run(context, names)\n File "/usr/lib/python2.7/dist-packages/nose/util.py", line 478, in try_run\n return func()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 54, in setUpPackage\n launcher = JenkinsLauncher(update_war=True, launch=True)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 20, in __init__\n self.launch()\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/systests/__init__.py", line 41, in launch\n raise Timeout(\'Timeout error occured while waiting for Jenkins start.\')\nTimeout: Timeout error occured while waiting for Jenkins start.\n', # noqa
2323
'failedSince': 88,
2424
'name': 'systests>:setup',
2525
'skipped': False,
@@ -30,7 +30,7 @@ class TestResultSet(unittest.TestCase):
3030
'className': 'nose.failure.Failure',
3131
'duration': 0.0,
3232
'errorDetails': 'No module named mock',
33-
'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/unittest/case.py", line 332, in run\n testMethod()\n File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName\n addr.filename, addr.module)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath\n return self.importFromDir(dir_path, fqname)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir\n mod = load_module(part_fqname, fh, filename, desc)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/unittests/test_build.py", line 1, in <module>\n import mock\nImportError: No module named mock\n',
33+
'errorStackTrace': 'Traceback (most recent call last):\n File "/usr/lib/python2.7/unittest/case.py", line 332, in run\n testMethod()\n File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName\n addr.filename, addr.module)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath\n return self.importFromDir(dir_path, fqname)\n File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir\n mod = load_module(part_fqname, fh, filename, desc)\n File "/var/lib/jenkins/jobs/test_jenkinsapi/workspace/jenkinsapi/src/jenkinsapi_tests/unittests/test_build.py", line 1, in <module>\n import mock\nImportError: No module named mock\n', # noqa
3434
'failedSince': 88,
3535
'name': 'runTest',
3636
'skipped': False,

jenkinsapi_utils/simple_post_logger.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def do_POST(self):
2626
logging.error(item)
2727
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
2828

29+
2930
Handler = ServerHandler
3031

3132
httpd = SocketServer.TCPServer(("", PORT), Handler)

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytz>=2014.4
2+
requests>=2.3.0
3+
six>=1.10.0

0 commit comments

Comments
 (0)