[arvados] created: 2.6.0-341-g6daa187dc
git repository hosting
git at public.arvados.org
Wed Jul 5 21:02:57 UTC 2023
at 6daa187dccdc8d7513417d5122fd145661647617 (commit)
commit 6daa187dccdc8d7513417d5122fd145661647617
Author: Brett Smith <brett.smith at curii.com>
Date: Wed Jul 5 16:58:07 2023 -0400
20343: Define Python regexps with raw strings
Prevent the DeprecationWarning added to Python 3.6 for unrecognized
string escape sequences. Found candidates by running:
git grep --line-number -E '\bre\.\w+\([^r]*\\'
Most of the changes just add the raw string prefix `r` to these regexps,
but I did make some other readability improvements while I was at it,
including switching from regexps to plain string test methods where
appropriate.
Arvados-DCO-1.1-Signed-off-by: Brett Smith <brett.smith at curii.com>
diff --git a/sdk/cwl/arvados_cwl/arvworkflow.py b/sdk/cwl/arvados_cwl/arvworkflow.py
index 43d23e9b9..cddcd15c5 100644
--- a/sdk/cwl/arvados_cwl/arvworkflow.py
+++ b/sdk/cwl/arvados_cwl/arvworkflow.py
@@ -51,6 +51,21 @@ metrics = logging.getLogger('arvados.cwl-runner.metrics')
max_res_pars = ("coresMin", "coresMax", "ramMin", "ramMax", "tmpdirMin", "tmpdirMax")
sum_res_pars = ("outdirMin", "outdirMax")
+_basetype_re = re.compile(r'''(?:
+Directory
+|File
+|array
+|boolean
+|double
+|enum
+|float
+|int
+|long
+|null
+|record
+|string
+)(?:\[\])?\??''', re.VERBOSE)
+
def make_wrapper_workflow(arvRunner, main, packed, project_uuid, name, git_info, tool):
col = arvados.collection.Collection(api_client=arvRunner.api,
keep_client=arvRunner.keep_client)
@@ -161,12 +176,7 @@ def rel_ref(s, baseuri, urlexpander, merged_map, jobmapper):
return os.path.join(r, p3)
def is_basetype(tp):
- basetypes = ("null", "boolean", "int", "long", "float", "double", "string", "File", "Directory", "record", "array", "enum")
- for b in basetypes:
- if re.match(b+"(\[\])?\??", tp):
- return True
- return False
-
+ return _basetype_re.match(tp) is not None
def update_refs(d, baseuri, urlexpander, merged_map, jobmapper, runtimeContext, prefix, replacePrefix):
if isinstance(d, MutableSequence):
diff --git a/sdk/python/arvados/_normalize_stream.py b/sdk/python/arvados/_normalize_stream.py
index 485c757e7..c72b82be1 100644
--- a/sdk/python/arvados/_normalize_stream.py
+++ b/sdk/python/arvados/_normalize_stream.py
@@ -8,9 +8,7 @@ from . import config
import re
def escape(path):
- path = re.sub('\\\\', lambda m: '\\134', path)
- path = re.sub('[:\000-\040]', lambda m: "\\%03o" % ord(m.group(0)), path)
- return path
+ return re.sub(r'[\\:\000-\040]', lambda m: "\\%03o" % ord(m.group(0)), path)
def normalize_stream(stream_name, stream):
"""Take manifest stream and return a list of tokens in normalized format.
diff --git a/sdk/python/arvados/arvfile.py b/sdk/python/arvados/arvfile.py
index a1b2241b3..4b95835aa 100644
--- a/sdk/python/arvados/arvfile.py
+++ b/sdk/python/arvados/arvfile.py
@@ -100,7 +100,7 @@ class ArvadosFileReaderBase(_FileLikeObjectBase):
yield data
def decompressed_name(self):
- return re.sub('\.(bz2|gz)$', '', self.name)
+ return re.sub(r'\.(bz2|gz)$', '', self.name)
@_FileLikeObjectBase._before_close
def seek(self, pos, whence=os.SEEK_SET):
diff --git a/sdk/python/arvados/collection.py b/sdk/python/arvados/collection.py
index bd1775db2..a816d2d0e 100644
--- a/sdk/python/arvados/collection.py
+++ b/sdk/python/arvados/collection.py
@@ -1770,7 +1770,7 @@ class Collection(RichCollectionBase):
_segment_re = re.compile(r'(\d+):(\d+):(\S+)')
def _unescape_manifest_path(self, path):
- return re.sub('\\\\([0-3][0-7][0-7])', lambda m: chr(int(m.group(1), 8)), path)
+ return re.sub(r'\\([0-3][0-7][0-7])', lambda m: chr(int(m.group(1), 8)), path)
@synchronized
def _import_manifest(self, manifest_text):
diff --git a/sdk/python/arvados/config.py b/sdk/python/arvados/config.py
index e17eb1ff5..6f3bd0279 100644
--- a/sdk/python/arvados/config.py
+++ b/sdk/python/arvados/config.py
@@ -38,9 +38,7 @@ def load(config_file):
cfg = {}
with open(config_file, "r") as f:
for config_line in f:
- if re.match('^\s*$', config_line):
- continue
- if re.match('^\s*#', config_line):
+ if re.match(r'^\s*(?:#|$)', config_line):
continue
var, val = config_line.rstrip().split('=', 2)
cfg[var] = val
diff --git a/sdk/python/arvados/util.py b/sdk/python/arvados/util.py
index a4b7e64a0..5bce8d3f8 100644
--- a/sdk/python/arvados/util.py
+++ b/sdk/python/arvados/util.py
@@ -116,11 +116,12 @@ def tarball_extract(tarball, path):
os.unlink(os.path.join(path, '.locator'))
for f in CollectionReader(tarball).all_files():
- if re.search('\.(tbz|tar.bz2)$', f.name()):
+ f_name = f.name()
+ if f_name.endswith(('.tbz', '.tar.bz2')):
p = tar_extractor(path, 'j')
- elif re.search('\.(tgz|tar.gz)$', f.name()):
+ elif f_name.endswith(('.tgz', '.tar.gz')):
p = tar_extractor(path, 'z')
- elif re.search('\.tar$', f.name()):
+ elif f_name.endswith('.tar'):
p = tar_extractor(path, '')
else:
raise arvados.errors.AssertionError(
@@ -177,7 +178,7 @@ def zipball_extract(zipball, path):
os.unlink(os.path.join(path, '.locator'))
for f in CollectionReader(zipball).all_files():
- if not re.search('\.zip$', f.name()):
+ if not f.name().endswith('.zip'):
raise arvados.errors.NotImplementedError(
"zipball_extract cannot handle filename %s" % f.name())
zip_filename = os.path.join(path, os.path.basename(f.name()))
diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index b14ad141e..eb2784c71 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -338,7 +338,7 @@ def run(leave_running_atexit=False):
resdir = subprocess.check_output(['bundle', 'exec', 'passenger-config', 'about', 'resourcesdir']).decode().rstrip()
with open(resdir + '/templates/standalone/config.erb') as f:
template = f.read()
- newtemplate = re.sub('http {', 'http {\n passenger_stat_throttle_rate 0;', template)
+ newtemplate = re.sub(r'http \{', 'http {\n passenger_stat_throttle_rate 0;', template)
if newtemplate == template:
raise "template edit failed"
with open('tmp/passenger-nginx.conf.erb', 'w') as f:
diff --git a/sdk/python/tests/test_arv_get.py b/sdk/python/tests/test_arv_get.py
index 73ef2475b..d12739f6f 100644
--- a/sdk/python/tests/test_arv_get.py
+++ b/sdk/python/tests/test_arv_get.py
@@ -88,7 +88,7 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers,
def test_get_block(self):
# Get raw data using a block locator
- blk = re.search(' (acbd18\S+\+A\S+) ', self.col_manifest).group(1)
+ blk = re.search(r' (acbd18\S+\+A\S+) ', self.col_manifest).group(1)
r = self.run_get([blk, '-'])
self.assertEqual(0, r)
self.assertEqual(b'foo', self.stdout.getvalue())
diff --git a/sdk/python/tests/test_collections.py b/sdk/python/tests/test_collections.py
index 56c2352ad..9e753506b 100644
--- a/sdk/python/tests/test_collections.py
+++ b/sdk/python/tests/test_collections.py
@@ -593,7 +593,7 @@ class CollectionReaderTestCase(unittest.TestCase, CollectionTestMixin):
# Ensure stripped_manifest() doesn't mangle our manifest in
# any way other than stripping hints.
self.assertEqual(
- re.sub('\+[^\d\s\+]+', '', nonnormal),
+ re.sub(r'\+[^\d\s\+]+', '', nonnormal),
reader.stripped_manifest())
# Ensure stripped_manifest() didn't mutate our reader.
self.assertEqual(nonnormal, reader.manifest_text())
diff --git a/services/fuse/arvados_fuse/fusedir.py b/services/fuse/arvados_fuse/fusedir.py
index 7de95a0cb..8faf01cb6 100644
--- a/services/fuse/arvados_fuse/fusedir.py
+++ b/services/fuse/arvados_fuse/fusedir.py
@@ -26,7 +26,7 @@ _logger = logging.getLogger('arvados.arvados_fuse')
# Match any character which FUSE or Linux cannot accommodate as part
# of a filename. (If present in a collection filename, they will
# appear as underscores in the fuse mount.)
-_disallowed_filename_characters = re.compile('[\x00/]')
+_disallowed_filename_characters = re.compile(r'[\x00/]')
class Directory(FreshBase):
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list