Merge ~smoser/cloud-init:cleanup/fix-tip-pycodestyle-invalid-escape-sequences into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Chad Smith
Approved revision: 6f500dae89dc309001a12f1e878c1fe694201bf1
Merge reported by: Chad Smith
Merged at revision: acca826adf39ddfedde78cfbfc47e81a06c6f42a
Proposed branch: ~smoser/cloud-init:cleanup/fix-tip-pycodestyle-invalid-escape-sequences
Merge into: cloud-init:master
Diff against target: 135 lines (+13/-13)
8 files modified
cloudinit/analyze/__main__.py (+1/-1)
cloudinit/config/cc_apt_configure.py (+1/-1)
cloudinit/config/cc_power_state_change.py (+1/-1)
cloudinit/config/cc_rsyslog.py (+2/-2)
cloudinit/distros/freebsd.py (+3/-3)
cloudinit/util.py (+3/-3)
tests/cloud_tests/testcases/base.py (+1/-1)
tests/unittests/test_util.py (+1/-1)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+343041@code.launchpad.net

Commit message

pycodestyle: Fix invalid escape sequences in string literals.

Python has deprecated these invalid string literals now
  https://bugs.python.org/issue27364
and pycodestyle is identifying them with a W605 warning.
  https://github.com/PyCQA/pycodestyle/pull/676

So basically, any use of \ not followed by one of [\'"abfnrtv]
or \ooo (octal) \xhh (hex) or a newline is invalid. This is most
comomnly seen for us in regex. To solve, you either:
 a.) use a raw string r'...'
 b.) correctly escape the \ that was not intended to be interpreted.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:ada58c9f2ce211117958e47c78eecfeeafe79060
https://jenkins.ubuntu.com/server/job/cloud-init-ci/985/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/985/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:6f500dae89dc309001a12f1e878c1fe694201bf1
https://jenkins.ubuntu.com/server/job/cloud-init-ci/986/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/986/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

+1

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=acca826a

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/analyze/__main__.py b/cloudinit/analyze/__main__.py
2index 3ba5903..f861365 100644
3--- a/cloudinit/analyze/__main__.py
4+++ b/cloudinit/analyze/__main__.py
5@@ -69,7 +69,7 @@ def analyze_blame(name, args):
6 """
7 (infh, outfh) = configure_io(args)
8 blame_format = ' %ds (%n)'
9- r = re.compile('(^\s+\d+\.\d+)', re.MULTILINE)
10+ r = re.compile(r'(^\s+\d+\.\d+)', re.MULTILINE)
11 for idx, record in enumerate(show.show_events(_get_events(infh),
12 blame_format)):
13 srecs = sorted(filter(r.match, record), reverse=True)
14diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py
15index 5b9cbca..afaca46 100644
16--- a/cloudinit/config/cc_apt_configure.py
17+++ b/cloudinit/config/cc_apt_configure.py
18@@ -121,7 +121,7 @@ and https protocols respectively. The ``proxy`` key also exists as an alias for
19 All source entries in ``apt-sources`` that match regex in
20 ``add_apt_repo_match`` will be added to the system using
21 ``add-apt-repository``. If ``add_apt_repo_match`` is not specified, it defaults
22-to ``^[\w-]+:\w``
23+to ``^[\\w-]+:\\w``
24
25 **Add source list entries:**
26
27diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
28index 4da3a58..50b3747 100644
29--- a/cloudinit/config/cc_power_state_change.py
30+++ b/cloudinit/config/cc_power_state_change.py
31@@ -74,7 +74,7 @@ def givecmdline(pid):
32 if util.is_FreeBSD():
33 (output, _err) = util.subp(['procstat', '-c', str(pid)])
34 line = output.splitlines()[1]
35- m = re.search('\d+ (\w|\.|-)+\s+(/\w.+)', line)
36+ m = re.search(r'\d+ (\w|\.|-)+\s+(/\w.+)', line)
37 return m.group(2)
38 else:
39 return util.load_file("/proc/%s/cmdline" % pid)
40diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
41index af08788..27d2366 100644
42--- a/cloudinit/config/cc_rsyslog.py
43+++ b/cloudinit/config/cc_rsyslog.py
44@@ -203,8 +203,8 @@ LOG = logging.getLogger(__name__)
45 COMMENT_RE = re.compile(r'[ ]*[#]+[ ]*')
46 HOST_PORT_RE = re.compile(
47 r'^(?P<proto>[@]{0,2})'
48- '(([[](?P<bracket_addr>[^\]]*)[\]])|(?P<addr>[^:]*))'
49- '([:](?P<port>[0-9]+))?$')
50+ r'(([[](?P<bracket_addr>[^\]]*)[\]])|(?P<addr>[^:]*))'
51+ r'([:](?P<port>[0-9]+))?$')
52
53
54 def reload_syslog(command=DEF_RELOAD, systemd=False):
55diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
56index 754d3df..099fac5 100644
57--- a/cloudinit/distros/freebsd.py
58+++ b/cloudinit/distros/freebsd.py
59@@ -110,7 +110,7 @@ class Distro(distros.Distro):
60 if dev.startswith('lo'):
61 return dev
62
63- n = re.search('\d+$', dev)
64+ n = re.search(r'\d+$', dev)
65 index = n.group(0)
66
67 (out, err) = util.subp(['ifconfig', '-a'])
68@@ -118,7 +118,7 @@ class Distro(distros.Distro):
69 if len(x.split()) > 0]
70 bsddev = 'NOT_FOUND'
71 for line in ifconfigoutput:
72- m = re.match('^\w+', line)
73+ m = re.match(r'^\w+', line)
74 if m:
75 if m.group(0).startswith('lo'):
76 continue
77@@ -128,7 +128,7 @@ class Distro(distros.Distro):
78 break
79
80 # Replace the index with the one we're after.
81- bsddev = re.sub('\d+$', index, bsddev)
82+ bsddev = re.sub(r'\d+$', index, bsddev)
83 LOG.debug("Using network interface %s", bsddev)
84 return bsddev
85
86diff --git a/cloudinit/util.py b/cloudinit/util.py
87index acdc0d8..1717b52 100644
88--- a/cloudinit/util.py
89+++ b/cloudinit/util.py
90@@ -1446,7 +1446,7 @@ def get_config_logfiles(cfg):
91 for fmt in get_output_cfg(cfg, None):
92 if not fmt:
93 continue
94- match = re.match('(?P<type>\||>+)\s*(?P<target>.*)', fmt)
95+ match = re.match(r'(?P<type>\||>+)\s*(?P<target>.*)', fmt)
96 if not match:
97 continue
98 target = match.group('target')
99@@ -2275,8 +2275,8 @@ def parse_mount(path):
100 # the regex is a bit complex. to better understand this regex see:
101 # https://regex101.com/r/2F6c1k/1
102 # https://regex101.com/r/T2en7a/1
103- regex = r'^(/dev/[\S]+|.*zroot\S*?) on (/[\S]*) ' + \
104- '(?=(?:type)[\s]+([\S]+)|\(([^,]*))'
105+ regex = (r'^(/dev/[\S]+|.*zroot\S*?) on (/[\S]*) '
106+ r'(?=(?:type)[\s]+([\S]+)|\(([^,]*))')
107 for line in mount_locs:
108 m = re.search(regex, line)
109 if not m:
110diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
111index 7598d46..4fda8f9 100644
112--- a/tests/cloud_tests/testcases/base.py
113+++ b/tests/cloud_tests/testcases/base.py
114@@ -235,7 +235,7 @@ class CloudTestCase(unittest.TestCase):
115 'found unexpected kvm availability-zone %s' %
116 v1_data['availability-zone'])
117 self.assertIsNotNone(
118- re.match('[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}',
119+ re.match(r'[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}',
120 v1_data['instance-id']),
121 'kvm instance-id is not a UUID: %s' % v1_data['instance-id'])
122 self.assertIn('ubuntu', v1_data['local-hostname'])
123diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
124index 5010190..7cbd553 100644
125--- a/tests/unittests/test_util.py
126+++ b/tests/unittests/test_util.py
127@@ -800,7 +800,7 @@ class TestSubp(helpers.CiTestCase):
128
129 os.chmod(noshebang, os.stat(noshebang).st_mode | stat.S_IEXEC)
130 self.assertRaisesRegex(util.ProcessExecutionError,
131- 'Missing #! in script\?',
132+ r'Missing #! in script\?',
133 util.subp, (noshebang,))
134
135 def test_returns_none_if_no_capture(self):

Subscribers

People subscribed via source and target branches