Skip to content

Commit

Permalink
Fix: Compatibility issues for Python 2 runs (#140)
Browse files Browse the repository at this point in the history
* Fix: Encode the output file properly for Python 2 runs

Avoid compatibility errors with the `open(...)` function in Python 2 for
setting the file's encoding.

Sometimes in case an old architecture and `cms-sw` release is being
used, a Python 2 interpreter is available for executing the
`run_the_matrix_pdmv.py` module and there are compatibility issues with
the encoding argument.

* Fix: Compatibility issue with string formatting

Remove the usage of f-strings.
  • Loading branch information
ggonzr authored Jan 20, 2025
1 parent 5ea8487 commit a0a325b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/utils/dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def list_certification_files(cert_type):
url = "%s/%s/" % (dqm_cert_url, cert_type)
page_content = requests.get(url=url, timeout=30)
if page_content.status_code != 200:
error_msg = f"Unable to retrieve the content related to {cert_type}"
error_msg = "Unable to retrieve the content related to %s" % cert_type
raise HTTPError(error_msg, response=page_content)

# Parse the HTML and retrieve the file names
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_certification_file(path):
url = "%s/%s" % (dqm_cert_url, path)
file = requests.get(url=url, timeout=30)
if file.status_code != 200:
error_msg = f"Unable to retrieve the content related to {path}"
error_msg = "Unable to retrieve the content related to %s" % path
raise HTTPError(error_msg, response=file)

return file.json()
Expand Down
3 changes: 2 additions & 1 deletion core/utils/run_the_matrix_pdmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import print_function

import argparse
import codecs
import importlib
import inspect
import json
Expand Down Expand Up @@ -312,7 +313,7 @@ def main():
print('All workflows:')
print(json.dumps(workflows, indent=2, sort_keys=True))
if opt.output_file:
with open(opt.output_file, 'w', encoding='utf-8') as workflows_file:
with codecs.open(opt.output_file, 'w', encoding='utf-8') as workflows_file:
json.dump(workflows, workflows_file)


Expand Down

0 comments on commit a0a325b

Please sign in to comment.