From 9954f067d645315a0dab6be764a6447a34ee53e0 Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Thu, 11 Jan 2024 15:14:48 -0500 Subject: [PATCH] Add py312 support to template and drop pdm testing pdm cannot resolve different dependency versions for different python versions, and there is no numpy version that can be simultaneously resolved both to python 3.8 and python 3.12. So the only way to use support pdm would be to raise the lower limit of our template app, or have special pdm support. Users can still use pdm if they wish, but they'll have to work out the consequences themselves. pdm is removed from printed instructions and testing --- pyproject.toml | 80 +++++++++---------- snakebids/project_template/copier.yaml | 38 +++------ ...'poetry' %}pyproject.toml{% endif %}.jinja | 4 - ...'poetry' %}pyproject.toml{% endif %}.jinja | 4 + snakebids/tests/test_template.py | 2 +- 5 files changed, 54 insertions(+), 74 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5a7fdcb5..bec94a84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,9 +23,7 @@ style = "pep440" bump = true [tool.poetry-dynamic-versioning.substitution] -files = [ - 'snakebids/__init__.py', -] +files = ['snakebids/__init__.py'] patterns = [ "(^\\s+\"snakebids_version\":\\s*\")[^'\"]*(\")", "(^__version__\\s*(?::.*?)?=\\s*['\"])[^'\"]*(['\"])", @@ -66,7 +64,6 @@ scipy = [ pandas = [ { version = "<=2.0.3", python = "<3.9" }, { version = ">=2.1.1", python = ">=3.12" }, - ] # minimum 8.2.0 to use post-copy mesages copier = ">=8.2.0" @@ -132,8 +129,8 @@ expr = "platform.python_version()" args = [{ name = "container_id", positional = true, required = true }] uses = { VERSION = "_get_version" } cmd = """ - docker build 'containers/${container_id}' \ - --tag 'snakebids/${container_id}:${VERSION}' \ + docker build "containers/${container_id}" \ + --tag "snakebids/${container_id}:${VERSION}" \ --build-arg="PYTHON_VERSION=${VERSION}" """ @@ -143,10 +140,7 @@ markers = [ ] [tool.coverage.run] -omit = [ - "snakebids/project_template/**", - "snakebids/tests/**", -] +omit = ["snakebids/project_template/**", "snakebids/tests/**"] [tool.coverage.report] exclude_lines = [ @@ -154,7 +148,7 @@ exclude_lines = [ "@overload", 'class [a-zA-Z0-9_]+\([^)]*Protocol.*\)', 'if TYPE_CHECKING', - "def __dir__" + "def __dir__", ] [tool.isort] @@ -170,31 +164,31 @@ reportImportCycles = false [tool.ruff] select = [ - "E", # pycodestyle error - "W", # pycodestyle warning - "F", # pyflakes - "N", # pep8-naming - "UP", # pyupgrade - "YTT", # flake8-2020 - "S", # flake8-bandit - "BLE", # flake8-blind-except - "B", # flake8-bugbear - "A", # flake8-builtins - "COM", # flake8-commas - "C4", # flake8-comprehensions - "T10", # flake8-debugger - "EM", # flake8-errmsg - "FA", # flake8-future-annotations - "ISC", # flake8-implicit-str-concat - "ICN", # flake8-import-conventions - "G", # flake8-logging-format - "INP", # flake8-no-pep420 - "PIE", # flake8-pie - "PT", # flake8-pytest-style - "RSE", # flake8-raise - "RET", # flake8-return - "SLF", # flake8-self - "SIM", # flake8-simplify + "E", # pycodestyle error + "W", # pycodestyle warning + "F", # pyflakes + "N", # pep8-naming + "UP", # pyupgrade + "YTT", # flake8-2020 + "S", # flake8-bandit + "BLE", # flake8-blind-except + "B", # flake8-bugbear + "A", # flake8-builtins + "COM", # flake8-commas + "C4", # flake8-comprehensions + "T10", # flake8-debugger + "EM", # flake8-errmsg + "FA", # flake8-future-annotations + "ISC", # flake8-implicit-str-concat + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "INP", # flake8-no-pep420 + "PIE", # flake8-pie + "PT", # flake8-pytest-style + "RSE", # flake8-raise + "RET", # flake8-return + "SLF", # flake8-self + "SIM", # flake8-simplify # We use os.path a lot in "legitimate" ways, so this ruleset has too many # false positives # "PTH", # flake8-use-pathlib @@ -210,11 +204,11 @@ select = [ ] ignore = [ "PLR0913", - "D105", # missing docstring in magic method - "D100", # Require docstring in public modules - "D104", # Require docstring in public packages - "S603", # Subprocess without shell equals true - "S607", # start-process-with-partial-path + "D105", # missing docstring in magic method + "D100", # Require docstring in public modules + "D104", # Require docstring in public packages + "S603", # Subprocess without shell equals true + "S607", # start-process-with-partial-path # recommended ignores for ruff format "W191", "E111", @@ -241,8 +235,8 @@ namespace-packages = ["snakebids/plugins"] "snakebids/project_template/**" = ["N999"] "snakebids/tests/**" = [ "D", - "S101", # assert - "S307", # Use of eval + "S101", # assert + "S307", # Use of eval "SLF", ] diff --git a/snakebids/project_template/copier.yaml b/snakebids/project_template/copier.yaml index 3bb226ef..084f44de 100644 --- a/snakebids/project_template/copier.yaml +++ b/snakebids/project_template/copier.yaml @@ -65,7 +65,7 @@ bids_version: when: false python_version: - default: ">=3.8,<3.12" + default: ">=3.8,<3.13" when: false snakebids_version: @@ -96,27 +96,16 @@ _message_after_copy: > $ cd {{ _copier_conf.dst_path }} - {% if build_system == "poetry" -%} {{ Fore.BLUE }}2.{{ Fore.RESET }} Install dependencies. + {% if build_system == "poetry" %} $ poetry install - - {%- else -%} - {{ Fore.BLUE + "2." + Fore.RESET + """ Install dependencies. This may vary - depending on your tooling. The following are examples (the first example - should work on any python environment; the others require 3rd party tools): - """ | wordwrap(80)}} - - * {{Fore.YELLOW}}Virtual Environment and setuptools:{{Fore.RESET}} - $ python -m venv .venv - $ source .venv/bin/activate - $ pip install . - - * {{Fore.YELLOW}}Hatch:{{Fore.RESET}} - $ hatch env create - - * {{Fore.YELLOW}}PDM:{{Fore.RESET}} - $ pdm install + {%- elif build_system == "hatch" %} + $ hatch env create + {%- else %} + $ python -m venv .venv + $ source .venv/bin/activate + $ pip install . {%- endif %} @@ -125,15 +114,12 @@ _message_after_copy: > {% if build_system == "poetry" %} $ poetry run {{ test_run_cmd }} - {%- else %} - * {{Fore.YELLOW}}Virtual Environment and setuptools:{{Fore.RESET}} - $ {{ test_run_cmd }} + {%- elif build_system == "hatch" %} + $ hatch env run -- {{ test_run_cmd }} - * {{Fore.YELLOW}}Hatch:{{Fore.RESET}} - $ hatch env run -- {{ test_run_cmd }} + {%- else %} + $ {{ test_run_cmd }} - * {{Fore.YELLOW}}PDM:{{Fore.RESET}} - $ pdm run {{ test_run_cmd }} {%- endif %} _jinja_extensions: diff --git a/snakebids/project_template/{% if build_system != 'poetry' %}pyproject.toml{% endif %}.jinja b/snakebids/project_template/{% if build_system != 'poetry' %}pyproject.toml{% endif %}.jinja index b372fb96..daaf5c65 100644 --- a/snakebids/project_template/{% if build_system != 'poetry' %}pyproject.toml{% endif %}.jinja +++ b/snakebids/project_template/{% if build_system != 'poetry' %}pyproject.toml{% endif %}.jinja @@ -30,10 +30,6 @@ requires-python = "{{ python_version }}" dependencies = [ "snakemake >= {{ snakemake_version }},<8", "snakebids >= {{ snakebids_version }}", - {# Explicitly specify numpy version for py38 until snakebids 0.10.x to - work around specification bug causing numpys too high for py38 to be - locked by pdm -#} - "numpy <=1.24.4; python_version < \"3.9\"", ] [project.scripts] diff --git a/snakebids/project_template/{% if build_system == 'poetry' %}pyproject.toml{% endif %}.jinja b/snakebids/project_template/{% if build_system == 'poetry' %}pyproject.toml{% endif %}.jinja index 9d9840f5..4b2a37fd 100644 --- a/snakebids/project_template/{% if build_system == 'poetry' %}pyproject.toml{% endif %}.jinja +++ b/snakebids/project_template/{% if build_system == 'poetry' %}pyproject.toml{% endif %}.jinja @@ -24,6 +24,10 @@ classifiers = [ python = "{{ python_version }}" snakemake = ">={{ snakemake_version }},<8" snakebids = ">={{ snakebids_version }}" +pandas = [ + { version = "<=2.0.3", python = "<3.9" }, + { version = ">=2.1.1", python = ">=3.12" }, +] [tool.poetry.scripts] {{ name_slug }} = "{{ name_slug }}.run:main" diff --git a/snakebids/tests/test_template.py b/snakebids/tests/test_template.py index 534e0918..0ca33f23 100644 --- a/snakebids/tests/test_template.py +++ b/snakebids/tests/test_template.py @@ -270,7 +270,7 @@ def test_pyproject_correctly_formatted( ("setuptools", "setuptools"), ("poetry", "poetry"), ("hatch", "hatch"), - ("flit", "pdm"), + ("flit", "setuptools"), ], ) def test_template_dry_runs_successfully(tmp_path: Path, build: BuildBackend, venv: str):