Skip to content

Commit

Permalink
pre-commit: sort imports / update contrib doc (AMICI-dev#2085)
Browse files Browse the repository at this point in the history
* pre-commit: sort imports / update contrib doc

* sort imports

* fix circular import
  • Loading branch information
dweindl authored May 13, 2023
1 parent fe1874c commit b4add4a
Show file tree
Hide file tree
Showing 75 changed files with 309 additions and 327 deletions.
26 changes: 16 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-added-large-files

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand Down
17 changes: 5 additions & 12 deletions documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
import re
import subprocess
import sys
import typing

# need to import before setting typing.TYPE_CHECKING=True, fails otherwise
import amici
import exhale.deploy
import exhale_multiproject_monkeypatch
import mock
from exhale import configs as exhale_configs
from sphinx.transforms.post_transforms import ReferencesResolver

# need to import before setting typing.TYPE_CHECKING=True, fails otherwise
import pandas as pd
import sympy as sp
from exhale import configs as exhale_configs
from sphinx.transforms.post_transforms import ReferencesResolver

exhale_multiproject_monkeypatch, pd, sp # to avoid removal of unused import

Expand Down Expand Up @@ -60,7 +59,7 @@ def my_breathe_DomainDirectiveFactory_create(domain: str, args):
if domain != "mat":
return old_breathe_DomainDirectiveFactory_create(domain, args)

from sphinxcontrib.matlab import MATLABDomain, MatClassmember
from sphinxcontrib.matlab import MatClassmember, MATLABDomain

matlab_classes = {k: (v, k) for k, v in MATLABDomain.directives.items()}
matlab_classes["variable"] = (MatClassmember, "attribute")
Expand Down Expand Up @@ -125,12 +124,6 @@ def install_doxygen():
# Required for matlab doxygen processing
install_mtocpp()

# Install AMICI if not already present
typing.TYPE_CHECKING = True
import amici

typing.TYPE_CHECKING = False


# -- Project information -----------------------------------------------------
# The short X.Y version
Expand Down
41 changes: 20 additions & 21 deletions documentation/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ AMICI roughly follows the
All new contributions are merged into ``develop``. These changes are
regularly merged into ``master`` as new releases. For release versioning
we are trying to follow `semantic versioning <https://semver.org/>`__.
New releases are created on Github and are automatically deployed to
`Zenodo <https://zenodo.org/record/3362453#.XVwJ9vyxVMA>`__ for
New releases are created on GitHub and are automatically deployed to
`Zenodo <https://doi.org/10.5281/zenodo.597928>`__ for
archiving and to obtain a digital object identifier (DOI) to make them
citable. Furthermore, our `CI pipeline <documentation/CI.md>`__ will
automatically create and deploy a new release on
Expand Down Expand Up @@ -51,17 +51,11 @@ process described below:

- Submit a pull request to the ``develop`` branch

- Make sure your code is documented appropriately

- Run ``scripts/run-doxygen.sh`` to check completeness of your
documentation

- Make sure your code is compatible with C++17, ``gcc`` and ``clang``
(our CI pipeline will do this for you)
- Ensure all tests pass

- When adding new functionality, please also provide test cases (see
``tests/cpp/`` and
`documentation/CI.md <documentation/CI.md>`__)
``tests/cpp/``, ``python/tests/``,
and `documentation/CI.md <documentation/CI.md>`__)

- Write meaningful commit messages

Expand All @@ -84,8 +78,8 @@ process described below:
- Wait for feedback. If you do not receive feedback to your pull
request within a week, please give us a friendly reminder.

Style guide
~~~~~~~~~~~
Style/compatibility guide
~~~~~~~~~~~~~~~~~~~~~~~~~

General
^^^^^^^
Expand All @@ -105,12 +99,18 @@ Python
- For the Python code we want to follow
`PEP8 <https://www.python.org/dev/peps/pep-0008/>`__. Although this
is not the case for all existing code, any new contributions should
do so.
do so. We use `black <https://black.readthedocs.io/en/stable/index.html>`__
for code formatting.

To run black as pre-commit hook, install the
`pre-commit <https://pre-commit.com/>`_ package
(e.g. ``pip install pre-commit``), and enable AMICI-hooks by running
``pre-commit install`` from within the AMICI directory.

- We use Python `type
hints <https://docs.python.org/3/library/typing.html>`__ for all
functions (but not for class attributes, since they are not supported
by the current Python doxygen filter). In Python code type hints
by the current Python doxygen filter). In Python code, type hints
should be used instead of doxygen ``@type``.

For function docstrings, follow this format:
Expand All @@ -135,15 +135,14 @@ Python
C++
^^^

- We use C++14
- We use C++17

- We want to maintain compatibility with g++, clang and the Intel C++
- We want to maintain compatibility with g++, clang, and the Intel C++
compiler

- For code formatting, we use the settings from ``.clang-format`` in
the root directory

- *Details to be defined*
- For code formatting, we use ``clang-format`` and ``cmake-format``. They can
be invoked by ``make clang-format cmake-format`` from the CMake build
directory.

Matlab
^^^^^^
Expand Down
9 changes: 5 additions & 4 deletions documentation/recreate_reference_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
Requires pandoc
"""

import biblib.bib
import biblib.messages
import biblib.algo
import os
import sys
import subprocess
import sys

import biblib.algo
import biblib.bib
import biblib.messages


def get_keys_by_year(bibfile):
Expand Down
14 changes: 7 additions & 7 deletions python/benchmark/benchmark_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
times are averages of N_REPEATS simulations at reference values.
"""

import importlib
import os
import pysb
import sys
import timeit

import amici
from amici.pysb_import import pysb2amici
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import importlib
import timeit
import sys

import pysb
from amici.pysb_import import pysb2amici
from pysb.simulator import ScipyOdeSimulator

sys.path.insert(0, os.path.join("..", "tests"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pysb.core import Rule, Parameter, Model, Monomer, Expression, Initial, Observable
import os

import pysb.export
import os
from pysb.core import Expression, Initial, Model, Monomer, Observable, Parameter, Rule

model = Model()

Expand Down
15 changes: 7 additions & 8 deletions python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sys
from pathlib import Path
from types import ModuleType as ModelModule
from typing import Optional, Union, Callable, Any
from typing import Any, Callable, Optional, Union


def _get_amici_path():
Expand Down Expand Up @@ -52,7 +52,7 @@ def _get_commit_hash():
def _imported_from_setup() -> bool:
"""Check whether this module is imported from `setup.py`"""

from inspect import getouterframes, currentframe
from inspect import currentframe, getouterframes
from os import sep

# in case we are imported from setup.py, this will be the AMICI package
Expand Down Expand Up @@ -107,18 +107,17 @@ def _imported_from_setup() -> bool:
# has to be done before importing readSolverSettingsFromHDF5
# from .swig_wrappers
hdf5_enabled = "readSolverSettingsFromHDF5" in dir()
from .swig_wrappers import *

# These modules require the swig interface and other dependencies
from .numpy import ReturnDataView, ExpDataView
from .numpy import ExpDataView, ReturnDataView
from .pandas import *
from .swig_wrappers import *

# These modules don't require the swig interface
from .sbml_import import SbmlImporter, assignmentRules2observables
from .de_export import DEModel, DEExporter

from typing import Protocol, runtime_checkable

from .de_export import DEExporter, DEModel
from .sbml_import import SbmlImporter, assignmentRules2observables

@runtime_checkable
class ModelModule(Protocol):
"""Type of AMICI-generated model modules.
Expand Down
3 changes: 2 additions & 1 deletion python/sdist/amici/__init__.template.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""AMICI-generated module for model TPL_MODELNAME"""

import amici
from pathlib import Path

import amici

# Ensure we are binary-compatible, see #556
if "TPL_AMICI_VERSION" != amici.__version__:
raise amici.AmiciVersionError(
Expand Down
3 changes: 2 additions & 1 deletion python/sdist/amici/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Package-level entrypoint"""

from . import __version__, compiledWithOpenMP, has_clibs, hdf5_enabled
import os
import sys

from . import __version__, compiledWithOpenMP, has_clibs, hdf5_enabled


def print_info():
"""Displays information on the current AMICI installation.
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/conserved_quantities_demartino.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import math
import random
import sys
from typing import List, MutableSequence, Sequence, Tuple, Union, Optional
from typing import List, MutableSequence, Optional, Sequence, Tuple, Union

from .logging import get_logger

Expand Down
3 changes: 1 addition & 2 deletions python/sdist/amici/custom_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import sys
from pathlib import Path

from amici.swig import fix_typehints
from cmake_build_extension import BuildExtension, CMakeExtension
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from setuptools.command.sdist import sdist

from amici.swig import fix_typehints


class AmiciInstall(install):
"""Custom `install` command to handle extra arguments"""
Expand Down
4 changes: 2 additions & 2 deletions python/sdist/amici/cxxcodeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import itertools
import os
import re
from typing import Dict, List, Optional, Tuple, Iterable
from typing import Dict, Iterable, List, Optional, Tuple

import sympy as sp
from sympy.codegen.rewriting import optimize, Optimization
from sympy.codegen.rewriting import Optimization, optimize
from sympy.printing.cxx import CXX11CodePrinter
from sympy.utilities.iterables import numbered_symbols
from toposort import toposort
Expand Down
Loading

0 comments on commit b4add4a

Please sign in to comment.