Skip to content

Commit

Permalink
Modernize with new tooling and fix or update some code (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
153957 authored May 10, 2024
2 parents 8f5069e + beae082 commit 34e7f9f
Show file tree
Hide file tree
Showing 164 changed files with 6,153 additions and 5,766 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf

[*.py]
max_line_length = 120

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[Makefile]
indent_style = tab
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
fail-fast: false
matrix:
python-version: [
'3.8',
'3.9',
'3.10',
'3.11',
'3.12',
]
runs-on: ubuntu-latest
steps:
Expand All @@ -30,19 +30,19 @@ jobs:
- run: make unittests
- run: coverage report

flake:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install flake8 flake8-isort pep8-naming
- run: make flaketest
- run: pip install ruff
- run: make linttest

docs:
if: github.ref == 'refs/heads/master'
needs: [tests, flake]
needs: [tests, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
.PHONY: test unittests flaketest doctest update_data

.PHONY: test
test: unittests flaketest doctest

.PHONY: unittests
unittests:
coverage run -m unittest

flaketest:
flake8 sapphire
.PHONY: linttest
linttest:
ruff check .

.PHONY: lintfix
lintfix:
ruff check --fix-only .

.PHONY: doctest
doctest:
sphinx-build -anW doc doc/_build/html

.PHONY: update_data
update_data:
ifeq ($(strip $(shell git status --porcelain | wc -l)), 0)
@echo "Updating local data. Creating test data to match local data and committing."
Expand Down
39 changes: 20 additions & 19 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath('.'))

# Often reused
AUTHORS = 'David Fokkema, Arne de Laat, and Tom Kooij'
Expand Down Expand Up @@ -83,27 +81,26 @@
# Output file base name for HTML help builder.
htmlhelp_basename = 'SAPPHiREdoc'


def setup(app):
app.add_css_file('hisparc_style.css')


# -- Options for LaTeX output --------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'SAPPHiRE.tex', 'SAPPHiRE Documentation',
AUTHORS, 'manual'),
('index', 'SAPPHiRE.tex', 'SAPPHiRE Documentation', AUTHORS, 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -116,8 +113,7 @@ def setup(app):
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'sapphire', 'SAPPHiRE Documentation',
[AUTHORS], 1)
('index', 'sapphire', 'SAPPHiRE Documentation', [AUTHORS], 1),
]


Expand All @@ -127,10 +123,15 @@ def setup(app):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'SAPPHiRE', 'SAPPHiRE Documentation',
AUTHORS, 'SAPPHiRE',
'One line description of project.',
'Miscellaneous'),
(
'index',
'SAPPHiRE',
'SAPPHiRE Documentation',
AUTHORS,
'SAPPHiRE',
'One line description of project.',
'Miscellaneous',
),
]


Expand Down
3 changes: 2 additions & 1 deletion doc/scripts/is_useful.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def square(x):
return x ** 2
return x**2


print(1, 2, 3)
print(square(1), square(2), square(3))
2 changes: 1 addition & 1 deletion doc/scripts/is_useful_and_importable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def square(x):
return x ** 2
return x**2


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions doc/scripts/plot_zenith_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def plot_zenith_distribution(data):
zenith = zenith.compress(-isnan(zenith))

plt.hist(degrees(zenith), bins=linspace(0, 90, 51), histtype='step')
plt.xlabel("zenith [deg]")
plt.ylabel("count")
plt.xlabel('zenith [deg]')
plt.ylabel('count')


if __name__ == '__main__':
Expand Down
189 changes: 189 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
[build-system]
requires = ['flit_core>=3.9']
build-backend = 'flit_core.buildapi'

[project]
name = 'hisparc-sapphire'
version = '2.0.0'
description = 'A framework for the HiSPARC experiment'
readme = 'README.rst'
requires-python = '>=3.9'
license = {file = 'LICENSE'}
authors = [
{name = 'Arne de Laat', email = 'arne@delaat.net'},
{name = 'David Fokkema'},
{name = 'Tom Kooij'},
]
maintainers = [
{name = 'Arne de Laat', email = 'arne@delaat.net'},
]
keywords = [
'cosmic rays',
'detectors',
'astrophysics',
'HiSPARC',
'Nikhef',
'University of Utah',
]
classifiers = [
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python',
'Topic :: Education',
'Topic :: Scientific/Engineering',
]
dependencies = [
'numpy>=1.25.2',
'scipy>=1.13.0',
'tables>=3.9.2',
'progressbar2>=4.4.2',
]

[project.optional-dependencies]
dev = [
'Sphinx',
'coverage==7.4.4',
'ruff==0.4.1',
]
astropy = [
'astropy>=5.0.0',
]
publish = [
'flit==3.9.0',
]

[project.urls]
Homepage = 'https://data.hisparc.nl'
Documentation = 'https://docs.hisparc.nl/sapphire/'
Repository = 'https://github.com/hisparc/sapphire/'
Issues = 'https://github.com/HiSPARC/sapphire/issues'

[project.scripts]
create_and_store_test_data = 'sapphire.tests.create_and_store_test_data:main'
update_local_data = 'sapphire.data.update_local_data:main'
extend_local_data = 'sapphire.data.extend_local_data:main'

[tool.flit.module]
name = 'sapphire'

[tool.ruff]
line-length = 120
target-version = 'py39'
extend-exclude = [
'doc/',
'scripts/',
]

[tool.ruff.format]
quote-style = 'single' # Prefer single quotes, except for triple quotes strings

[tool.ruff.lint]
select = ['ALL'] # https://docs.astral.sh/ruff/rules/
ignore = [
'ANN', # No type annotations yet
'ARG002', # Allow unused arguments to keep signature equal for similar functions
'B028', # Allow warnings.warn without stacklevel
'B904', # Allow skipping causes for exceptions
'BLE001', # Allow catching Exception
'CPY001', # Do not require copyright notices
'D', # Ignore docstring checks
'DTZ', # Ignore timezones for datetime
'E731', # Allow assigning lambda to variable
'EM', # Allow messages directly in exceptions
'ERA001', # Allow commented code
'F405', # Allow star imports
'FBT001', # Allow positional for boolean arguments
'FBT002', # Allow default value for boolean arguments
'PD', # Not using pandas
'PERF203', # Allow try-except in loop
'PLR0913', # Allow functions with many arguments
'PLR6301', # Allow not using self in methods
'PT', # Not using pytest
'PTH', # Allow using os.path
'RET504', # Allow variable assignment before return
'RET505', # Allow elif after return
'RET506', # Allow elif after raise
'RET507', # Allow elif after continue
'RET508', # Allow elif after break
'S311', # Allow using random for non-cryptographic purposes
'SIM108', # Allow if-else block instead of ternary
'SIM117', # Allow separate with statements to preserve context
'SLF001', # Allow accessing private members
'T201', # Allow using print
'TD002', # Allow TODO without author
'TD003', # Allow TODO without issue link
'TID252', # Allow relative imports
'TRY003', # Specific messages for common exception classes

# TODO these still need to be checked (i.e. ignored or fixed)
'ARG001',
'ARG003',
'ARG005',
'B018',
'C901',
'FBT003',
'FIX002',
'G002',
'G004',
'NPY002',
'PLR0911',
'PLR0912',
'PLR0915',
'PLR2004',
'PLW2901',
'RET503',
'RUF005',
'RUF012',
'S103',
'S108',
'S310',
'S602',
'S603',
'S604',
'S607',
'SIM102',
'SIM105',
'SIM115',
'TRY301',
'TRY400',
'UP031',
]

[tool.ruff.lint.per-file-ignores]
'sapphire/corsika/units.py' = ['N816'] # Allow mixed case variables
'sapphire/esd.py' = ['A002'] # Some keyword arguments shadow a builtin
'sapphire/kascade.py' = ['N806'] # Allow non lower case variables to match KASCADE
'sapphire/storage.py' = ['N815'] # Allow mixed case variables
'sapphire/tests/simulations/test_gammas.py' = ['N806'] # Allow upper case variables
'sapphire/tests/transformations/test_celestial.py' = ['N806'] # Allow upper case variables

[tool.ruff.lint.flake8-quotes]
inline-quotes = 'single'

[tool.ruff.lint.isort]
lines-between-types = 1
section-order = [
'future',
'standard-library',
'third-party',
'extras',
'first-party',
'local-folder',
]

[tool.ruff.lint.isort.sections]
extras = ['artist', 'pylab']

[tool.coverage.run]
branch = true
source = [
'sapphire',
]

[tool.coverage.report]
show_missing = true
skip_empty = true
skip_covered = true
2 changes: 0 additions & 2 deletions sapphire/README

This file was deleted.

1 change: 1 addition & 0 deletions sapphire/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Simulation and Analysis Program Package for HiSPARC Research (SAPPHiRE)
Loading

0 comments on commit 34e7f9f

Please sign in to comment.