Skip to content

Commit

Permalink
Change CI to use micromamba and nox
Browse files Browse the repository at this point in the history
  • Loading branch information
c-randall committed Jan 14, 2025
1 parent 7c6b9a9 commit 325a5cb
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 53 deletions.
39 changes: 15 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand All @@ -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
97 changes: 97 additions & 0 deletions inprogress/getfullargspec.py
Original file line number Diff line number Diff line change
@@ -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))
30 changes: 21 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import nox

nox.options.sessions = []


@nox.session(name='cleanup', python=False)
def run_cleanup(_):
Expand All @@ -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',
Expand All @@ -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')

Expand Down Expand Up @@ -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='):
Expand Down
34 changes: 14 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 325a5cb

Please sign in to comment.