Skip to content

Commit

Permalink
switch to pyproject, modernize everything (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener authored Jan 6, 2025
1 parent a28e220 commit 0470b06
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 539 deletions.
59 changes: 33 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,43 @@ on:
- cron: '5 0 * * *'

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
# matches compat target in setup.py
python-version: '3.7'
- name: Run flake8
run: |
pip install -U flake8 pep8-naming flake8-quotes flake8-comprehensions flake8-isort types-psutil numpy flake8-bugbear
flake8 setup.py doc/conf.py logpyle bin/* examples/*.py test/*.py
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Ruff check
run: |
python -m pip install ruff
ruff check
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master

examples:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.x']
os: [ubuntu-latest, macos-13]
python-version: ['3.10', '3.11', '3.12', '3.13', '3.x']
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install prerequisites
run: |
[[ $(uname) == "Darwin" ]] && brew install open-mpi
[[ $(uname) == "Linux" ]] && sudo apt-get update && sudo apt-get install -y mpich libmpich-dev
[[ $(uname) == "Linux" ]] && sudo apt-get update && sudo apt-get install -y libopenmpi-dev
pip install wheel matplotlib mpi4py psutil
pip install -e .
- name: Run and test examples
Expand All @@ -53,7 +58,7 @@ jobs:
## Check for warnings and logging
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))'
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' | grep Oof
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' | grep "warnings capture test"
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from logging"))'
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from logging"))' | grep WARNING
Expand Down Expand Up @@ -89,7 +94,7 @@ jobs:
## Check for warnings and logging
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))'
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' | grep Oof
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' | grep "warnings capture test"
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from logging"))'
runalyzer summary.sqlite -c 'db.print_cursor(db.q("select * from logging"))' | grep WARNING
Expand Down Expand Up @@ -151,7 +156,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: "Main Script"
Expand All @@ -165,20 +170,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: "Main Script"
run: |
set -x
sudo apt-get update && sudo apt-get install -y libopenmpi-dev
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-mypy.sh
export EXTRA_INSTALL="pytools numpy types-psutil pymbolic"
export EXTRA_INSTALL="pytools numpy types-psutil pymbolic mpi4py matplotlib"
. ./prepare-and-run-mypy.sh python3
pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand All @@ -196,7 +203,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Compare coverage with 'main' branch
Expand Down Expand Up @@ -226,7 +233,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand All @@ -245,7 +252,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand Down
Empty file modified bin/upgrade-db
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions doc/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ the hood, this ensures that the quantity is gathered from all present run_ids.

Magic refers to the usage of customized commands to operate on our mangled and
non-mangled SQL queries. To issue a magic command, preceding it with a ``.``.
This will issue a command to runalyzer instead of refering to a python symbol.
This will issue a command to runalyzer instead of referring to a python symbol.

Running the script
------------------
Expand Down Expand Up @@ -222,11 +222,11 @@ before serving it.
Usage
-----
After the virtual environment has been setup, click the ``Add file`` button
to add a pannel for analysis.
to add a panel for analysis.

To analyze a run, click on the browse button to upload one or more files.
These files will be gathered together under the hood. You can then select
quantites from the X and Y dropdowns. If you would like to keep track of
quantities from the X and Y dropdowns. If you would like to keep track of
multiple quantities in the same graph, you can press ``Add Line to Plot``
to add a Y dropdown.

Expand Down
102 changes: 16 additions & 86 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,99 +1,32 @@
#!/usr/bin/env python3

import sys
from urllib.request import urlopen

# -- General configuration ------------------------------------------------
from logpyle import __version__

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# {{{ linkcode_resolve

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx_copybutton",
]
autoclass_content = "class"
# autodoc_typehints = "description"
_conf_url = \
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
exec(compile(_inf.read(), _conf_url, "exec"), globals())

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
old_linkcode_resolve = linkcode_resolve # noqa: F821 (linkcode_resolve comes from the URL above)

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"
def linkcode_resolve(*args, **kwargs):
linkcode_url = "https://github.com/illinois-ceesd/logpyle/blob/main/{filepath}#L{linestart}-L{linestop}"
return old_linkcode_resolve(*args, **kwargs, linkcode_url=linkcode_url)


# }}}

# General information about the project.
project = "logpyle"
copyright = "2017, Andreas Kloeckner"
author = "Andreas Kloeckner"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
ver_dic = {}
exec(
compile(open("../logpyle/version.py").read(), "../logpyle/version.py", "exec"),
ver_dic,
)
version = ".".join(str(x) for x in ver_dic["VERSION"])
release = ver_dic["VERSION_TEXT"]

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

nitpicky = True


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"

html_theme_options = {}

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
version = __version__
release = __version__


intersphinx_mapping = {
Expand All @@ -103,6 +36,3 @@
"pytools": ("https://documen.tician.de/pytools/", None),
"mpi4py": ("https://mpi4py.readthedocs.io/en/stable/", None),
}


sys._BUILDING_SPHINX_DOCS = True
16 changes: 12 additions & 4 deletions examples/log-mpi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#!/usr/bin/env python3

import logging
from collections.abc import Callable
from random import uniform
from time import sleep
from typing import Any, Callable
from typing import Any
from warnings import warn

from mpi4py import MPI

from logpyle import (IntervalTimer, LogManager, LogQuantity, add_general_quantities,
add_run_info, add_simulation_quantities, set_dt)
from logpyle import (
IntervalTimer,
LogManager,
LogQuantity,
add_general_quantities,
add_run_info,
add_simulation_quantities,
set_dt,
)


class Fifteen(LogQuantity):
Expand Down Expand Up @@ -68,7 +76,7 @@ def main() -> None:

# Illustrate warnings/logging capture
if uniform(0, 1) < 0.05:
warn("Oof. Something went awry.")
warn("warnings capture test", stacklevel=2)

if istep == 16:
logger.warning("test logging")
Expand Down
15 changes: 11 additions & 4 deletions examples/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
from time import sleep
from warnings import warn

from logpyle import (GCStats, IntervalTimer, LogManager, LogQuantity,
add_general_quantities, add_run_info, add_simulation_quantities,
set_dt)
from logpyle import (
GCStats,
IntervalTimer,
LogManager,
LogQuantity,
add_general_quantities,
add_run_info,
add_simulation_quantities,
set_dt,
)


class Fifteen(LogQuantity):
Expand Down Expand Up @@ -59,7 +66,7 @@ def main() -> None:

# Illustrate warnings capture
if uniform(0, 1) < 0.05:
warn("Oof. Something went awry.")
warn("warnings capture test", stacklevel=2)

if istep == 50:
logger.warning("test logging")
Expand Down
16 changes: 11 additions & 5 deletions examples/optional-log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
from contextlib import nullcontext
from random import uniform
from time import sleep
from typing import Union

from logpyle import (IntervalTimer, LogManager, _SubTimer, add_general_quantities,
add_run_info, add_simulation_quantities, set_dt)
from logpyle import (
IntervalTimer,
LogManager,
_SubTimer,
add_general_quantities,
add_run_info,
add_simulation_quantities,
set_dt,
)


def main(use_logpyle: bool) -> None:
def main(use_logpyle: bool) -> None: # noqa: C901
if use_logpyle:
logmgr = LogManager("optional-log.sqlite", "w")
else:
Expand All @@ -25,7 +31,7 @@ def main(use_logpyle: bool) -> None:
if logmgr:
vis_timer = IntervalTimer("t_vis", "Time spent visualizing")
logmgr.add_quantity(vis_timer)
time_vis: Union[_SubTimer, nullcontext[None]] = vis_timer.get_sub_timer()
time_vis: _SubTimer | nullcontext[None] = vis_timer.get_sub_timer()
else:
time_vis = nullcontext()

Expand Down
Loading

0 comments on commit 0470b06

Please sign in to comment.