Skip to content

Commit 21d5087

Browse files
authored
Merge pull request #88 from csdms/mcflugen/update-python
Update python version to 3.10+
2 parents 56ce18b + 766b93b commit 21d5087

23 files changed

+245
-151
lines changed

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- uses: conda-incubator/setup-miniconda@v2
3939
with:
4040
auto-update-conda: true
41-
python-version: 3.9
41+
python-version: 3.12
4242
channels: conda-forge
4343
channel-priority: true
4444

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
19-
- name: Set up Python 3.9
19+
- name: Set up Python 3.12
2020
uses: actions/setup-python@v2
2121
with:
22-
python-version: 3.9
22+
python-version: 3.12
2323

2424
- name: Lint
2525
run: |

.github/workflows/test-cli.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test CLI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-cli:
7+
# We want to run on external PRs, but not on our own internal PRs as they'll be run
8+
# by the push to the branch. Without this if check, checks are duplicated since
9+
# internal PRs match both the push and pull_request events.
10+
if:
11+
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
12+
github.repository
13+
14+
runs-on: ${{ matrix.os }}
15+
16+
defaults:
17+
run:
18+
shell: bash -l {0}
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-latest, macos-latest]
24+
python-version: ["3.10", "3.11", "3.12"]
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
with:
29+
submodules: true
30+
- name: Set up Python ${{ matrix.python-version }}
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
35+
- name: Install dependencies
36+
run: python -m pip install nox tomli
37+
38+
- name: Run the tests
39+
run: nox --session test test-cli --python ${{ matrix.python-version }} --verbose
40+
41+
- name: Coveralls
42+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
43+
uses: AndreMiras/coveralls-python-action@v20201129

.github/workflows/build-test-ci.yml .github/workflows/test-langs.yml

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Build/Test CI
1+
name: Test languages
22

33
on: [push, pull_request]
44

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

2020
strategy:
21+
fail-fast: false
2122
matrix:
2223
os: [ubuntu-latest, macos-latest]
23-
python-version: ["3.9", "3.10"]
24+
python-version: ["3.10", "3.11", "3.12"]
25+
language: ["c", "cxx", "python", "fortran"]
2426

2527
steps:
2628
- uses: actions/checkout@v3
2729
with:
2830
submodules: true
29-
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v4
31-
with:
32-
python-version: ${{ matrix.python-version }}
3331

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

4543
- name: Install compilers
46-
run: mamba install c-compiler cxx-compiler fortran-compiler cmake
47-
48-
- name: Run the tests
49-
run: nox --session test test-cli --python ${{ matrix.python-version }} --verbose
44+
run: mamba install c-compiler cxx-compiler fortran-compiler
5045

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

5449
- name: Coveralls
5550
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'

.pre-commit-config.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.3.0
3+
rev: 24.2.0
44
hooks:
55
- id: black
66
name: black
@@ -25,7 +25,7 @@ repos:
2525
exclude: ^babelizer/data
2626

2727
- repo: https://github.com/pycqa/flake8
28-
rev: 4.0.1
28+
rev: 7.0.0
2929
hooks:
3030
- id: flake8
3131
additional_dependencies:
@@ -35,21 +35,21 @@ repos:
3535
exclude: ^babelizer/data
3636

3737
- repo: https://github.com/asottile/pyupgrade
38-
rev: v2.34.0
38+
rev: v3.15.1
3939
hooks:
4040
- id: pyupgrade
41-
args: [--py38-plus]
41+
args: [--py310-plus]
4242
exclude: ^babelizer/data
4343

4444
- repo: https://github.com/PyCQA/isort
45-
rev: 5.10.1
45+
rev: 5.13.2
4646
hooks:
4747
- id: isort
4848
files: \.py$
4949
exclude: ^babelizer/data
5050

5151
- repo: https://github.com/pre-commit/pre-commit-hooks
52-
rev: v4.3.0
52+
rev: v4.5.0
5353
hooks:
5454
- id: check-builtin-literals
5555
exclude: ^babelizer/data
@@ -66,7 +66,7 @@ repos:
6666
- id: trailing-whitespace
6767

6868
- repo: https://github.com/PyCQA/pydocstyle
69-
rev: 6.1.1
69+
rev: 6.3.0
7070
hooks:
7171
- id: pydocstyle
7272
files: babelizer/.*\.py$
@@ -77,7 +77,7 @@ repos:
7777
additional_dependencies: [".[toml]"]
7878

7979
- repo: https://github.com/pre-commit/mirrors-mypy
80-
rev: v0.982
80+
rev: v1.8.0
8181
hooks:
8282
- id: mypy
8383
additional_dependencies: [types-all]

babelizer/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""The *babelizer*."""
2+
23
from ._version import __version__
34

45
__all__ = ["__version__"]

babelizer/cli.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
"""The command line interface to the babelizer."""
2+
23
import fnmatch
34
import os
45
import pathlib
6+
import sys
57
import tempfile
68
from functools import partial
79

810
import click
911
import git
10-
import pkg_resources
12+
13+
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
14+
import importlib.resources as importlib_resources
15+
else: # pragma: no cover (<PY312)
16+
import importlib_resources
17+
1118

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

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

141-
template = template or pkg_resources.resource_filename("babelizer", "data")
148+
template = template or str(importlib_resources.files("babelizer") / "data")
142149

143150
if not quiet:
144151
out(f"reading template from {template}")
@@ -359,9 +366,7 @@ def ask_until_done(text):
359366
}
360367

361368
libraries = {}
362-
if (not prompt) or any(
363-
[x is not None for x in (name, library, header, entry_point)]
364-
):
369+
if (not prompt) or any(x is not None for x in (name, library, header, entry_point)):
365370
babelized_class = name or ask("Name of babelized class", default="<name>")
366371
libraries[babelized_class] = {
367372
"language": language,
@@ -385,11 +390,13 @@ def ask_until_done(text):
385390
libraries[babelized_class] = {
386391
"language": language,
387392
"library": ask(f"[{babelized_class}] Name of library to babelize"),
388-
"header": ask(
389-
f"[{babelized_class}] Name of header file containing BMI class "
390-
)
391-
if language != "python"
392-
else "__UNUSED__",
393+
"header": (
394+
ask(
395+
f"[{babelized_class}] Name of header file containing BMI class "
396+
)
397+
if language != "python"
398+
else "__UNUSED__"
399+
),
393400
"entry_point": ask(f"[{babelized_class}] Name of BMI class "),
394401
}
395402
if not yes("Add another library?", default=False):

babelizer/data/{{cookiecutter.package_name}}/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["cython", "numpy", "setuptools<60", "wheel"]
2+
requires = ["cython", "numpy", "setuptools", "wheel"]
33

44
[tool.pytest.ini_options]
55
minversion = "5.0"

babelizer/data/{{cookiecutter.package_name}}/{{cookiecutter.package_name}}/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#! /usr/bin/env python
2-
import pkg_resources
2+
import importlib.metadata
33

4-
5-
__version__ = pkg_resources.get_distribution("{{ cookiecutter.package_name }}").version
4+
__version__ = importlib.metadata.version("{{ cookiecutter.package_name }}")
65

76

87
from .bmi import (

babelizer/data/{{cookiecutter.package_name}}/{{cookiecutter.package_name}}/bmi.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from .lib import {{ classes|join(', ') }}
1111

1212
{%- else %}
13-
import pkg_resources
13+
import sys
14+
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
15+
import importlib.resources as importlib_resources
16+
else: # pragma: no cover (<PY312)
17+
import importlib_resources
18+
1419

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

@@ -20,7 +25,7 @@
2025

2126
{%- for cls in classes %}
2227
{{ cls }}.__name__ = "{{ cls }}"
23-
{{ cls }}.METADATA = pkg_resources.resource_filename(__name__ , "data/{{ cls }}")
28+
{{ cls }}.METADATA = str(importlib_resources.files(__name__) / "data/{{ cls }}")
2429
{%- endfor %}
2530

2631
{%- endif %}

babelizer/metadata.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Library metadata used by the babelizer to wrap libraries."""
2+
23
import pathlib
34
import re
45
import warnings
@@ -142,7 +143,9 @@ def __init__(
142143
Information about how to set up continuous integration.
143144
"""
144145
if plugin is not None:
145-
warnings.warn("use 'package' instead of 'plugin'", DeprecationWarning)
146+
warnings.warn(
147+
"use 'package' instead of 'plugin'", DeprecationWarning, stacklevel=2
148+
)
146149
if package is not None:
147150
raise ValueError("specify one of 'package' or 'plugin', not both")
148151
package = plugin
@@ -295,7 +298,9 @@ def validate(config):
295298
),
296299
optional={},
297300
)
298-
warnings.warn("use 'package' instead of 'plugin'", DeprecationWarning)
301+
warnings.warn(
302+
"use 'package' instead of 'plugin'", DeprecationWarning, stacklevel=2
303+
)
299304

300305
@staticmethod
301306
def _handle_old_style_entry_points(library):

babelizer/render.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
"""Render a new babelized project."""
2+
23
import contextlib
34
import os
45
import pathlib
6+
import sys
57

68
import black as blk
79
import git
810
import isort
9-
import pkg_resources
1011
import tomlkit as toml
1112
from cookiecutter.exceptions import OutputDirExistsException
1213
from cookiecutter.main import cookiecutter
1314

15+
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
16+
import importlib.resources as importlib_resources
17+
else: # pragma: no cover (<PY312)
18+
import importlib_resources
19+
1420
from .errors import OutputDirExistsError, RenderError
1521

1622

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

4652
try:
4753
path = render_plugin_repo(

babelizer/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility functions used by the babelizer."""
2+
23
import pathlib
34
import subprocess
45
import sys

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pathlib
1313
import sys
1414

15-
import pkg_resources
15+
from babelizer._version import __version__
1616

1717
# -- Path setup --------------------------------------------------------------
1818

@@ -28,7 +28,7 @@
2828

2929
project = "babelizer"
3030
author = "Community Surface Dynamics Modeling System"
31-
version = pkg_resources.get_distribution("babelizer").version
31+
version = __version__
3232
release = version
3333
this_year = datetime.date.today().year
3434
copyright = f"{this_year}, {author}"

0 commit comments

Comments
 (0)