Update hacking for Python3

The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Update local hacking checks for new flake8.

Remove hacking and friends from lower-constraints, it's not needed
there.

Change-Id: Iadf750a1e6d3181b645ceccdf75cf910bc23adfd
This commit is contained in:
Andreas Jaeger 2020-04-01 09:58:36 +02:00
parent dc8956d7b8
commit b306576d27
7 changed files with 32 additions and 22 deletions

View File

@ -19,8 +19,9 @@
def main():
"""health check for Monasca-persister"""
#TODO wait for health check endpoint ...
# TODO(Christian Brandstetter) wait for health check endpoint ...
return 0
if __name__ == '__main__':
main()

View File

@ -8,13 +8,11 @@ docutils==0.11
elasticsearch==2.0.0
extras==1.0.0
fixtures==3.0.0
flake8==2.5.5
future==0.16.0
gevent==1.2.2
gitdb==0.6.4
GitPython==1.0.1
greenlet==0.4.10
hacking==0.12.0
influxdb==2.9.2
iso8601==0.1.11
kazoo==2.2
@ -40,8 +38,6 @@ oslo.serialization==2.18.0
oslo.utils==3.33.0
oslotest==3.2.0
pbr==2.0.0
pep8==1.7.1
pyflakes==1.0.0
pyinotify==0.9.6
PyMySQL==0.7.6
pyparsing==2.1.0

View File

@ -11,8 +11,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import re
from hacking import core
assert_no_xrange_re = re.compile(r"\s*xrange\s*\(")
assert_True = re.compile(r".*assertEqual\(True, .*\)")
assert_None = re.compile(r".*assertEqual\(None, .*\)")
@ -23,17 +27,20 @@ no_log_warn = re.compile(r".*LOG.warn\(.*\)")
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
@core.flake8ext
def no_mutable_default_args(logical_line):
msg = "M001: Method's default argument shouldn't be mutable!"
if mutable_default_args.match(logical_line):
yield (0, msg)
@core.flake8ext
def no_xrange(logical_line):
if assert_no_xrange_re.match(logical_line):
yield (0, "M002: Do not use xrange().")
@core.flake8ext
def validate_assertTrue(logical_line):
if re.match(assert_True, logical_line):
msg = ("M003: Unit tests should use assertTrue(value) instead"
@ -41,6 +48,7 @@ def validate_assertTrue(logical_line):
yield (0, msg)
@core.flake8ext
def validate_assertIsNone(logical_line):
if re.match(assert_None, logical_line):
msg = ("M004: Unit tests should use assertIsNone(value) instead"
@ -48,12 +56,14 @@ def validate_assertIsNone(logical_line):
yield (0, msg)
@core.flake8ext
def no_log_warn_check(logical_line):
if re.match(no_log_warn, logical_line):
msg = ("M005: LOG.warn is deprecated, please use LOG.warning!")
yield (0, msg)
@core.flake8ext
def validate_assertIsNotNone(logical_line):
if re.match(assert_Not_Equal, logical_line) or \
re.match(assert_Is_Not, logical_line):
@ -63,18 +73,9 @@ def validate_assertIsNotNone(logical_line):
yield (0, msg)
@core.flake8ext
def assert_raisesRegexp(logical_line):
res = assert_raises_regexp.search(logical_line)
if res:
yield (0, "M007: assertRaisesRegex must be used instead "
"of assertRaisesRegexp")
def factory(register):
register(no_mutable_default_args)
register(no_xrange)
register(validate_assertTrue)
register(validate_assertIsNone)
register(no_log_warn_check)
register(validate_assertIsNotNone)
register(assert_raisesRegexp)

View File

@ -132,7 +132,7 @@ def main():
# Start
try:
LOG.info('''
LOG.info(r'''
_____
/ \ ____ ____ _____ ______ ____ _____
@ -164,5 +164,6 @@ def main():
LOG.exception('Error! Exiting.')
clean_exit(signal.SIGKILL)
if __name__ == "__main__":
sys.exit(main())

View File

@ -173,9 +173,9 @@ htmlhelp_basename = 'MonitoringApiReleaseNotesDoc'
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [(
master_doc, 'MonitoringPersiterReleaseNotes.tex',
u'Monitoring Persister Release Notes', [author],
'manual'
master_doc, 'MonitoringPersiterReleaseNotes.tex',
u'Monitoring Persister Release Notes', [author],
'manual'
)]
# The name of an image file (relative to this directory) to place at the top of

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.
bandit>=1.1.0 # Apache-2.0
flake8<2.6.0,>=2.5.4 # MIT
hacking>=1.1.0,<1.2.0 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0

15
tox.ini
View File

@ -88,8 +88,19 @@ commands =
# B303 cassandra metrics repository uses SHA1 for metric_id
bandit -r monasca_persister -n5 -s B303 -x monasca_persister/tests
[hacking]
local-check-factory = monasca_persister.hacking.checks.factory
[flake8:local-plugins]
extension =
def factory(register):
M001 = checks:no_mutable_default_args
M002 = checks:no_xrange
M003 = checks:validate_assertTrue
M004 = checks:validate_assertIsNone
M005 = checks:no_log_warn_check
M006 = checks:validate_assertIsNotNone
M007 = checks:assert_raisesRegexp
paths = ./monasca_persister/hacking
[testenv:lower-constraints]
basepython = python3