From c2ca09b9b939b1309d82d092bd88f7e9a2a99ec6 Mon Sep 17 00:00:00 2001 From: afabiani Date: Thu, 15 Nov 2018 13:10:44 +0100 Subject: [PATCH] - preparing for test suite / introducing pep8 format checks --- autopep8.sh | 6 + flake8.sh | 6 + requirements.txt | 23 +- setup.cfg | 5 + setup.py | 69 ++-- src/wpsremote/ConfigParser.py | 37 ++- src/wpsremote/__init__.py | 1 - src/wpsremote/action.py | 22 +- src/wpsremote/bus.py | 5 +- src/wpsremote/busIndipendentMessages.py | 41 ++- src/wpsremote/command_line_parameter.py | 22 +- src/wpsremote/computation_job_const.py | 6 +- src/wpsremote/computation_job_input.py | 85 ++--- src/wpsremote/computation_job_inputs.py | 56 ++-- src/wpsremote/computation_job_param.py | 20 +- .../computational_job_input_action.py | 1 + ...omputational_job_input_action_cmd_param.py | 27 +- ...computational_job_input_action_copyfile.py | 5 +- ...ional_job_input_action_create_json_file.py | 39 +-- ...tional_job_input_action_update_ini_file.py | 65 ++-- ...ional_job_input_action_update_json_file.py | 40 +-- .../computational_job_input_actions.py | 65 ++-- src/wpsremote/configInstance.py | 81 ++--- src/wpsremote/config_file_parameter.py | 17 +- .../config_file_parameter_cmre_oaa.py | 164 ++++++---- src/wpsremote/decryptor.py | 8 +- src/wpsremote/encryptor.py | 8 +- src/wpsremote/ftpUpload.py | 28 +- src/wpsremote/ftpsUpload.py | 39 ++- src/wpsremote/input_parameter.py | 67 ++-- src/wpsremote/input_parameters.py | 158 +++++----- src/wpsremote/introspection.py | 31 +- src/wpsremote/mockutils.py | 11 +- src/wpsremote/output_file_parameter.py | 149 +++++---- src/wpsremote/output_parameters.py | 69 ++-- src/wpsremote/path.py | 72 +++-- src/wpsremote/process_test.py | 26 +- src/wpsremote/processbot.py | 296 +++++++++++------- src/wpsremote/resource_cleaner.py | 233 +++++++------- src/wpsremote/resource_monitor.py | 47 ++- src/wpsremote/serviceTester.py | 199 ++++++------ src/wpsremote/servicebot.py | 192 +++++++----- src/wpsremote/sftpUpload.py | 30 +- src/wpsremote/termination_handler.py | 45 +-- src/wpsremote/upload.py | 3 +- src/wpsremote/wpsagent.py | 163 ++++++---- src/wpsremote/xmppBus.py | 135 ++++---- src/wpsremote/xmppMessages.py | 120 +++---- .../xmpp_data/configs/myservice/code/test.py | 35 +-- test/__init__.py | 1 - test/test_computation_job_inputs.py | 291 +++++++++-------- test/test_process_input_parameters.py | 61 ++-- test_suite.sh | 9 + 53 files changed, 1944 insertions(+), 1490 deletions(-) create mode 100644 autopep8.sh create mode 100644 flake8.sh create mode 100644 test_suite.sh diff --git a/autopep8.sh b/autopep8.sh new file mode 100644 index 0000000..d0aa246 --- /dev/null +++ b/autopep8.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +autopep8 -v -i -a -a -r *.py +autopep8 -v -i -a -a -r src +autopep8 -v -i -a -a -r test diff --git a/flake8.sh b/flake8.sh new file mode 100644 index 0000000..370efd0 --- /dev/null +++ b/flake8.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +flake8 *.py +flake8 src/wpsremote +flake8 test diff --git a/requirements.txt b/requirements.txt index ca7898b..ff7fb47 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,28 @@ +asn1crypto==0.24.0 astroid==1.4.4 +autopep8==1.4.3 +bcrypt==3.1.4 +cffi==1.11.5 colorama==0.3.6 +cryptography==2.3.1 +enum34==1.1.6 flake8==2.5.4 functools32==3.2.3.post2 +idna==2.7 +ipaddress==1.0.22 jsonschema==2.5.1 lazy-object-proxy==1.2.1 mccabe==0.4.0 -pep8==1.7.0 -psutil==4.0.0 +paramiko==2.4.1 +pep8==1.7.1 +psutil==5.4.7 +pyasn1==0.4.4 +pycodestyle==2.4.0 +pycparser==2.18 +pycrypto==2.6.1 pyflakes==1.0.0 pylint==1.5.4 +PyNaCl==1.2.1 six==1.10.0 -sleekxmpp==1.3.1 -wheel==0.24.0 -wrapt==1.10.6 +sleekxmpp==1.3.3 +wrapt==1.10.10 diff --git a/setup.cfg b/setup.cfg index b88034e..79f906a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,7 @@ [metadata] description-file = README.md + +[flake8] +max-line-length = 120 +exclude=management,scripts,docs,static +ignore=E121,E122,E124,E126,E226 diff --git a/setup.py b/setup.py index fc9375f..a5d6944 100644 --- a/setup.py +++ b/setup.py @@ -24,25 +24,38 @@ python setup.py bdist --format=gztar upload -r pypi python setup.py bdist_wheel upload -r pypi """ -from setuptools import setup, find_packages +try: # for pip >= 10 + from pip._internal.req import parse_requirements + from pip._internal.download import PipSession +except ImportError: # for pip <= 9.0.3 + from pip.req import parse_requirements + from pip.download import PipSession +from distutils.core import setup + +from setuptools import find_packages + +# Parse requirements.txt to get the list of dependencies +inst_req = parse_requirements('requirements.txt', + session=PipSession()) +REQUIREMENTS = [str(r.req) for r in inst_req] try: readme_text = file('README.md', 'rb').read() -except IOError,e: +except IOError as e: readme_text = '' setup( - name = "wps-remote", - version = "2.15.0", - author = "GeoServer Developers", - author_email = "geoserver-devel@lists.sourceforge.net", - description = "A library that allows users to publish their executables as GeoServer WPS Processes through the XMPP protocol", - keywords = "XMPP Beckend for GeoServer Remote WPS ProcessFactory.", - long_description = readme_text, - license = "GPL", - url = "https://github.com/geoserver/wps-remote", - #https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers = [ + name="wps-remote", + version="2.15.0", + author="GeoServer Developers", + author_email="geoserver-devel@lists.sourceforge.net", + description="A library that allows users to publish their executables as GeoServer WPS Processes through the XMPP protocol", # noqa + keywords="XMPP Beckend for GeoServer Remote WPS ProcessFactory.", + long_description=readme_text, + license="GPL", + url="https://github.com/geoserver/wps-remote", + # https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ 'Environment :: Web Environment', 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', 'Intended Audience :: Developers', @@ -51,9 +64,9 @@ 'Programming Language :: Python', 'Topic :: Scientific/Engineering :: GIS', ], - package_dir = {'':'src'}, - packages = find_packages('src'), - package_data = { + package_dir={'': 'src'}, + packages=find_packages('src'), + package_data={ '': [ 'xmpp_data/*.*', 'xmpp_data/configs/*.*', @@ -67,25 +80,7 @@ 'xmpp_data/test/*.*', ] }, - include_package_data = True, - test_suite = "test", - install_requires = [ - "astroid==1.4.4", - "colorama==0.3.6", - "flake8==2.5.4", - "functools32", - "jsonschema==2.5.1", - "lazy-object-proxy==1.2.1", - "mccabe==0.4.0", - "paramiko", - "pep8==1.7.0", - "psutil>=4.0.0", - "pycrypto", - "pyflakes==1.0.0", - "pylint==1.5.4", - "six==1.10.0", - "sleekxmpp>=1.3.1", - "wheel==0.24.0", - "wrapt==1.10.10", - ], + include_package_data=True, + test_suite="test", + install_requires=REQUIREMENTS, ) diff --git a/src/wpsremote/ConfigParser.py b/src/wpsremote/ConfigParser.py index a6a18c0..ef12c9e 100644 --- a/src/wpsremote/ConfigParser.py +++ b/src/wpsremote/ConfigParser.py @@ -4,6 +4,9 @@ # This code is licensed under the GPL 2.0 license, available at the root # application directory. +import re +import UserDict as _UserDict + __author__ = "Alessio Fabiani" __copyright__ = "Copyright 2016 Open Source Geospatial Foundation - all rights reserved" __license__ = "GPL" @@ -103,8 +106,6 @@ # fallback for setup.py which hasn't yet built _collections _default_dict = dict -import re - __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError", "InterpolationError", "InterpolationDepthError", "InterpolationSyntaxError", "ParsingError", @@ -117,7 +118,6 @@ MAX_INTERPOLATION_DEPTH = 10 - # exception classes class Error(Exception): """Base class for ConfigParser exceptions.""" @@ -146,6 +146,7 @@ def __repr__(self): __str__ = __repr__ + class NoSectionError(Error): """Raised when no section matches a requested option.""" @@ -154,6 +155,7 @@ def __init__(self, section): self.section = section self.args = (section, ) + class DuplicateSectionError(Error): """Raised when a section is multiply-created.""" @@ -162,6 +164,7 @@ def __init__(self, section): self.section = section self.args = (section, ) + class NoOptionError(Error): """A requested option was not found.""" @@ -172,6 +175,7 @@ def __init__(self, option, section): self.section = section self.args = (option, section) + class InterpolationError(Error): """Base class for interpolation-related exceptions.""" @@ -181,6 +185,7 @@ def __init__(self, option, section, msg): self.section = section self.args = (option, section, msg) + class InterpolationMissingOptionError(InterpolationError): """A string substitution required a setting which was not available.""" @@ -195,10 +200,12 @@ def __init__(self, option, section, rawval, reference): self.reference = reference self.args = (option, section, rawval, reference) + class InterpolationSyntaxError(InterpolationError): """Raised when the source text into which substitutions are made does not conform to the required syntax.""" + class InterpolationDepthError(InterpolationError): """Raised when substitutions are nested too deeply.""" @@ -211,6 +218,7 @@ def __init__(self, option, section, rawval): InterpolationError.__init__(self, option, section, msg) self.args = (option, section, rawval) + class ParsingError(Error): """Raised when a configuration file does not follow legal syntax.""" @@ -224,6 +232,7 @@ def append(self, lineno, line): self.errors.append((lineno, line)) self.message += '\n\t[line %2d]: %s' % (lineno, line) + class MissingSectionHeaderError(ParsingError): """Raised when a key-value pair is found before any section header.""" @@ -268,7 +277,7 @@ def add_section(self, section): case-insensitive variants. """ if section.lower() == "default": - raise ValueError, 'Invalid section name: %s' % section + raise ValueError('Invalid section name: %s' % section) if section in self._sections: raise DuplicateSectionError(section) @@ -377,7 +386,7 @@ def getfloat(self, section, option): def getboolean(self, section, option): v = self.get(section, option) if v.lower() not in self._boolean_states: - raise ValueError, 'Not a boolean: %s' % v + raise ValueError('Not a boolean: %s' % v) return self._boolean_states[v.lower()] def optionxform(self, optionstr): @@ -392,8 +401,8 @@ def has_option(self, section, option): return False else: option = self.optionxform(option) - return (option in self._sections[section] - or option in self._defaults) + return (option in self._sections[section] or + option in self._defaults) def set(self, section, option, value=None): """Set an option.""" @@ -452,7 +461,7 @@ def remove_section(self, section): r'\[' # [ r'(?P
[^]]+)' # very permissive! r'\]' # ] - ) + ) OPTCRE = re.compile( r'(?P