Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update supported Python versions #334

Merged
merged 16 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- published

env:
MINIMUM_PYTHON_VERSION: "3.7"
MINIMUM_PYTHON_VERSION: "3.8"

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- uses: actions/checkout@v3
Expand All @@ -36,29 +36,25 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Tox and any other packages
run: |
python -m pip install --upgrade pip
python -m pip install tox-gh-actions poetry
- name: Run quick tests (Not Python ${{ env.MINIMUM_PYTHON_VERSION }})
if: ${{ matrix.python-version != env.MINIMUM_PYTHON_VERSION }}
run: tox -- -m "not slow"
- name: Run all tests (Python ${{ env.MINIMUM_PYTHON_VERSION }} only)
if: ${{ matrix.python-version == env.MINIMUM_PYTHON_VERSION }}
- name: Run all tests
run: tox

docs:
runs-on: ubuntu-latest
steps:
- name: Install Python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- uses: actions/checkout@v3
Expand All @@ -81,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ ENV/

# Poetry
poetry.lock

# vscode
.vscode/
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v3.3.1
hooks:
- id: pyupgrade
language: python
args: [--py37-plus]
args: [--py38-plus]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
language: python
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
language: python
Expand All @@ -35,8 +35,6 @@ repos:
- mccabe
- yesqa
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.931'
rev: 'v1.0.1'
hooks:
- id: mypy
additional_dependencies:
- types-setuptools # Required for versioning on py37
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# History

## 0.3.2 (UNRELEASED)

- Removed support for Python 3.7
- Added support for Python 3.10 and Python 3.11

## 0.3.1 (2022-01-24)

- Added parameters to docker run commands to better reflect how
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ containers for grand-challenge.org.

## Getting Started

[evalutils](https://github.com/comic/evalutils) requires Python 3.7 or
[evalutils](https://github.com/comic/evalutils) requires Python 3.8 or
above, and can be installed from `pip`.
Please see the [Getting Started](https://comic.github.io/evalutils/usage.html)
documentation for more details.
11 changes: 2 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@
#
import os
import sys
from importlib.metadata import version as _get_version
from typing import Dict, List

try:
from importlib.metadata import version

evalutils_version = version("evalutils")
except ImportError:
# py <= py37
from pkg_resources import get_distribution

evalutils_version = get_distribution("evalutils").version
evalutils_version = _get_version("evalutils")

sys.path.insert(0, os.path.abspath(".."))

Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python 3.7, 3.8 and 3.9. Check
3. The pull request should work for Python 3.8, 3.9, 3.10 and 3.11. Check
https://travis-ci.org/comic/evalutils/pull_requests
and make sure that the tests pass for all supported Python versions.

Expand Down
10 changes: 0 additions & 10 deletions docs/environment.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The different challenge types that you can select are:
For this sort of challenge, you may have many candidate points and many ground truth points per case.
By default, the results per case are also reported.

If you do not have a local python 3.7+ environment you can also
If you do not have a local python 3.8+ environment you can also
generate your project with docker by running a container and sharing your current user id:

.. code-block:: console
Expand Down Expand Up @@ -396,7 +396,7 @@ The different algorithm types that you can select are:
For instance, this evaluation could be used for detection of tumours in images.
By default, the algorithm outputs a single `/output/results.json` which lists the results per case.

If you do not have a local python 3.7+ environment you can also
If you do not have a local python 3.8+ environment you can also
generate your project with docker by running a container and sharing your current user id:

.. code-block:: console
Expand Down
18 changes: 8 additions & 10 deletions evalutils/cli.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import re
import sys
from importlib.metadata import version
from pathlib import Path
from typing import List

import click
from cookiecutter.exceptions import FailedHookException
from cookiecutter.main import cookiecutter

try:
from importlib.metadata import version

evalutils_version = version("evalutils")
except ImportError:
# py <= py37
from pkg_resources import get_distribution

evalutils_version = get_distribution("evalutils").version
evalutils_version = version("evalutils")

EVALUATION_CHOICES = ["Classification", "Segmentation", "Detection"]
ALGORITHM_CHOICES = EVALUATION_CHOICES
Expand All @@ -40,7 +34,7 @@ def validate_python_module_name_string(ctx, param, arg):
exit(1)

if not re.match(MODULE_REGEX, arg) or arg in FORBIDDEN_NAMES:
click.echo(f"ERROR: '{arg}' is not a valid Python module name!")
click.echo(f"ERROR: {arg!r} is not a valid Python module name!")
exit(1)

return arg
Expand Down Expand Up @@ -96,6 +90,8 @@ def init_evaluation(challenge_name, kind, dev):
"evalutils_version": evalutils_version,
"challenge_kind": kind,
"dev_build": 1 if dev else 0,
"python_major_version": sys.version_info.major,
"python_minor_version": sys.version_info.minor,
},
)
click.echo(f"Created project {challenge_name}")
Expand Down Expand Up @@ -186,6 +182,8 @@ def init_algorithm(algorithm_name, kind, dev):
"evalutils_name": __name__.split(".")[0],
"evalutils_version": evalutils_version,
"dev_build": 1 if dev else 0,
"python_major_version": sys.version_info.major,
"python_minor_version": sys.version_info.minor,
},
)
click.echo(f"Created project {algorithm_name}")
Expand Down
8 changes: 4 additions & 4 deletions evalutils/evalutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _load_cases(
*,
folder: Path,
file_loader: ImageLoader,
file_filter: Pattern[str] = None,
file_filter: Optional[Pattern[str]] = None,
) -> DataFrame:
cases = None

Expand Down Expand Up @@ -183,7 +183,7 @@ def process(self):
self.process_cases()
self.save()

def process_cases(self, file_loader_key: str = None):
def process_cases(self, file_loader_key: Optional[str] = None):
if file_loader_key is None:
file_loader_key = self._index_key
self._case_results = []
Expand Down Expand Up @@ -329,8 +329,8 @@ def __init__(
file_sorter_key: Callable = first_int_in_filename_key,
file_loader: FileLoader,
validators: Tuple[DataFrameValidator, ...],
join_key: str = None,
aggregates: Set[str] = None,
join_key: Optional[str] = None,
aggregates: Optional[Set[str]] = None,
output_file: PathLike = DEFAULT_EVALUATION_OUTPUT_FILE_PATH,
):
"""
Expand Down
2 changes: 1 addition & 1 deletion evalutils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def first_int_in_filename_key(fname: Path) -> str:
try:
return f"{get_first_int_in(fname.stem):>64}"
except AttributeError:
logger.warning(f"Could not find an int in the string '{fname.stem}'.")
logger.warning(f"Could not find an int in the string {fname.stem!r}.")
return fname.stem


Expand Down
6 changes: 2 additions & 4 deletions evalutils/templates/algorithm/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"package_name": "{{ cookiecutter.algorithm_name|replace(' ', '') }}",
"evalutils_name": "",
"evalutils_version": "",
"docker_base_container": "python:3.9-slim",
"dev_build": 0,
"_copy_without_render": [
"*.github"
]
"python_major_version": "",
"python_minor_version": ""
}
2 changes: 1 addition & 1 deletion evalutils/templates/algorithm/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
package_name = "{{ cookiecutter.package_name }}"

if not re.match(MODULE_REGEX, package_name) or package_name in FORBIDDEN_NAMES:
print(f"ERROR: '{package_name}' is not a valid Python module name!")
print(f"ERROR: {package_name!r} is not a valid Python module name!")
exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: CI
on: [push, pull_request]

env:
PYTHON_VERSION: '3.9'
PYTHON_VERSION: '{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}'

jobs:

algorithm-tests:
runs-on: ubuntu-latest
steps:
- name: Install Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
- name: Install Python ${{ "{{" }} env.PYTHON_VERSION {{ "}}" }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ "{{" }} env.PYTHON_VERSION {{ "}}" }}
- uses: actions/checkout@v3
- name: Build the containers
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM {{ cookiecutter.docker_base_container }}
FROM python:{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}-slim

{% if cookiecutter.dev_build|int -%}
RUN apt-get update && apt-get install -y git
Expand Down Expand Up @@ -28,4 +28,4 @@ RUN python -m pip install --user -rrequirements.txt

COPY --chown=algorithm:algorithm process.py /opt/algorithm/

ENTRYPOINT python -m process $0 $@
ENTRYPOINT [ "python", "-m", "process" ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% if not cookiecutter.dev_build|int %}
{{ cookiecutter.evalutils_name }}=={{ cookiecutter.evalutils_version }}
{% endif %}
scikit-learn==0.24.2
scipy==1.6.3
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ docker run --rm \

docker run --rm \
-v {{ cookiecutter.package_name|lower }}-output-$VOLUME_SUFFIX:/output/ \
{{ cookiecutter.docker_base_container }} cat /output/results.json | python -m json.tool
python:{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}-slim cat /output/results.json | python -m json.tool

docker run --rm \
-v {{ cookiecutter.package_name|lower }}-output-$VOLUME_SUFFIX:/output/ \
-v $SCRIPTPATH/test/:/input/ \
{{ cookiecutter.docker_base_container }} python -c "import json, sys; f1 = json.load(open('/output/results.json')); f2 = json.load(open('/input/expected_output.json')); sys.exit(f1 != f2);"
python:{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}-slim python -c "import json, sys; f1 = json.load(open('/output/results.json')); f2 = json.load(open('/input/expected_output.json')); sys.exit(f1 != f2);"

if [ $? -eq 0 ]; then
echo "Tests successfully passed..."
Expand Down
6 changes: 2 additions & 4 deletions evalutils/templates/evaluation/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
],
"evalutils_name": "",
"evalutils_version": "",
"docker_base_container": "python:3.9-slim",
"dev_build": 0,
"_copy_without_render": [
"*.github"
]
"python_major_version": "",
"python_minor_version": ""
}
2 changes: 1 addition & 1 deletion evalutils/templates/evaluation/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
package_name = "{{ cookiecutter.package_name }}"

if not re.match(MODULE_REGEX, package_name) or package_name in FORBIDDEN_NAMES:
print(f"ERROR: '{package_name}' is not a valid Python module name!")
print(f"ERROR: {package_name!r} is not a valid Python module name!")
exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: CI
on: [push, pull_request]

env:
PYTHON_VERSION: '3.9'
PYTHON_VERSION: '{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}'

jobs:

evaluation-tests:
runs-on: ubuntu-latest
steps:
- name: Install Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
- name: Install Python ${{ "{{" }} env.PYTHON_VERSION {{ "}}" }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ "{{" }} env.PYTHON_VERSION {{ "}}" }}
- uses: actions/checkout@v3
- name: Build the containers
run: |
Expand Down
Loading