Skip to content

Commit

Permalink
Merge pull request #88 from csdms/mcflugen/update-python
Browse files Browse the repository at this point in the history
Update python version to 3.10+
  • Loading branch information
mcflugen authored Mar 4, 2024
2 parents 56ce18b + 766b93b commit 21d5087
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.9
python-version: 3.12
channels: conda-forge
channel-priority: true

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.12

- name: Lint
run: |
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/test-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test CLI

on: [push, pull_request]

jobs:
test-cli:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository

runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash -l {0}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install nox tomli

- name: Run the tests
run: nox --session test test-cli --python ${{ matrix.python-version }} --verbose

- name: Coveralls
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
uses: AndreMiras/coveralls-python-action@v20201129
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build/Test CI
name: Test languages

on: [push, pull_request]

jobs:
build-and-test:
test-langs:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
Expand All @@ -18,18 +18,16 @@ jobs:
shell: bash -l {0}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10"]
python-version: ["3.10", "3.11", "3.12"]
language: ["c", "cxx", "python", "fortran"]

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -43,13 +41,10 @@ jobs:
run: python -m pip install nox tomli

- name: Install compilers
run: mamba install c-compiler cxx-compiler fortran-compiler cmake

- name: Run the tests
run: nox --session test test-cli --python ${{ matrix.python-version }} --verbose
run: mamba install c-compiler cxx-compiler fortran-compiler

- name: Run the language tests
run: nox --non-interactive --error-on-missing-interpreter --session test-langs --python ${{ matrix.python-version }} --verbose
run: nox -s "test-langs-${{ matrix.python-version }}(lang='${{ matrix.language }}')" --python ${{ matrix.python-version }} --verbose

- name: Coveralls
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.2.0
hooks:
- id: black
name: black
Expand All @@ -25,7 +25,7 @@ repos:
exclude: ^babelizer/data

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -35,21 +35,21 @@ repos:
exclude: ^babelizer/data

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py310-plus]
exclude: ^babelizer/data

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
files: \.py$
exclude: ^babelizer/data

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: check-builtin-literals
exclude: ^babelizer/data
Expand All @@ -66,7 +66,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
rev: 6.3.0
hooks:
- id: pydocstyle
files: babelizer/.*\.py$
Expand All @@ -77,7 +77,7 @@ repos:
additional_dependencies: [".[toml]"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-all]
Expand Down
1 change: 1 addition & 0 deletions babelizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The *babelizer*."""

from ._version import __version__

__all__ = ["__version__"]
29 changes: 18 additions & 11 deletions babelizer/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""The command line interface to the babelizer."""

import fnmatch
import os
import pathlib
import sys
import tempfile
from functools import partial

import click
import git
import pkg_resources

if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
import importlib.resources as importlib_resources
else: # pragma: no cover (<PY312)
import importlib_resources


from .errors import OutputDirExistsError, ScanError, SetupPyError, ValidationError
from .metadata import BabelMetadata
Expand Down Expand Up @@ -70,7 +77,7 @@ def init(meta, template, quiet, verbose, package_version):
META is babelizer configuration information, usually saved to a file.
"""
output = pathlib.Path(".")
template = template or pkg_resources.resource_filename("babelizer", "data")
template = template or str(importlib_resources.files("babelizer") / "data")

if not quiet:
out(f"reading template from {template}")
Expand Down Expand Up @@ -138,7 +145,7 @@ def update(template, quiet, verbose):
err("this does not appear to be a babelized folder (missing 'babel.yaml')")
raise click.Abort()

template = template or pkg_resources.resource_filename("babelizer", "data")
template = template or str(importlib_resources.files("babelizer") / "data")

if not quiet:
out(f"reading template from {template}")
Expand Down Expand Up @@ -359,9 +366,7 @@ def ask_until_done(text):
}

libraries = {}
if (not prompt) or any(
[x is not None for x in (name, library, header, entry_point)]
):
if (not prompt) or any(x is not None for x in (name, library, header, entry_point)):
babelized_class = name or ask("Name of babelized class", default="<name>")
libraries[babelized_class] = {
"language": language,
Expand All @@ -385,11 +390,13 @@ def ask_until_done(text):
libraries[babelized_class] = {
"language": language,
"library": ask(f"[{babelized_class}] Name of library to babelize"),
"header": ask(
f"[{babelized_class}] Name of header file containing BMI class "
)
if language != "python"
else "__UNUSED__",
"header": (
ask(
f"[{babelized_class}] Name of header file containing BMI class "
)
if language != "python"
else "__UNUSED__"
),
"entry_point": ask(f"[{babelized_class}] Name of BMI class "),
}
if not yes("Add another library?", default=False):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["cython", "numpy", "setuptools<60", "wheel"]
requires = ["cython", "numpy", "setuptools", "wheel"]

[tool.pytest.ini_options]
minversion = "5.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#! /usr/bin/env python
import pkg_resources
import importlib.metadata


__version__ = pkg_resources.get_distribution("{{ cookiecutter.package_name }}").version
__version__ = importlib.metadata.version("{{ cookiecutter.package_name }}")


from .bmi import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from .lib import {{ classes|join(', ') }}

{%- else %}
import pkg_resources
import sys
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
import importlib.resources as importlib_resources
else: # pragma: no cover (<PY312)
import importlib_resources


{% for babelized_class, component in cookiecutter.components|dictsort %}

Expand All @@ -20,7 +25,7 @@

{%- for cls in classes %}
{{ cls }}.__name__ = "{{ cls }}"
{{ cls }}.METADATA = pkg_resources.resource_filename(__name__ , "data/{{ cls }}")
{{ cls }}.METADATA = str(importlib_resources.files(__name__) / "data/{{ cls }}")
{%- endfor %}

{%- endif %}
Expand Down
9 changes: 7 additions & 2 deletions babelizer/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Library metadata used by the babelizer to wrap libraries."""

import pathlib
import re
import warnings
Expand Down Expand Up @@ -142,7 +143,9 @@ def __init__(
Information about how to set up continuous integration.
"""
if plugin is not None:
warnings.warn("use 'package' instead of 'plugin'", DeprecationWarning)
warnings.warn(
"use 'package' instead of 'plugin'", DeprecationWarning, stacklevel=2
)
if package is not None:
raise ValueError("specify one of 'package' or 'plugin', not both")
package = plugin
Expand Down Expand Up @@ -295,7 +298,9 @@ def validate(config):
),
optional={},
)
warnings.warn("use 'package' instead of 'plugin'", DeprecationWarning)
warnings.warn(
"use 'package' instead of 'plugin'", DeprecationWarning, stacklevel=2
)

@staticmethod
def _handle_old_style_entry_points(library):
Expand Down
10 changes: 8 additions & 2 deletions babelizer/render.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
"""Render a new babelized project."""

import contextlib
import os
import pathlib
import sys

import black as blk
import git
import isort
import pkg_resources
import tomlkit as toml
from cookiecutter.exceptions import OutputDirExistsException
from cookiecutter.main import cookiecutter

if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
import importlib.resources as importlib_resources
else: # pragma: no cover (<PY312)
import importlib_resources

from .errors import OutputDirExistsError, RenderError


Expand Down Expand Up @@ -41,7 +47,7 @@ def render(plugin_metadata, output, template=None, clobber=False, version="0.1")
Raised if output directory exists and clobber is not set.
"""
if template is None:
template = pkg_resources.resource_filename("babelizer", "data")
template = str(importlib_resources.files("babelizer") / "data")

try:
path = render_plugin_repo(
Expand Down
1 change: 1 addition & 0 deletions babelizer/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility functions used by the babelizer."""

import pathlib
import subprocess
import sys
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pathlib
import sys

import pkg_resources
from babelizer._version import __version__

# -- Path setup --------------------------------------------------------------

Expand All @@ -28,7 +28,7 @@

project = "babelizer"
author = "Community Surface Dynamics Modeling System"
version = pkg_resources.get_distribution("babelizer").version
version = __version__
release = version
this_year = datetime.date.today().year
copyright = f"{this_year}, {author}"
Expand Down
Loading

0 comments on commit 21d5087

Please sign in to comment.