Skip to content

Commit

Permalink
Pyflake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lechat committed Jan 25, 2023
1 parent b999a86 commit b184882
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 81 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: ci

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: py${{ matrix.python-version }}-jenkins-stable
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["2.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Setup the Pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: >-
${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}-${{
hashFiles('setup.py') }}-${{ hashFiles('tox.ini') }}-${{
hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install Dependencies
run: |
sudo apt-get update; sudo apt-get install gcc libkrb5-dev
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
- name: Test with tox
env:
JENKINS_VERSION=stable
run: tox

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.1
with:
file: ./coverage.xml
name: ${{ runner.os }}-${{ matrix.python-version }}
22 changes: 13 additions & 9 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# JenkinsAPI documentation build configuration file, created by
# sphinx-quickstart on Mon Jan 09 16:35:17 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
Expand All @@ -29,16 +30,17 @@
"salimfadhley@gmail.com, ramon@vanalteren.nl, ruslan.lutcenko@gmail.com"
)
PROJECT_URL = "https://github.com/salimfadhley/jenkinsapi"
SHORT_DESCRIPTION = "A Python API for accessing resources on a Jenkins continuous-integration server."
SHORT_DESCRIPTION = "A Python API for accessing resources on a Jenkins \
continuous-integration server."
# CHANGE THIS

# -- General configuration -----------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
Expand Down Expand Up @@ -83,7 +85,8 @@
# directories to ignore when looking for source files.
exclude_patterns = []

# The reST default role (used for this markup: `text`) to use for all documents.
# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
Expand Down Expand Up @@ -188,15 +191,16 @@

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
("index", "JenkinsAPI.tex", "JenkinsAPI Documentation", "xxx", "manual"),
]
Expand Down
1 change: 0 additions & 1 deletion jenkinsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
Current code lives on github: https://github.com/salimfadhley/jenkinsapi
"""
import sys
from jenkinsapi import (
# Modules
command_line,
Expand Down
3 changes: 2 additions & 1 deletion jenkinsapi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def _get_git_repo_url(self):
_actions = [
x for x in self._data["actions"] if x and "lastBuiltRevision" in x
]
# old Jenkins version have key remoteUrl v/s the new version has a list remoteUrls
# old Jenkins version have key remoteUrl v/s the new version
# has a list remoteUrls
result = _actions[0].get("remoteUrls", _actions[0].get("remoteUrl"))
if isinstance(result, list):
result = ",".join(result)
Expand Down
7 changes: 4 additions & 3 deletions jenkinsapi/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class UsernamePasswordCredential(Credential):
"""

def __init__(self, cred_dict):
jenkins_class = "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"
jenkins_class = "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" # noqa
super(UsernamePasswordCredential, self).__init__(
cred_dict, jenkins_class
)
Expand Down Expand Up @@ -220,7 +220,7 @@ class SSHKeyCredential(Credential):
"""

def __init__(self, cred_dict):
jenkins_class = "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
jenkins_class = "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey" # noqa
super(SSHKeyCredential, self).__init__(cred_dict, jenkins_class)
if "typeName" in cred_dict:
username = cred_dict["displayName"].split(" ")[0]
Expand Down Expand Up @@ -304,7 +304,8 @@ def get_attributes_xml(self):
class AmazonWebServicesCredentials(Credential):
"""
AWS credential using the CloudBees AWS Credentials Plugin
See https://wiki.jenkins.io/display/JENKINS/CloudBees+AWS+Credentials+Plugin
See
https://wiki.jenkins.io/display/JENKINS/CloudBees+AWS+Credentials+Plugin
Constructor expects following dict:
{
Expand Down
45 changes: 25 additions & 20 deletions jenkinsapi/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def create_node_with_config(self, name, config):
Create a new slave node with specific configuration.
Config should be resemble the output of node.get_node_attributes()
:param str name: name of slave
:param dict config: Node attributes for Jenkins API request to create node
:param dict config: Node attributes for Jenkins API request
to create node
(See function output Node.get_node_attributes())
:return: node obj
"""
Expand All @@ -403,8 +404,8 @@ def install_plugin(
Install a plugin and optionally restart jenkins.
@param plugin: Plugin (string or Plugin object) to be installed
@param restart: Boolean, restart Jenkins when required by plugin
@param force_restart: Boolean, force Jenkins to restart, ignoring plugin
preferences
@param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
@param no_warning: Don't show warning when restart is needed and
restart parameters are set to False
"""
Expand All @@ -429,11 +430,11 @@ def install_plugins(
):
"""
Install a list of plugins and optionally restart jenkins.
@param plugin_list: List of plugins (strings, Plugin objects or a mix of
the two) to be installed
@param plugin_list: List of plugins (strings, Plugin objects or
a mix of the two) to be installed
@param restart: Boolean, restart Jenkins when required by plugin
@param force_restart: Boolean, force Jenkins to restart, ignoring plugin
preferences
@param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
"""
plugins = [
p if isinstance(p, Plugin) else Plugin(p) for p in plugin_list
Expand Down Expand Up @@ -461,8 +462,8 @@ def delete_plugin(
dependencies.
@param plugin: Plugin (string or Plugin object) to be deleted
@param restart: Boolean, restart Jenkins when required by plugin
@param force_restart: Boolean, force Jenkins to restart, ignoring plugin
preferences
@param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
"""
if isinstance(plugin, Plugin):
plugin = plugin.shortName
Expand All @@ -484,13 +485,13 @@ def delete_plugins(
no_reboot_warning=False,
):
"""
Delete a list of plugins and optionally restart jenkins. Will not delete
dependencies.
@param plugin_list: List of plugins (strings, Plugin objects or a mix of
the two) to be deleted
Delete a list of plugins and optionally restart jenkins. Will not
delete dependencies.
@param plugin_list: List of plugins (strings, Plugin objects or
a mix of the two) to be deleted
@param restart: Boolean, restart Jenkins when required by plugin
@param force_restart: Boolean, force Jenkins to restart, ignoring plugin
preferences
@param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
"""
for plugin in plugin_list:
self.delete_plugin(plugin, restart=False, no_reboot_warning=True)
Expand Down Expand Up @@ -561,7 +562,9 @@ def __jenkins_is_unavailable(self):
time.sleep(1)

def safe_exit(self, wait_for_exit=True, max_wait=360):
"""restarts jenkins when no jobs are running, except for pipeline jobs"""
"""
Restarts jenkins when no jobs are running, except for pipeline jobs
"""
# NB: unlike other methods, the value of resp.status_code
# here can be 503 even when everything is normal
url = "%s/safeExit" % (self.baseurl,)
Expand Down Expand Up @@ -603,8 +606,10 @@ def __jenkins_is_unresponsive(self, max_wait=360):
is_alive = True

def quiet_down(self):
"""Put Jenkins in a Quiet mode, preparation for restart. no new builds started"""
# https://support.cloudbees.com/hc/en-us/articles/216118748-How-to-Start-Stop-or-Restart-your-Instance-
"""
Put Jenkins in a Quiet mode, preparation for restart.
No new builds started
"""
# NB: unlike other methods, the value of resp.status_code
# here can be 503 even when everything is normal
url = "%s/quietDown" % (self.baseurl,)
Expand All @@ -616,7 +621,6 @@ def quiet_down(self):

def cancel_quiet_down(self):
"""Cancel the effect of the quiet-down command"""
# https://support.cloudbees.com/hc/en-us/articles/216118748-How-to-Start-Stop-or-Restart-your-Instance-
# NB: unlike other methods, the value of resp.status_code
# here can be 503 even when everything is normal
url = "%s/cancelQuietDown" % (self.baseurl,)
Expand Down Expand Up @@ -690,7 +694,8 @@ def shutdown(self):
def generate_new_api_token(
self, new_token_name="Token By jenkinsapi python"
):
subUrl = "/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken"
subUrl = "/me/descriptorByName/jenkins.security.\
ApiTokenProperty/generateNewToken"
url = "%s%s" % (self.baseurl, subUrl)
data = urlencode({"newTokenName": new_token_name})
response = self.requester.post_and_confirm_status(url, data=data)
Expand Down
3 changes: 2 additions & 1 deletion jenkinsapi/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ def get_scm_type(self):
element_tree = self._get_config_element_tree()
scm_element = element_tree.find("scm")
if not scm_element:
multibranch_scm_prefix = "properties/org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty/branch/"
multibranch_scm_prefix = "properties/org.jenkinsci.plugins.\
workflow.multibranch.BranchJobProperty/branch/"
multibranch_path = multibranch_scm_prefix + "scm"
scm_element = element_tree.find(multibranch_path)
if scm_element:
Expand Down
3 changes: 2 additions & 1 deletion jenkinsapi/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def create_multibranch_pipeline(

start_time = time.time()
# redirect-url does not work with indexing;
# so the only workaround found is to parse the console output untill scan has finished.
# so the only workaround found is to parse the console output
# until scan has finished.
scan_finished = False
while not scan_finished and block and time.time() < start_time + delay:
indexing_console_text = self.jenkins.requester.get_url(
Expand Down
9 changes: 5 additions & 4 deletions jenkinsapi/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, jenkins_obj, baseurl, nodename, node_dict, poll=True):
],
'tool_location': [
{
"key": "hudson.tasks.Maven$MavenInstallation$DescriptorImpl@Maven 3.0.5",
"key": "hudson.tasks.Maven$MavenInstallation$DescriptorImpl@Maven 3.0.5", # noqa
"home": "/home/apache-maven-3.0.5/"
},
{
Expand Down Expand Up @@ -406,8 +406,8 @@ def set_config_element(self, el_name, value):

def get_monitor(self, monitor_name, poll_monitor=True):
"""
Polls the node returning one of the monitors in the monitorData branch of the
returned node api tree.
Polls the node returning one of the monitors in the monitorData
branch of the returned node api tree.
"""
monitor_data_key = "monitorData"
if poll_monitor:
Expand Down Expand Up @@ -516,7 +516,8 @@ def get_response_time(self):

def get_clock_difference(self):
"""
Returns the difference between the node's clock and the master Jenkins clock.
Returns the difference between the node's clock and
the master Jenkins clock.
Used to detect out of sync clocks.
"""
monitor_data = self.get_monitor("ClockMonitor")
Expand Down
15 changes: 8 additions & 7 deletions jenkinsapi/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def iterkeys(self):
"""
Return an iterator over the container's node names.
Using iterkeys() while creating nodes may raise a RuntimeError or fail to iterate over all
entries.
Using iterkeys() while creating nodes may raise a RuntimeError
or fail to iterate over all entries.
"""
for item in self._data["computer"]:
yield item["displayName"]
Expand All @@ -71,8 +71,8 @@ def iteritems(self):
"""
Return an iterator over the container's (name, node) pairs.
Using iteritems() while creating nodes may raise a RuntimeError or fail to iterate over all
entries.
Using iteritems() while creating nodes may raise a RuntimeError or
fail to iterate over all entries.
"""
for item in self._data["computer"]:
nodename = item["displayName"]
Expand All @@ -91,8 +91,8 @@ def itervalues(self):
"""
Return an iterator over the container's nodes.
Using itervalues() while creating nodes may raise a RuntimeError or fail to iterate over
all entries.
Using itervalues() while creating nodes may raise a RuntimeError
or fail to iterate over all entries.
"""
for item in self._data["computer"]:
try:
Expand Down Expand Up @@ -169,7 +169,8 @@ def create_node_with_config(self, name, config):
Create a new slave node with specific configuration.
Config should be resemble the output of node.get_node_attributes()
:param str name: name of slave
:param dict config: Node attributes for Jenkins API request to create node
:param dict config: Node attributes for Jenkins API request
to create node
(See function output Node.get_node_attributes())
:return: node obj
"""
Expand Down
7 changes: 4 additions & 3 deletions jenkinsapi/utils/krb_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
class KrbRequester(Requester):

"""
A class which carries out HTTP requests with Kerberos/GSSAPI authentication.
A class which carries out HTTP requests with Kerberos/GSSAPI
authentication.
"""

def __init__(self, *args, **kwargs):
"""
:param ssl_verify: flag indicating if server certificate in HTTPS requests should be
verified
:param ssl_verify: flag indicating if server certificate
in HTTPS requests should be verified
:param baseurl: Jenkins' base URL
:param mutual_auth: type of mutual authentication, use one of
REQUIRED, OPTIONAL or DISABLED
Expand Down
2 changes: 2 additions & 0 deletions jenkinsapi_tests/systests/test_env_vars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
System tests for `jenkinsapi.jenkins` module.
"""
import time

from jenkinsapi_tests.systests.job_configs import JOB_WITH_ENV_VARS
from jenkinsapi_tests.test_utils.random_strings import random_string

Expand Down
Loading

0 comments on commit b184882

Please sign in to comment.