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

Remove pin on Pylint to support Python 3.11 #260

Merged
merged 3 commits into from
Apr 8, 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
22 changes: 15 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,31 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
root-version: ["6.24", "6.26", "6.28"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
root-version: ["6.24", "6.26", "6.28", "6.30"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
exclude:
- root-version: "6.24"
python-version: "3.10"
- root-version: "6.24"
python-version: "3.11"
- root-version: "6.26"
python-version: "3.6"
- root-version: "6.26"
python-version: "3.7"
- root-version: "6.26"
python-version: "3.11"
- root-version: "6.28"
python-version: "3.6"
- root-version: "6.28"
python-version: "3.7"
- root-version: "6.30"
python-version: "3.6"
- root-version: "6.30"
python-version: "3.7"
include:
- os: macos-latest
root-version: "6.28"
python-version: "3.10"
root-version: "6.30"
python-version: "3.11"

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -70,7 +78,7 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade \
'pylint==2.9.6' \
'pylint' \
pytest_pylint \
configparser \
astroid \
Expand Down Expand Up @@ -109,7 +117,7 @@ jobs:
path: examples/*.html

- name: Run pylint
if: ${{ always() }}
if: ${{ always() && !startsWith(matrix.python-version, '3.6') && !startsWith(matrix.python-version, '3.7') }}
run: |
python -m pylint hepdata_lib/*.py
python -m pylint tests/*.py --rcfile=tests/pylintrc
python -m pylint tests/*.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Library for getting your data into HEPData

- Documentation: https://hepdata-lib.readthedocs.io

This code works with Python 3.6, 3.7, 3.8, 3.9 or 3.10.
This code works with Python 3.6, 3.7, 3.8, 3.9, 3.10, 3.11 or 3.12.

## Installation

Expand Down
5 changes: 3 additions & 2 deletions docs/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ Analysing the code
::

pylint hepdata_lib/*.py
pylint tests/*.py --rcfile=tests/pylintrc
pylint tests/*.py

These commands are run by GitHub Actions, so you should first check locally that no issues are flagged.
These commands are run by GitHub Actions (for Python 3.8 or later),
so you should first check locally that no issues are flagged.


Making a release
Expand Down
20 changes: 10 additions & 10 deletions hepdata_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def make_dict(self):
elif self.uncertainties and self.zero_uncertainties_warning:
print(
"Warning: omitting 'errors' since all uncertainties " \
"are zero for bin {} of variable '{}'.".format(i+1, self.name)
f"are zero for bin {i+1} of variable '{self.name}'."
)
print(
"Note that bins with zero content should preferably " \
Expand Down Expand Up @@ -389,7 +389,7 @@ def write_images(self, outdir):

for image_file in self.image_files:
if not os.path.isfile(image_file):
raise RuntimeError("File %s does not exist!" % image_file)
raise RuntimeError(f"File {image_file} does not exist!")
if not os.path.exists(outdir):
os.makedirs(outdir)

Expand All @@ -408,16 +408,16 @@ def write_images(self, outdir):
if helpers.file_is_outdated(png_output_path, image_file):
helpers.convert_pdf_to_png(image_file, png_output_path)
else:
print("Full-size PNG file %s is newer than its source file. \
print(f"Full-size PNG file {png_output_path} is newer than its source file. \
Remove the thumbnail file or use create_files(remove_old=True)\
to force recreation." % png_output_path)
to force recreation.")

if helpers.file_is_outdated(thumbnail_output_path, png_output_path):
helpers.convert_png_to_thumbnail(png_output_path, thumbnail_output_path)
else:
print("Thumbnail PNG file %s is newer than its source file. \
print("Thumbnail PNG file {thumbnail_output_path} is newer than its source file. \
Remove the thumbnail file or use create_files(remove_old=True)\
to force recreation." % thumbnail_output_path)
to force recreation.")

image = {}
image["description"] = "Image file"
Expand Down Expand Up @@ -461,12 +461,12 @@ def write_yaml(self, outdir="."):
shortname = self.name.lower().replace(" ", "_")
outfile_path = os.path.join(
outdir, f'{shortname}.yaml')
with open(outfile_path, 'w') as outfile:
with open(outfile_path, 'w', encoding='utf-8') as outfile:
yaml.dump(table, outfile, default_flow_style=False)

# Add entry to central submission file
submission_path = os.path.join(outdir, 'submission.yaml')
with open(submission_path, 'a+') as submissionfile:
with open(submission_path, 'a+', encoding='utf-8') as submissionfile:
submission = {}
submission["name"] = self.name
submission["description"] = self.description
Expand Down Expand Up @@ -574,7 +574,7 @@ def read_abstract(self, filepath):
:param filepath: Path to text file containing abstract.
:type filepath: string.
"""
with open(filepath) as afile:
with open(filepath, encoding='utf-8') as afile:
raw = str(afile.read())
raw = raw.replace("\r\n", "")
raw = raw.replace("\n", "")
Expand Down Expand Up @@ -619,7 +619,7 @@ def create_files(self, outdir=".", validate=True, remove_old=False):
if self.record_ids:
submission["record_ids"] = self.record_ids

with open(os.path.join(outdir, 'submission.yaml'), 'w') as outfile:
with open(os.path.join(outdir, 'submission.yaml'), 'w', encoding='utf-8') as outfile:
yaml.dump(
submission,
outfile,
Expand Down
9 changes: 2 additions & 7 deletions hepdata_lib/c_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import io
from array import array
from future.utils import raise_from
from ROOT import TGraph, TGraphErrors
from ROOT import TGraph, TGraphErrors # pylint: disable=no-name-in-module
import hepdata_lib.root_utils as ru
from hepdata_lib.helpers import check_file_existence

Expand Down Expand Up @@ -34,7 +34,7 @@ def cfile(self, cfile):
"CFileReader: Input file is not a .C file (name does not end in .C)!"
)
if check_file_existence(cfile):
self._cfile = open(cfile) # pylint: disable=consider-using-with
self._cfile = open(cfile, encoding='utf-8') # pylint: disable=consider-using-with
else:
if isinstance(cfile, io.TextIOBase):
self._cfile = cfile
Expand Down Expand Up @@ -75,7 +75,6 @@ def get_graphs(self):

def create_tgraph_dict(self, graph_list, list_of_tgraphs):
"""Function to create pyroot TGraph dict"""
# pylint: disable=no-self-use

# Adding tgraphs into a dictionary
y_values = []
Expand All @@ -100,7 +99,6 @@ def create_tgraph_dict(self, graph_list, list_of_tgraphs):

def create_tgrapherrors_dict(self, graph_list):
"""Function to create pyroot TGraphErrors dict"""
# pylint: disable=no-self-use

# Adding TGraphErrors into a dictionary
y_values = []
Expand Down Expand Up @@ -135,7 +133,6 @@ def create_tgrapherrors_dict(self, graph_list):

def create_tgrapherrors(self, x_value, y_value, dx_value, dy_value):
"""Function to create pyroot TGraphErrors object"""
# pylint: disable=no-self-use

# Creating pyroot TGraphErrors object
x_values = array('i')
Expand Down Expand Up @@ -171,7 +168,6 @@ def create_tgrapherrors(self, x_value, y_value, dx_value, dy_value):

def create_tgraph(self, x_value, y_value):
"""Function to create pyroot TGraph object"""
# pylint: disable=no-self-use

# Creating pyroot TGraph object
x_values = array('i')
Expand All @@ -197,7 +193,6 @@ def create_tgraph(self, x_value, y_value):

def check_for_comments(self, line):
"""Check line for comment"""
# pylint: disable=no-self-use

_line = line
ignoreline = 0
Expand Down
26 changes: 12 additions & 14 deletions hepdata_lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def execute_command(command):
:type command: string
"""

subprocess_args = dict(
args=command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
universal_newlines=True
)
subprocess_args = {
"args": command,
"stdin": subprocess.PIPE,
"stdout": subprocess.PIPE,
"stderr": subprocess.PIPE,
"shell": True,
"universal_newlines": True
}
with subprocess.Popen(**subprocess_args) as proc:
exit_code = proc.wait()
if exit_code == 127:
Expand Down Expand Up @@ -294,10 +294,9 @@ def convert_pdf_to_png(source, target):
:param target: Output file in PNG format.
:type target: str
"""
assert os.path.exists(source), "Source file does not exist: %s" % source
assert os.path.exists(source), f"Source file does not exist: {source}"

command = "convert -flatten -density 300 -fuzz 1% -trim +repage {} {}".format(
source, target)
command = f"convert -flatten -density 300 -fuzz 1% -trim +repage {source} {target}"
command_ok = execute_command(command)
if not command_ok:
print("ImageMagick does not seem to be installed \
Expand All @@ -314,8 +313,7 @@ def convert_png_to_thumbnail(source, target):
:type target: str
"""

command = "convert -thumbnail 240x179 {} {}".format(
source, target)
command = f"convert -thumbnail 240x179 {source} {target}"
command_ok = execute_command(command)

if not command_ok:
Expand All @@ -334,7 +332,7 @@ def file_is_outdated(file_path, reference_file_path):
:type reference_file_path: str
"""
if not os.path.exists(reference_file_path):
raise RuntimeError("Reference file does not exist: %s" % reference_file_path)
raise RuntimeError(f"Reference file does not exist: {reference_file_path}")
if not os.path.exists(file_path):
return True

Expand Down
32 changes: 15 additions & 17 deletions hepdata_lib/root_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def tfile(self, tfile):
raise RuntimeError(
"RootFileReader: Input file is not a ROOT file (name does not end in .root)!"
)
if check_file_existence(tfile):
self._tfile = r.TFile(tfile)
elif isinstance(tfile, r.TFile):
check_file_existence(tfile)
self._tfile = r.TFile(tfile) # pylint: disable=no-member
elif isinstance(tfile, r.TFile): # pylint: disable=no-member
self._tfile = tfile
else:
raise ValueError(
"RootReader: Encountered unkonown type of variable passed as tfile argument: "
"RootReader: Encountered unknown type of variable passed as tfile argument: "
+ str(type(tfile)))

if not self._tfile:
Expand Down Expand Up @@ -157,7 +157,7 @@ def read_hist_2d(self, path_to_hist, **kwargs):
ylim = kwargs.pop('ylim', (None, None))
force_symmetric_errors = kwargs.pop('force_symmetric_errors', False)
if kwargs:
raise TypeError('Unexpected **kwargs: %r' % kwargs)
raise TypeError(f'Unexpected **kwargs: {repr(kwargs)}')
assert isinstance(xlim, (tuple, list))
assert isinstance(ylim, (tuple, list))
assert len(xlim) == 2
Expand Down Expand Up @@ -193,7 +193,7 @@ def read_hist_1d(self, path_to_hist, **kwargs):
xlim = kwargs.pop('xlim', (None, None))
force_symmetric_errors = kwargs.pop('force_symmetric_errors', False)
if kwargs:
raise TypeError('Unexpected **kwargs: %r' % kwargs)
raise TypeError(f'Unexpected **kwargs: {repr(kwargs)}')
assert isinstance(xlim, (tuple, list))
assert len(xlim) == 2
if xlim[0] and xlim[1]:
Expand All @@ -217,7 +217,7 @@ def read_tree(self, path_to_tree, branch_name):

"""
tree = self.tfile.Get(path_to_tree)
if not tree or not isinstance(tree, r.TTree):
if not tree or not isinstance(tree, r.TTree): # pylint: disable=no-member
raise RuntimeError(f"No TTree found for path '{path_to_tree}'.")
values = []
for event in tree:
Expand Down Expand Up @@ -297,7 +297,7 @@ def get_hist_2d_points(hist, **kwargs):
ylim = kwargs.pop('ylim', (None, None))
force_symmetric_errors = kwargs.pop('force_symmetric_errors', False)
if kwargs:
raise TypeError('Unexpected **kwargs: %r' % kwargs)
raise TypeError(f'Unexpected **kwargs: {repr(kwargs)}')
assert isinstance(xlim, (tuple, list))
assert isinstance(ylim, (tuple, list))
assert len(xlim) == 2
Expand All @@ -317,7 +317,7 @@ def get_hist_2d_points(hist, **kwargs):
ixmax = hist.GetXaxis().FindBin(xlim[1]) if xlim[1] is not None else hist.GetNbinsX() + 1
iymin = hist.GetYaxis().FindBin(ylim[0]) if ylim[0] is not None else 1
iymax = hist.GetYaxis().FindBin(ylim[1]) if ylim[1] is not None else hist.GetNbinsY() + 1
symmetric = (hist.GetBinErrorOption() == r.TH1.kNormal)
symmetric = hist.GetBinErrorOption() == r.TH1.kNormal # pylint: disable=no-member
if force_symmetric_errors:
symmetric = True
for x_bin in range(ixmin, ixmax):
Expand Down Expand Up @@ -377,7 +377,7 @@ def get_hist_1d_points(hist, **kwargs):
xlim = kwargs.pop('xlim', (None, None))
force_symmetric_errors = kwargs.pop('force_symmetric_errors', False)
if kwargs:
raise TypeError('Unexpected **kwargs: %r' % kwargs)
raise TypeError(f'Unexpected **kwargs: {repr(kwargs)}')
assert isinstance(xlim, (tuple, list))
assert len(xlim) == 2
if xlim[0] and xlim[1]:
Expand All @@ -388,7 +388,7 @@ def get_hist_1d_points(hist, **kwargs):
for key in ["x", "y", "x_edges", "x_labels", "dy"]:
points[key] = []

symmetric = (hist.GetBinErrorOption() == r.TH1.kNormal)
symmetric = hist.GetBinErrorOption() == r.TH1.kNormal # pylint: disable=no-member
if force_symmetric_errors:
symmetric = True
ixmin = hist.GetXaxis().FindBin(xlim[0]) if xlim[0] is not None else 1
Expand Down Expand Up @@ -430,10 +430,8 @@ def get_graph_points(graph):
"""

# Check input
if not isinstance(graph, (r.TGraph, r.TGraphErrors, r.TGraphAsymmErrors)):
raise TypeError(
"Expected to input to be TGraph or similar, instead got '{0}'".
format(type(graph)))
if not isinstance(graph, (r.TGraph, r.TGraphErrors, r.TGraphAsymmErrors)): # pylint: disable=no-member
raise TypeError(f"Expected to input to be TGraph or similar, instead got '{type(graph)}'")

# Extract points
points = defaultdict(list)
Expand All @@ -444,10 +442,10 @@ def get_graph_points(graph):
graph.GetPoint(i, x_val, y_val)
points["x"].append(float(x_val.value))
points["y"].append(float(y_val.value))
if isinstance(graph, r.TGraphErrors):
if isinstance(graph, r.TGraphErrors): # pylint: disable=no-member
points["dx"].append(graph.GetErrorX(i))
points["dy"].append(graph.GetErrorY(i))
elif isinstance(graph, r.TGraphAsymmErrors):
elif isinstance(graph, r.TGraphAsymmErrors): # pylint: disable=no-member
points["dx"].append((-graph.GetErrorXlow(i),
graph.GetErrorXhigh(i)))
points["dy"].append((-graph.GetErrorYlow(i),
Expand Down
Loading
Loading