diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edef5c1..4d1e3e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,16 +44,14 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Spell check - run: | - pip install codespell - codespell --config .github/linters/.codespellrc - + - name: Install nox + run: pip install nox + - name: Code format - run: | - pip install flake8 - flake8 --config .github/linters/.flake8 src - flake8 --config .github/linters/.flake8 tests + run: nox -s linter + + - name: Spell check + run: nox -s codespell test: name: (Test ${{ matrix.python-version }}, ${{ matrix.os }}) @@ -74,32 +72,25 @@ jobs: uses: actions/checkout@v4 - name: Setup conda/python - uses: conda-incubator/setup-miniconda@v3 + uses: mamba-org/setup-micromamba@v2 with: # ci_environment.yml specifies sundials version to compile - auto-update-conda: true - miniconda-version: latest environment-file: environments/ci_environment.yml - python-version: ${{ matrix.python-version }} - activate-environment: sun - channels: conda-forge - conda-remove-defaults: "true" + create-args: python=${{ matrix.python-version }} - name: Verify environment run: | - conda info - conda list + micromamba info + micromamba list - name: Install scikit-sundae run: | python -m pip install --upgrade pip - pip install . + pip install .[tests] - name: List info run: | - conda info - conda list + micromamba info + micromamba list - name: Pytest - run: | - pip install pandas pytest - pytest . + run: nox -s tests -- no-reports diff --git a/inprogress/getfullargspec.py b/inprogress/getfullargspec.py new file mode 100644 index 0000000..842fd4d --- /dev/null +++ b/inprogress/getfullargspec.py @@ -0,0 +1,97 @@ +import inspect +from collections import namedtuple +from inspect import (_POSITIONAL_ONLY, _POSITIONAL_OR_KEYWORD, _VAR_POSITIONAL, + _KEYWORD_ONLY, _VAR_KEYWORD,) + +from jax import jit as jjit +from numba import jit as njit + + +def py_func(a: int, b: int, *c, x: int = 1, y: int = 2, **z): + return x + y + + +@njit +def nb_func(a: int, b: int, *c, x: int = 1, y: int = 2, **z): + return x + y + + +@jjit +def jax_func(a: int, b: int, *c, x: int = 1, y: int = 2, **z): + return x + y + + +class py_call: + + def __call__(self, a: int, b: int, *c, x: int = 1, y: int = 2, **z): + return x + y + + @classmethod + def call(cls, a: int, b: int, *c, x: int = 1, y: int = 2, **z): + return x + y + + +FullArgSpec = namedtuple( + 'FullArgSpec', + 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations', +) + + +def getfullargspec(func) -> FullArgSpec: + + try: + sig = inspect.signature(func) + except Exception as ex: + raise TypeError('unsupported callable') from ex + + args = [] + varargs = None + varkw = None + posonlyargs = [] + kwonlyargs = [] + annotations = {} + defaults = () + kwdefaults = {} + + if sig.return_annotation is not sig.empty: + annotations['return'] = sig.return_annotation + + for param in sig.parameters.values(): + kind = param.kind + name = param.name + + if kind is _POSITIONAL_ONLY: + posonlyargs.append(name) + if param.default is not param.empty: + defaults += (param.default,) + elif kind is _POSITIONAL_OR_KEYWORD: + args.append(name) + if param.default is not param.empty: + defaults += (param.default,) + elif kind is _VAR_POSITIONAL: + varargs = name + elif kind is _KEYWORD_ONLY: + kwonlyargs.append(name) + if param.default is not param.empty: + kwdefaults[name] = param.default + elif kind is _VAR_KEYWORD: + varkw = name + + if param.annotation is not param.empty: + annotations[name] = param.annotation + + if not kwdefaults: + kwdefaults = None + + if not defaults: + defaults = None + + return FullArgSpec(posonlyargs + args, varargs, varkw, defaults, + kwonlyargs, kwdefaults, annotations) + + +print('py:', getfullargspec(py_func)) +print('nb:', getfullargspec(nb_func)) +print('jax:', getfullargspec(jax_func)) +print('call:', getfullargspec(py_call())) +print('cls:', getfullargspec(py_call.call)) diff --git a/noxfile.py b/noxfile.py index bab7209..49f086e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -5,6 +5,8 @@ import nox +nox.options.sessions = [] + @nox.session(name='cleanup', python=False) def run_cleanup(_): @@ -27,6 +29,8 @@ def run_flake8(session): Use the optional 'format' argument to run autopep8 prior to the linter. """ + + session.run('pip', 'install', '--upgrade', 'flake8') if 'format' in session.posargs: session.run('autopep8', '.', '--in-place', '--recursive', @@ -44,9 +48,10 @@ def run_codespell(session): the files. Otherwise, you will only see a summary of the found errors. """ + + session.run('pip', 'install', '--upgrade', 'codespell') command = ['codespell', '--config=.github/linters/.codespellrc'] - if 'write' in session.posargs: command.insert(1, '-w') @@ -84,14 +89,21 @@ def run_pytest(session): """ - command = [ - 'pytest', - '--cov=src/sksundae', - '--cov-report=html:reports/htmlcov', - '--cov-report=xml:reports/coverage.xml', - '--junitxml=reports/junit.xml', - 'tests/', - ] + if 'no-reports' in session.posargs: + command = [ + 'pytest', + '--cov=src/sksundae', + 'tests/', + ] + else: + command = [ + 'pytest', + '--cov=src/sksundae', + '--cov-report=html:reports/htmlcov', + '--cov-report=xml:reports/coverage.xml', + '--junitxml=reports/junit.xml', + 'tests/', + ] for arg in session.posargs: if arg.startswith('parallel='): diff --git a/pyproject.toml b/pyproject.toml index ede4807..3f411b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,35 +51,29 @@ version = {attr = "sksundae.__version__"} where = ["src"] [project.optional-dependencies] -dev = [ - "nox", - "pandas", - "pytest", - "pytest-cov", - "pytest-xdist", - "genbadge[all]", - "flake8", - "autopep8", - "codespell", - "sphinx", - "myst-nb", - "sphinx-design", - "sphinx-autoapi", - "sphinx-favicon", - "sphinx-copybutton", - "pydata-sphinx-theme", - "matplotlib", -] docs = [ "sphinx", "myst-nb", "sphinx-design", "sphinx-autoapi", - "sphinx-favicon", "sphinx-copybutton", "pydata-sphinx-theme", "matplotlib", ] +tests = [ + "pandas", + "pytest", + "pytest-cov", + "pytest-xdist", +] +dev = [ + "nox", + "flake8", + "autopep8", + "codespell", + "genbadge[all]", + "scikit-sundae[docs,tests]", +] [project.urls] Homepage = "https://github.com/NREL/scikit-sundae"