Skip to content

Commit

Permalink
docs: add "Analysing the code" section on Pylint
Browse files Browse the repository at this point in the history
* Change "type" to "file_type" in argument of add_additional_resource.
* Disable some messages from Pylint when run on my local installation.
  • Loading branch information
GraemeWatt committed Oct 14, 2023
1 parent 1aea7b2 commit dfa0a89
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 23 deletions.
13 changes: 12 additions & 1 deletion docs/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ After installing the ``hepdata_lib`` package, move into the ``hepdata_lib/docs``

pip install -r requirements.txt

Then you can build the documentation locally with Sphinx using ``make html`` and view the output by opening a web browser at ``_build/html/index.html``.
Then you can build the documentation locally with Sphinx using ``make html`` and view the output by opening a web browser at ``_build/html/index.html``.


Analysing the code
------------------

::

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

These commands are run by GitHub Actions, so you should first check locally that no issues are flagged.
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ Additional resources, hosted either externally or locally, can be linked with th

sub.add_additional_resource("Web page with auxiliary material", "https://atlas.web.cern.ch/Atlas/GROUPS/PHYSICS/PAPERS/STDM-2012-02/")
sub.add_additional_resource("Some file", "root_file.root", copy_file=True)
sub.add_additional_resource("Archive of full likelihoods in the HistFactory JSON format", "Likelihoods.tar.gz", copy_file=True, type="HistFactory")
sub.add_additional_resource("Archive of full likelihoods in the HistFactory JSON format", "Likelihoods.tar.gz", copy_file=True, file_type="HistFactory")

The first argument is a ``description`` and the second is the ``location`` of the external link or local resource file.
The optional argument ``copy_file=True`` (default value of ``False``) will copy a local file into the output directory.
The optional argument ``type="HistFactory"`` (default value of ``None``) can be used to identify statistical models provided in the HistFactory JSON
The optional argument ``file_type="HistFactory"`` (default value of ``None``) can be used to identify statistical models provided in the HistFactory JSON
format rather than relying on certain trigger words in the ``description`` (see `pyhf section of submission documentation`_).

The ``add_link`` function can alternatively be used to add a link to an external resource:
Expand Down
8 changes: 4 additions & 4 deletions hepdata_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self):
self.files_to_copy = []
self.additional_resources = []

def add_additional_resource(self, description, location, copy_file=False, type=None):
def add_additional_resource(self, description, location, copy_file=False, file_type=None):
"""
Add any kind of additional resource.
If copy_file is set to False, the location and description will be added as-is.
Expand All @@ -78,7 +78,7 @@ def add_additional_resource(self, description, location, copy_file=False, type=N
:param copy_file: If set to true, will attempt to copy a local file to the tar ball.
:type copy_file: bool
:param type: Type of the resource file. Currently, only "HistFactory" has any effect.
:param file_type: Type of the resource file. Currently, only "HistFactory" has any effect.
"""

resource = {}
Expand All @@ -91,8 +91,8 @@ def add_additional_resource(self, description, location, copy_file=False, type=N
else:
resource["location"] = location

if type:
resource["type"] = type
if file_type:
resource["type"] = file_type

self.additional_resources.append(resource)

Expand Down
2 changes: 1 addition & 1 deletion hepdata_lib/c_file_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""".C file reader"""
import io
from array import array
from array import array # pylint: disable-msg=E0611
from future.utils import raise_from
from ROOT import TGraph, TGraphErrors
import hepdata_lib.root_utils as ru
Expand Down
2 changes: 1 addition & 1 deletion hepdata_lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_number_precision(value):
if value == 0 or isinstance(value, str) or np.isnan(value) or np.isinf(value):
return value

return math.ceil(math.log10(abs(value)))
return math.ceil(math.log10(abs(value))) # pylint: disable-msg=I1101


def relative_round(value, relative_digits):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cfilereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest import TestCase
import os
import numpy as np
from hepdata_lib.c_file_reader import CFileReader
from hepdata_lib.c_file_reader import CFileReader # pylint: disable-msg=E0401

class TestCFileReader(TestCase):
"""Test the CFileReader class."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# !/usr/bin/env python
"""Test execute_command() function."""
from unittest import TestCase
from hepdata_lib.helpers import execute_command
from hepdata_lib.helpers import execute_command # pylint: disable-msg=E0401

class TestExecuteCommand(TestCase):
"""Test execute_command() function."""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import numpy as np

from hepdata_lib.helpers import relative_round
from hepdata_lib.helpers import get_number_precision
from hepdata_lib.helpers import get_value_precision_wrt_reference
from hepdata_lib.helpers import round_value_and_uncertainty
from hepdata_lib.helpers import relative_round # pylint: disable-msg=E0401
from hepdata_lib.helpers import get_number_precision # pylint: disable-msg=E0401
from hepdata_lib.helpers import get_value_precision_wrt_reference # pylint: disable-msg=E0401
from hepdata_lib.helpers import round_value_and_uncertainty # pylint: disable-msg=E0401


class TestHelpers(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import yaml
from test_utilities import tmp_directory_name
from hepdata_lib import Submission, Table, Variable
from hepdata_lib import Submission, Table, Variable # pylint: disable-msg=E0401

class TestOutput(TestCase):
"""Test output"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rootfilereader.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
"""Test RootFileReader."""
from unittest import TestCase
from array import array
from array import array # pylint: disable-msg=E0611
import os
import ctypes
import numpy as np
import ROOT
from test_utilities import float_compare, tuple_compare, histogram_compare_1d, make_tmp_root_file
from hepdata_lib.root_utils import RootFileReader
from hepdata_lib.root_utils import RootFileReader # pylint: disable-msg=E0401


class TestRootFileReader(TestCase):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest import TestCase
import tarfile
from test_utilities import tmp_directory_name
from hepdata_lib import Submission, Table, Variable, Uncertainty
from hepdata_lib import Submission, Table, Variable, Uncertainty # pylint: disable-msg=E0401

class TestSubmission(TestCase):
"""Test the Submission class."""
Expand Down Expand Up @@ -60,7 +60,8 @@ def test_additional_resource_size(self):
with open(testpath, "wb") as testfile:
testfile.write(bytes("\0" * size, "utf-8"))
try:
test_submission.add_additional_resource("Some description", testpath, copy_file=True, type="HistFactory")
test_submission.add_additional_resource("Some description", testpath,
copy_file=True, file_type="HistFactory")
except RuntimeError:
self.fail("Submission.add_additional_resource raised an unexpected RuntimeError.")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest import TestCase

from test_utilities import tmp_directory_name
from hepdata_lib import Table, Variable, Uncertainty
from hepdata_lib import Table, Variable, Uncertainty # pylint: disable-msg=E0401

class TestTable(TestCase):
"""Test the Table class."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from unittest import TestCase
import test_utilities
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Variable, Uncertainty # pylint: disable-msg=E0401


class TestUncertainty(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from unittest import TestCase
import test_utilities
from hepdata_lib import Variable, Uncertainty
from hepdata_lib import Variable, Uncertainty # pylint: disable-msg=E0401


class TestVariable(TestCase):
Expand Down

0 comments on commit dfa0a89

Please sign in to comment.