Skip to content

Commit 5836843

Browse files
Merge pull request #2721 from boegel/no_more_basestring
consistently use 'string_type' from easybuild.tools.py2vs3 rather than 'basestring'
2 parents 4163371 + 6f16ffd commit 5836843

29 files changed

+111
-86
lines changed

easybuild/framework/easyblock.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
from easybuild.tools.modules import invalidate_module_caches_for, get_software_root, get_software_root_env_var_name
8888
from easybuild.tools.modules import get_software_version_env_var_name
8989
from easybuild.tools.package.utilities import package
90+
from easybuild.tools.py2vs3 import string_type
9091
from easybuild.tools.repository.repository import init_repository
9192
from easybuild.tools.toolchain import DUMMY_TOOLCHAIN_NAME
9293
from easybuild.tools.systemtools import det_parallelism, use_group
@@ -344,7 +345,7 @@ def fetch_sources(self, sources=None, checksums=None):
344345
for index, source in enumerate(sources):
345346
extract_cmd, download_filename, source_urls, git_config = None, None, None, None
346347

347-
if isinstance(source, basestring):
348+
if isinstance(source, string_type):
348349
filename = source
349350

350351
elif isinstance(source, dict):
@@ -409,7 +410,7 @@ def fetch_patches(self, patch_specs=None, extension=False, checksums=None):
409410
# no 'isinstance(..., int)', since that would make True/False also acceptable
410411
if type(patch_spec[1]) == int:
411412
level = patch_spec[1]
412-
elif isinstance(patch_spec[1], basestring):
413+
elif isinstance(patch_spec[1], string_type):
413414
# non-patch files are assumed to be files to copy
414415
if not patch_spec[0].endswith('.patch'):
415416
copy_file = True
@@ -559,7 +560,7 @@ def fetch_extension_sources(self, skip_checksums=False):
559560
else:
560561
raise EasyBuildError("Source for extension %s not found.", ext)
561562

562-
elif isinstance(ext, basestring):
563+
elif isinstance(ext, string_type):
563564
exts_sources.append({'name': ext})
564565

565566
else:
@@ -696,7 +697,7 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
696697

697698
url_filename = download_filename or filename
698699

699-
if isinstance(url, basestring):
700+
if isinstance(url, string_type):
700701
if url[-1] in ['=', '/']:
701702
fullurl = "%s%s" % (url, url_filename)
702703
else:
@@ -1117,7 +1118,7 @@ def make_module_extra(self, altroot=None, altversion=None):
11171118
lines.append(self.module_generator.set_environment(key, value))
11181119

11191120
for (key, value) in self.cfg['modextrapaths'].items():
1120-
if isinstance(value, basestring):
1121+
if isinstance(value, string_type):
11211122
value = [value]
11221123
elif not isinstance(value, (tuple, list)):
11231124
raise EasyBuildError("modextrapaths dict value %s (type: %s) is not a list or tuple",
@@ -1247,7 +1248,7 @@ def make_module_req(self):
12471248
if self.dry_run:
12481249
self.dry_run_msg(" $%s: %s" % (key, ', '.join(requirements[key])))
12491250
reqs = requirements[key]
1250-
if isinstance(reqs, basestring):
1251+
if isinstance(reqs, string_type):
12511252
self.log.warning("Hoisting string value %s into a list before iterating over it", reqs)
12521253
reqs = [reqs]
12531254

@@ -1372,7 +1373,7 @@ def skip_extensions(self):
13721373

13731374
if not exts_filter or len(exts_filter) == 0:
13741375
raise EasyBuildError("Skipping of extensions, but no exts_filter set in easyconfig")
1375-
elif isinstance(exts_filter, basestring) or len(exts_filter) != 2:
1376+
elif isinstance(exts_filter, string_type) or len(exts_filter) != 2:
13761377
raise EasyBuildError('exts_filter should be a list or tuple of ("command","input")')
13771378
cmdtmpl = exts_filter[0]
13781379
cmdinputtmpl = exts_filter[1]
@@ -1743,7 +1744,7 @@ def check_checksums(self):
17431744
for ext in self.cfg['exts_list']:
17441745
# just skip extensions for which only a name is specified
17451746
# those are just there to check for things that are in the "standard library"
1746-
if not isinstance(ext, basestring):
1747+
if not isinstance(ext, string_type):
17471748
ext_name = ext[0]
17481749
# take into account that extension may be a 2-tuple with just name/version
17491750
ext_opts = ext[2] if len(ext) == 3 else {}
@@ -1928,7 +1929,7 @@ def extensions_step(self, fetch=False):
19281929
if hasattr(exts_defaultclass, '__iter__'):
19291930
self.log.nosupport("Module path for default class is explicitly defined", '2.0')
19301931

1931-
elif isinstance(exts_defaultclass, basestring):
1932+
elif isinstance(exts_defaultclass, string_type):
19321933
# proper way: derive module path from specified class name
19331934
default_class = exts_defaultclass
19341935
default_class_modpath = get_module_path(default_class, generic=True)
@@ -2054,7 +2055,7 @@ def post_install_step(self):
20542055
if not isinstance(self.cfg['postinstallcmds'], (list, tuple)):
20552056
raise EasyBuildError("Invalid value for 'postinstallcmds', should be list or tuple of strings.")
20562057
for cmd in self.cfg['postinstallcmds']:
2057-
if not isinstance(cmd, basestring):
2058+
if not isinstance(cmd, string_type):
20582059
raise EasyBuildError("Invalid element in 'postinstallcmds', not a string: %s", cmd)
20592060
run_cmd(cmd, simple=True, log_ok=True, log_all=True)
20602061

@@ -2186,7 +2187,7 @@ def _sanity_check_step_common(self, custom_paths, custom_commands):
21862187
for i, command in enumerate(commands):
21872188
# set command to default. This allows for config files with
21882189
# non-tuple commands
2189-
if isinstance(command, basestring):
2190+
if isinstance(command, string_type):
21902191
self.log.debug("Using %s as sanity check command" % command)
21912192
commands[i] = command
21922193
else:
@@ -2287,7 +2288,7 @@ def xs2str(xs):
22872288
for key, (typ, check_fn) in path_keys_and_check.items():
22882289

22892290
for xs in paths[key]:
2290-
if isinstance(xs, basestring):
2291+
if isinstance(xs, string_type):
22912292
xs = (xs,)
22922293
elif not isinstance(xs, tuple):
22932294
raise EasyBuildError("Unsupported type %s encountered in '%s', not a string or tuple",

easybuild/framework/easyconfig/easyconfig.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from easybuild.tools.module_naming_scheme.utilities import avail_module_naming_schemes, det_full_ec_version
6767
from easybuild.tools.module_naming_scheme.utilities import det_hidden_modname, is_valid_module_name
6868
from easybuild.tools.modules import modules_tool
69-
from easybuild.tools.py2vs3 import OrderedDict
69+
from easybuild.tools.py2vs3 import OrderedDict, string_type
7070
from easybuild.tools.systemtools import check_os_dependency
7171
from easybuild.tools.toolchain import DUMMY_TOOLCHAIN_NAME, DUMMY_TOOLCHAIN_VERSION
7272
from easybuild.tools.toolchain.toolchain import TOOLCHAIN_CAPABILITIES, TOOLCHAIN_CAPABILITY_CUDA
@@ -462,7 +462,7 @@ def update(self, key, value, allow_duplicate=True):
462462
Update a string configuration value with a value (i.e. append to it).
463463
"""
464464
prev_value = self[key]
465-
if isinstance(prev_value, basestring):
465+
if isinstance(prev_value, string_type):
466466
if allow_duplicate or value not in prev_value:
467467
self[key] = '%s %s ' % (prev_value, value)
468468
elif isinstance(prev_value, list):
@@ -563,7 +563,7 @@ def check_deprecated(self, path):
563563

564564
deprecated = self['deprecated']
565565
if deprecated:
566-
if isinstance(deprecated, basestring):
566+
if isinstance(deprecated, string_type):
567567
depr_msgs.append("easyconfig file '%s' is marked as deprecated:\n%s\n" % (path, deprecated))
568568
else:
569569
raise EasyBuildError("Wrong type for value of 'deprecated' easyconfig parameter: %s", type(deprecated))
@@ -631,7 +631,7 @@ def validate_os_deps(self):
631631
not_found = []
632632
for dep in self['osdependencies']:
633633
# make sure we have a tuple
634-
if isinstance(dep, basestring):
634+
if isinstance(dep, string_type):
635635
dep = (dep,)
636636
elif not isinstance(dep, tuple):
637637
raise EasyBuildError("Non-tuple value type for OS dependency specification: %s (type %s)",
@@ -1389,7 +1389,7 @@ def resolve_template(value, tmpl_dict):
13891389
- value: some python object (supported are string, tuple/list, dict or some mix thereof)
13901390
- tmpl_dict: template dictionary
13911391
"""
1392-
if isinstance(value, basestring):
1392+
if isinstance(value, string_type):
13931393
# simple escaping, making all '%foo', '%%foo', '%%%foo' post-templates values available,
13941394
# but ignore a string like '%(name)s'
13951395
# behaviour of strings like '%(name)s',

easybuild/framework/easyconfig/format/format.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from easybuild.tools.build_log import EasyBuildError
4040
from easybuild.tools.configobj import Section
4141
from easybuild.tools.utilities import get_subclasses
42+
from easybuild.tools.py2vs3 import string_type
4243

4344

4445
# format is mandatory major.minor
@@ -312,7 +313,7 @@ def parse_sections(self, toparse, current):
312313
value_type = self.VERSION_OPERATOR_VALUE_TYPES[key]
313314
# list of supported toolchains/versions
314315
# first one is default
315-
if isinstance(value, basestring):
316+
if isinstance(value, string_type):
316317
# so the split should be unnecessary
317318
# (if it's not a list already, it's just one value)
318319
# TODO this is annoying. check if we can force this in configobj

easybuild/framework/easyconfig/format/one.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from easybuild.framework.easyconfig.templates import to_template_str
4545
from easybuild.tools.build_log import EasyBuildError, print_msg
4646
from easybuild.tools.filetools import read_file, write_file
47+
from easybuild.tools.py2vs3 import string_type
4748
from easybuild.tools.utilities import INDENT_4SPACES, quote_py_str
4849

4950

@@ -180,7 +181,7 @@ def _reformat_line(self, param_name, param_val, outer=False, addlen=0):
180181

181182
else:
182183
# dependencies are already dumped as strings, so they do not need to be quoted again
183-
if isinstance(param_val, basestring) and param_name not in DEPENDENCY_PARAMETERS:
184+
if isinstance(param_val, string_type) and param_name not in DEPENDENCY_PARAMETERS:
184185
res = quote_py_str(param_val)
185186

186187
return res
@@ -336,7 +337,7 @@ def extract_comments(self, rawtxt):
336337
# determine parameter value where the item value on this line is a part of
337338
for key, val in parsed_ec.items():
338339
item_val = re.sub(r',$', r'', rawline.rsplit('#', 1)[0].strip())
339-
if not isinstance(val, basestring) and item_val in str(val):
340+
if not isinstance(val, string_type) and item_val in str(val):
340341
comment_key, comment_val = key, item_val
341342
break
342343

easybuild/framework/easyconfig/format/version.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
from easybuild.base import fancylogger
3737
from easybuild.tools.build_log import EasyBuildError
38+
from easybuild.tools.py2vs3 import string_type
3839
from easybuild.tools.toolchain.utilities import search_toolchain
3940

4041

@@ -139,10 +140,10 @@ def test(self, test_version):
139140
if not self:
140141
raise EasyBuildError('Not a valid %s. Not initialised yet?', self.__class__.__name__)
141142

142-
if isinstance(test_version, basestring):
143+
if isinstance(test_version, string_type):
143144
test_version = self._convert(test_version)
144145
elif not isinstance(test_version, EasyVersion):
145-
raise EasyBuildError("test: argument should be a basestring or EasyVersion (type %s)", type(test_version))
146+
raise EasyBuildError("test: argument should be a string or EasyVersion (type %s)", type(test_version))
146147

147148
res = self.operator(test_version, self.version)
148149
self.log.debug("result of testing expression '%s %s %s': %s",
@@ -614,15 +615,15 @@ def add(self, versop_new, data=None, update=None):
614615
After add, versop_new is in the OrderedVersionOperators. If the same versop_new was already in it,
615616
it will update the data (if not None) (and not raise an error)
616617
617-
:param versop_new: VersionOperator instance (or will be converted into one if type basestring)
618+
:param versop_new: VersionOperator instance (or will be converted into one if type string)
618619
:param data: additional data for supplied version operator to be stored
619620
:param update: if versop_new already exist and has data set, try to update the existing data with the new data;
620621
instead of overriding the existing data with the new data (method used for updating is .update)
621622
"""
622-
if isinstance(versop_new, basestring):
623+
if isinstance(versop_new, string_type):
623624
versop_new = VersionOperator(versop_new)
624625
elif not isinstance(versop_new, VersionOperator):
625-
raise EasyBuildError("add: argument must be a VersionOperator instance or basestring: %s; type %s",
626+
raise EasyBuildError("add: argument must be a VersionOperator instance or string: %s; type %s",
626627
versop_new, type(versop_new))
627628

628629
if versop_new in self.versops:

easybuild/framework/easyconfig/format/yeb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from easybuild.base import fancylogger
3535
from easybuild.framework.easyconfig.format.format import EasyConfigFormat
3636
from easybuild.framework.easyconfig.format.pyheaderconfigobj import build_easyconfig_constants_dict
37+
from easybuild.tools.py2vs3 import string_type
3738
from easybuild.tools.utilities import INDENT_4SPACES, only_if_module_is_available, quote_str
3839

3940

@@ -147,7 +148,7 @@ def quote_yaml_special_chars(val):
147148
Single quotes inside the string are escaped by doubling them.
148149
(see: http://symfony.com/doc/current/components/yaml/yaml_format.html#strings)
149150
"""
150-
if isinstance(val, basestring):
151+
if isinstance(val, string_type):
151152
if "'" in val or YAML_SPECIAL_CHARS.intersection(val):
152153
val = "'%s'" % val.replace("'", "''")
153154

easybuild/framework/easyconfig/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from easybuild.framework.easyconfig.types import PARAMETER_TYPES, check_type_of_param_value
4040
from easybuild.tools.build_log import EasyBuildError
4141
from easybuild.tools.filetools import read_file, write_file
42+
from easybuild.tools.py2vs3 import string_type
4243

4344

4445
# deprecated easyconfig parameters, and their replacements
@@ -160,8 +161,8 @@ def _read(self, filename=None):
160161
except IOError as err:
161162
raise EasyBuildError('Failed to obtain content with %s: %s', self.get_fn, err)
162163

163-
if not isinstance(self.rawcontent, basestring):
164-
msg = 'rawcontent is not basestring: type %s, content %s' % (type(self.rawcontent), self.rawcontent)
164+
if not isinstance(self.rawcontent, string_type):
165+
msg = 'rawcontent is not a string: type %s, content %s' % (type(self.rawcontent), self.rawcontent)
165166
raise EasyBuildError("Unexpected result for raw content: %s", msg)
166167

167168
def _det_format_version(self):

easybuild/framework/easyconfig/style.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from easybuild.base import fancylogger
3535
from easybuild.framework.easyconfig.easyconfig import EasyConfig
3636
from easybuild.tools.build_log import EasyBuildError, print_msg
37+
from easybuild.tools.py2vs3 import string_type
3738
from easybuild.tools.utilities import only_if_module_is_available
3839

3940
try:
@@ -158,7 +159,7 @@ def cmdline_easyconfigs_style_check(ecs):
158159
# if an EasyConfig instance is provided, just grab the corresponding file path
159160
if isinstance(ec, EasyConfig):
160161
path = ec.path
161-
elif isinstance(ec, basestring):
162+
elif isinstance(ec, string_type):
162163
path = ec
163164
else:
164165
raise EasyBuildError("Value of unknown type encountered in cmdline_easyconfigs_style_check: %s (type: %s)",

easybuild/framework/easyconfig/templates.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from easybuild.base import fancylogger
3636
from easybuild.tools.build_log import EasyBuildError
37+
from easybuild.tools.py2vs3 import string_type
3738
from easybuild.tools.systemtools import get_shared_lib_ext
3839

3940

@@ -207,7 +208,7 @@ def template_constant_dict(config, ignore=None, skip_lower=True):
207208
else:
208209
raise EasyBuildError("Unexpected type for dependency: %s", dep)
209210

210-
if isinstance(dep_name, basestring) and dep_name.lower() == name.lower():
211+
if isinstance(dep_name, string_type) and dep_name.lower() == name.lower():
211212
template_values['%sver' % pref] = dep_version
212213
template_values['%sshortver' % pref] = '.'.join(dep_version.split('.')[:2])
213214
break

easybuild/tools/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from easybuild.base import fancylogger
4848
from easybuild.base.frozendict import FrozenDictKnownKeys
4949
from easybuild.tools.build_log import EasyBuildError
50+
from easybuild.tools.py2vs3 import string_type
5051

5152

5253
_log = fancylogger.getLogger('config', fname=False)
@@ -395,7 +396,7 @@ def init(options, config_options_dict):
395396

396397
# make sure source path is a list
397398
sourcepath = tmpdict['sourcepath']
398-
if isinstance(sourcepath, basestring):
399+
if isinstance(sourcepath, string_type):
399400
tmpdict['sourcepath'] = sourcepath.split(':')
400401
_log.debug("Converted source path ('%s') to a list of paths: %s" % (sourcepath, tmpdict['sourcepath']))
401402
elif not isinstance(sourcepath, (tuple, list)):

0 commit comments

Comments
 (0)