diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 8513f5df2..a37de91a5 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -155,8 +155,9 @@ class JenkinsManager(object): self.jenkins.delete_job(job_name) def get_plugins_info(self): - """ Return a list of plugin_info dicts, one for each plugin on the - Jenkins instance. + """Return a list of plugin_info dicts. + + Returns one for each plugin on the Jenkins instance. """ try: plugins_list = self.jenkins.get_plugins().values() diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py index 3aa24fe17..5a5637176 100644 --- a/jenkins_jobs/cli/entry.py +++ b/jenkins_jobs/cli/entry.py @@ -35,7 +35,8 @@ def __version__(): class JenkinsJobs(object): - """ This is the entry point class for the `jenkins-jobs` command line tool. + """This is the entry point class for the `jenkins-jobs` command line tool. + While this class can be used programmatically by external users of the JJB API, the main goal here is to abstract the `jenkins_jobs` tool in a way that prevents test suites from caring overly much about various diff --git a/jenkins_jobs/cli/parser.py b/jenkins_jobs/cli/parser.py index 379426540..d8e0ee572 100644 --- a/jenkins_jobs/cli/parser.py +++ b/jenkins_jobs/cli/parser.py @@ -29,8 +29,7 @@ def __version__(): def create_parser(): - """ Create an ArgumentParser object usable by JenkinsJobs. - """ + """Create an ArgumentParser object usable by JenkinsJobs.""" parser = argparse.ArgumentParser() parser.add_argument( "--conf", diff --git a/jenkins_jobs/cli/subcommand/base.py b/jenkins_jobs/cli/subcommand/base.py index 0e5c7bfe8..cd78f1124 100644 --- a/jenkins_jobs/cli/subcommand/base.py +++ b/jenkins_jobs/cli/subcommand/base.py @@ -50,8 +50,7 @@ class BaseSubCommand(object): @staticmethod def parse_option_recursive_exclude(parser): - """Add '--recursive' and '--exclude' arguments to given parser. - """ + """Add '--recursive' and '--exclude' arguments to given parser.""" parser.add_argument( "-r", "--recursive", diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py index 5b630c92d..fbb446a24 100644 --- a/jenkins_jobs/config.py +++ b/jenkins_jobs/config.py @@ -145,8 +145,7 @@ class JJBConfig(object): config_fp.close() def _init_defaults(self): - """ Initialize default configuration values using DEFAULT_CONF - """ + """Initialize default configuration values using DEFAULT_CONF.""" config = configparser.ConfigParser() # Load default config always if PY2: @@ -156,9 +155,7 @@ class JJBConfig(object): return config def _read_config_file(self, config_filename): - """ Given path to configuration file, read it in as a ConfigParser - object and return that object. - """ + """Return a ConfigParser object from a file input.""" if os.path.isfile(config_filename): self.__config_file = config_filename # remember file we read from logger.debug("Reading config from {0}".format(config_filename)) @@ -354,7 +351,9 @@ class JJBConfig(object): raise JenkinsJobsException("plugins_info must contain a list!") def get_module_config(self, section, key, default=None): - """ Given a section name and a key value, return the value assigned to + """Returns the value of a config in a config module. + + Given a section name and a key value, return the value assigned to the key in the JJB .ini file if it exists, otherwise emit a warning indicating that the value is not set. Default value returned if no value is set in the file will be a blank string. diff --git a/jenkins_jobs/formatter.py b/jenkins_jobs/formatter.py index 470646f0e..075e5a25c 100644 --- a/jenkins_jobs/formatter.py +++ b/jenkins_jobs/formatter.py @@ -27,8 +27,11 @@ logger = logging.getLogger(__name__) def deep_format(obj, paramdict, allow_empty=False): - """Apply the paramdict via str.format() to all string objects found within - the supplied obj. Lists and dicts are traversed recursively.""" + """Deep format configuration. + + Apply the paramdict via str.format() to all string objects found within + the supplied obj. Lists and dicts are traversed recursively. + """ # YAML serialisation was originally used to achieve this, but that places # limitations on the values in paramdict - the post-format result must # still be valid YAML (so substituting-in a string containing quotes, for diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 126afd959..c7f61a95b 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -1171,8 +1171,7 @@ def gradle(registry, xml_parent, data): def _groovy_common_scriptSource(data): - """Helper function to generate the XML element common to groovy builders - """ + """Helper function to generate the XML element common to groovy builders.""" scriptSource = XML.Element("scriptSource") if "command" in data and "file" in data: @@ -4004,8 +4003,8 @@ def build_publish_docker_image(registry, xml_parent, data): registry (default '') :arg bool clean-images: Option to clean local images (default false) :arg bool jenkins-job-delete: Attempt to remove images when jenkins - deletes the run (default false) - :arg str cloud: Cloud to use to build image (default '') + deletes the run (default false) + :arg str cloud: Cloud to use to build image (default '') Minimal example: diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index 178e30116..00ea48578 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -26,12 +26,10 @@ import pkg_resources def build_trends_publisher(plugin_name, xml_element, data): - """Helper to create various trend publishers. - """ + """Helper to create various trend publishers.""" def append_thresholds(element, data, only_totals): - """Appends the status thresholds. - """ + """Appends the status thresholds.""" for status in ["unstable", "failed"]: status_data = data.get(status, {}) diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py index 3601fe541..0c9640f0d 100644 --- a/jenkins_jobs/modules/hipchat_notif.py +++ b/jenkins_jobs/modules/hipchat_notif.py @@ -98,8 +98,9 @@ class HipChat(jenkins_jobs.modules.base.Base): def _load_global_data(self): """Load data from the global config object. - This is done lazily to avoid looking up the '[hipchat]' section - unless actually required. + + This is done lazily to avoid looking up the '[hipchat]' section + unless actually required. """ jjb_config = self.registry.jjb_config if not self.authToken: diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index ca446a158..333dd7005 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2141,8 +2141,7 @@ def checkstyle(registry, xml_parent, data): """ def convert_settings(lookup, data): - """Helper to convert settings from one key to another - """ + """Helper to convert settings from one key to another.""" for old_key in list(data.keys()): if old_key in lookup: diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 13ce06a9c..51df009d1 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -51,8 +51,7 @@ def gerrit_handle_legacy_configuration(data): hyphenizer = re.compile("[A-Z]") def hyphenize(attr): - """Convert strings like triggerOn to trigger-on. - """ + """Convert strings like triggerOn to trigger-on.""" return hyphenizer.sub(lambda x: "-%s" % x.group(0).lower(), attr) def convert_dict(d, old_keys): diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py index 5f1d7f9c1..dba00dfe7 100644 --- a/jenkins_jobs/registry.py +++ b/jenkins_jobs/registry.py @@ -88,9 +88,10 @@ class ModuleRegistry(object): return plugins_info_dict def get_plugin_info(self, plugin_name): - """ This method is intended to provide information about plugins within - a given module's implementation of Base.gen_xml. The return value is a - dictionary with data obtained directly from a running Jenkins instance. + """Provide information about plugins within a module's impl of Base.gen_xml. + + The return value is a dictionary with data obtained directly from a + running Jenkins instance. This allows module authors to differentiate generated XML output based on information such as specific plugin versions. diff --git a/jenkins_jobs/xml_config.py b/jenkins_jobs/xml_config.py index fabc72127..73ffd67a5 100644 --- a/jenkins_jobs/xml_config.py +++ b/jenkins_jobs/xml_config.py @@ -110,8 +110,9 @@ class XmlGenerator(object): class XmlJobGenerator(XmlGenerator): - """ This class is responsible for generating Jenkins Configuration XML from - a compatible intermediate representation of Jenkins Jobs. + """Class for generating Jenkins Configuration XML. + + Generates XML from a compatible intermediate representation of Jenkins Jobs. """ entry_point_group = "jenkins_jobs.projects" @@ -120,8 +121,9 @@ class XmlJobGenerator(XmlGenerator): class XmlViewGenerator(XmlGenerator): - """ This class is responsible for generating Jenkins Configuration XML from - a compatible intermediate representation of Jenkins Views. + """Class for generating Jenkins Configuration XML. + + Generates XML from a compatible intermediate representation of Jenkins Views. """ entry_point_group = "jenkins_jobs.views" diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index ee7d93a7b..87e4e68ab 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -243,7 +243,9 @@ class TestTests(CmdTestsBase): class TestJenkinsGetPluginInfoError(CmdTestsBase): - """ This test class is used for testing the 'test' subcommand when we want + """Test without mocking get_plugins_info. + + This test class is used for testing the 'test' subcommand when we want to validate its behavior without mocking jenkins_jobs.builder.JenkinsManager.get_plugins_info """ @@ -354,7 +356,7 @@ class MatchesDir(object): for root, _, files in os.walk(directory): return files - def __str__(self,): + def __str__(self, directory): return "MatchesDir({0})".format(self.__dirname) def match(self, other_directory): diff --git a/tests/cmd/subcommands/test_update.py b/tests/cmd/subcommands/test_update.py index f755f4b87..3206d71ff 100644 --- a/tests/cmd/subcommands/test_update.py +++ b/tests/cmd/subcommands/test_update.py @@ -79,8 +79,7 @@ class UpdateTests(CmdTestsBase): jenkins_get_all_jobs, jenkins_job_exists, ): - """ - Test update behaviour with --delete-old option + """Test update behaviour with --delete-old option. * mock out a call to jenkins.Jenkins.get_jobs() to return a known list of job names. @@ -117,11 +116,9 @@ class UpdateTests(CmdTestsBase): self.assertEqual(jenkins_delete_job.call_count, len(calls)) def test_update_timeout_not_set(self): - """Validate update timeout behavior when timeout not explicitly configured. - """ + """Validate update timeout behavior when timeout not explicitly configured.""" self.skipTest("TODO: Develop actual update timeout test approach.") def test_update_timeout_set(self): - """Validate update timeout behavior when timeout is explicitly configured. - """ + """Validate update timeout behavior when timeout is explicitly configured.""" self.skipTest("TODO: Develop actual update timeout test approach.")