Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linter errors #32

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[MASTER]
[MAIN]

# Specify a configuration file.
#rcfile=
Expand All @@ -7,9 +7,6 @@
# pygtk.require().
#init-hook=

# Profiled execution.
profile=no

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
Expand All @@ -19,7 +16,7 @@ persistent=yes

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=pylint.extensions.bad_builtin


[MESSAGES CONTROL]
Expand Down Expand Up @@ -49,14 +46,6 @@ extension-pkg-allow-list=pycurl
# (visual studio) and html
output-format=text

# Include message's id in output
include-ids=no

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=yes

Expand All @@ -67,11 +56,6 @@ reports=yes
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no


[TYPECHECK]

# Tells whether missing members accessed in mixin class should be ignored. A
Expand All @@ -82,24 +66,18 @@ ignore-mixin-members=yes
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject,Curl

# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
zope=no

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,acl_users,aq_parent


[BASIC]

# Required attributes for module, separated by a comma
required-attributes=
[pylint.DEPRECATED_BUILTINS]

# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input

[BASIC]

# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

Expand Down Expand Up @@ -186,10 +164,6 @@ notes=FIXME,XXX,TODO

[CLASSES]

# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by

# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp

Expand Down Expand Up @@ -231,7 +205,7 @@ max-locals=20
max-returns=6

# Maximum number of branch for function / method body
max-branchs=12
max-branches=12

# Maximum number of statements in function / method body
max-statements=50
Expand All @@ -253,4 +227,4 @@ max-public-methods=20

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
4 changes: 2 additions & 2 deletions GetPythonVersions.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_version_popen(path, note="", shorten=False, width=120, lcg_version="", a
output = process.communicate()[0]
output = output.decode('utf-8')
output = output.replace('+','')
version_info = list(map(int, output.split()[1].split('.')))
version_info = [int(x) for x in output.split()[1].split('.')]
versions = []
short_path = get_short_path(path)
pathlines = split_path_width(short_path if shorten else path, width=width)
Expand Down Expand Up @@ -269,7 +269,7 @@ def dict_to_formatted_versions(dictionary, width):
"""
versions = []
sorted_list = sorted(dictionary.items(),
key=lambda item: tuple(list(map(int, item[0].split('.')[0:3])) +
key=lambda item: tuple([int(x) for x in item[0].split('.')[0:3]] +
[item[0].split('.')[3] if len(item[0].split('.')) > 3 else ""]))
for python_version, version in sorted_list:
versions += dict_entry_to_formatted_version(python_version, version, width)
Expand Down
2 changes: 1 addition & 1 deletion GetSiteInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def get_site_info(site_alias = "",
if shell is not None and isinstance(shell, list):
site.print_shell_str(shell, env)
else:
print(site.__str__())
print(str(site))

return site

Expand Down
1 change: 1 addition & 0 deletions containerize/containerize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ done
dependency_check() {
subuid=$(< /etc/subuid grep "^$(id -u):")
subgid=$(< /etc/subgid grep "^$(id -u):")
# shellcheck disable=SC2319
if ! command -v buildah &> /dev/null; then
EXIT=$?
echo "Buildah could not be found!"
Expand Down
14 changes: 9 additions & 5 deletions copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(self, *, action, recursive = False, dry_run = False, **kwargs):
self.end_site_prefix = self.get_site_prefix(self.end_site) if self.end_site is not None else ""
self.build_command()

# pylint: disable=no-self-use
def get_site_prefix(self, site):
"""Return the formatted site path, including the protcol to use, the endpoint,
and the initial portion of the path, through the username.
Expand Down Expand Up @@ -261,6 +260,7 @@ def make_directory(end_site, path, protocol, debug = False):
return os.path.exists(path)
else:
ls_command = None
mkdir_command = None
if protocol == "gfal":
ls_command = GfalCommand(action = "ls",
verbose = True,
Expand All @@ -278,7 +278,8 @@ def make_directory(end_site, path, protocol, debug = False):
subaction = "mkdir",
end_site = end_site,
override_path = path)

else:
raise ValueError(f"Unknown protocol {protocol}")
returncode = 0
output = ""
with subprocess.Popen(ls_command.get_full_command(),
Expand Down Expand Up @@ -333,6 +334,7 @@ def get_list_of_files(protocol, start_site, sample, path, debug = False):
elif not remote_is_dir(start_site, path):
files_unfiltered = [path]
else:
ls_command = None
if protocol == "gfal":
ls_command = GfalCommand(action = "ls",
start_site = start_site,
Expand All @@ -342,6 +344,8 @@ def get_list_of_files(protocol, start_site, sample, path, debug = False):
subaction = "ls",
start_site = start_site,
override_path = path)
else:
raise ValueError(f"Unknown protocol {protocol}")
cmd = ls_command.get_full_command()
if debug:
print("get_list_of_files:")
Expand Down Expand Up @@ -439,7 +443,7 @@ def copytree(start_site, src, end_site, dst, current_depth, symlinks = False, ig
if not arguments.dry_run:
made_dir = make_directory(end_site, dst, arguments.protocol, arguments.debug)
if not made_dir:
raise Exception("ERROR::copytree::Unable to make the destination directory.")
raise RuntimeError("ERROR::copytree::Unable to make the destination directory.")

files = get_list_of_files(arguments.protocol, start_site, arguments.sample, src, arguments.debug)

Expand Down Expand Up @@ -536,7 +540,7 @@ def built_in_recursion(start_site, end_site, arguments):
if not arguments.dry_run:
made_dir = make_directory(end_site, end_site.path, arguments.protocol, arguments.debug)
if not made_dir:
raise Exception("ERROR::built_in_recursion::Unable to make the destination directory.")
raise RuntimeError("ERROR::built_in_recursion::Unable to make the destination directory.")

# Run the command and check the output codes
with subprocess.Popen(command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) as process:
Expand All @@ -546,7 +550,7 @@ def built_in_recursion(start_site, end_site, arguments):
if process.returncode == 0:
return True
else:
raise Exception("ERROR::built_in_recursion() Something went wrong with the copy command.")
raise RuntimeError("ERROR::built_in_recursion() Something went wrong with the copy command.")

def main(arguments = argparse.Namespace()):
"""The main function coordinating the overal logic of which protocols to use, how to get the site/server
Expand Down
1 change: 0 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import RecursiveFileList
import toolgenie
# pylint: enable=wrong-import-position
# pylint: disable=no-self-use

class Capturing(list):
"""A context manager which captures stdout and returns it as a list of strings, one for each line.
Expand Down
3 changes: 1 addition & 2 deletions test/test_copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import shutil
import subprocess

# pylint: disable=no-self-use
# pylint: disable=consider-using-with
# pylint: disable=invalid-name
# pylint: disable=too-many-public-methods
Expand Down Expand Up @@ -152,7 +151,7 @@ def check_popen(self, process, files_that_must_exist, expected_file_counts = Non
self.assertTrue(actual_count == expected_count, (f"The file count in folder {path} ({actual_count:d}) "
f"doesn't match the expected count of {expected_count:d}"))
else:
raise Exception("Remote file checking not yet implemented")
raise RuntimeError("Remote file checking not yet implemented")

def test_local_local_file(self):
"""Copy a single file from a local source to a local destination."""
Expand Down
18 changes: 9 additions & 9 deletions toolgenie.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def get_selected_architectures(relmap, architecture = None, quiet = False):
else:
user_response = architecture
if user_response.isdigit() and (int(user_response) > len(architecture_options) or int(user_response) < 0):
raise Exception("The response was out of bounds. You must enter a listed value.\n")
raise ValueError("The response was out of bounds. You must enter a listed value.\n")
if not user_response.isdigit() and 'r:' not in user_response and user_response not in architecture_options:
raise Exception("The response was not in the list of acceptable scram architectures.\n")
raise ValueError("The response was not in the list of acceptable scram architectures.\n")
selected_architectures = []
if 'r:' in user_response:
user_response_altered = user_response[2:]
Expand All @@ -137,7 +137,7 @@ def get_selected_architectures(relmap, architecture = None, quiet = False):
selected_architectures = [architecture_options[int(user_response)-1]
if user_response.isdigit() else user_response]
if len(selected_architectures) == 0:
raise Exception(f"Uh oh! No architectures were found based on your input ({user_response}).")
raise ValueError(f"Uh oh! No architectures were found based on your input ({user_response}).")

return (selected_architectures, user_response)

Expand All @@ -161,17 +161,17 @@ def get_selected_releases(selected_releases, cmssw = None, quiet = False):
else:
user_response = cmssw
if user_response.isdigit() and (int(user_response) > len(label_options) or int(user_response) < 0):
raise Exception("The response was out of bounds. You must enter a listed value.\n")
raise ValueError("The response was out of bounds. You must enter a listed value.\n")
if not user_response.isdigit() and 'r:' not in user_response and user_response not in label_options:
raise Exception("The response was not in the list of acceptable CMSSW releases.\n")
raise ValueError("The response was not in the list of acceptable CMSSW releases.\n")
selected_labels = []
if 'r:' in user_response:
user_response_altered = user_response[2:]
selected_labels = [lo for lo in label_options if re.search(user_response_altered, lo)]
else:
selected_labels = [label_options[int(user_response)-1] if user_response.isdigit() else user_response]
if len(selected_labels) == 0:
raise Exception(f"Uh oh! No releases were found based on your input ({user_response}).")
raise ValueError(f"Uh oh! No releases were found based on your input ({user_response}).")
selected_releases = filter_on_label(selected_releases, selected_labels)

return selected_releases
Expand All @@ -193,9 +193,9 @@ def get_selected_toolboxes(selected_releases_tools, tool = None, quiet = False):
selected_toolboxes = {}
for user_response in user_responses:
if user_response.isdigit() and (int(user_response) > len(tool_options) or int(user_response) < 0):
raise Exception("The response was out of bounds. You must enter a listed value.\n")
raise ValueError("The response was out of bounds. You must enter a listed value.\n")
if not user_response.isdigit() and user_response not in tool_options:
raise Exception("The response was not in the list of acceptable tools.\n")
raise ValueError("The response was not in the list of acceptable tools.\n")
selected_tool = tool_options[int(user_response)-1] if user_response.isdigit() else user_response
if not selected_tool in selected_toolboxes:
selected_toolboxes[selected_tool] = filter_on_tool(selected_releases_tools, selected_tool)
Expand Down Expand Up @@ -292,7 +292,7 @@ def parse_release_map(source=MapSource.GITHUB):
with open("/cvmfs/cms.cern.ch/releases.map", mode='r', encoding='utf-8') as release_map:
relmap = parse_map_lines(release_map)
else:
raise Exception("Unknown source for the architecture/release map.\n")
raise ValueError(f"Unknown source {source} for the architecture/release map.\n")

return relmap

Expand Down
Loading