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

chore: support Python 3.12 #418

Merged
merged 3 commits into from
Jul 24, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
- name: Install tools
run: pip install flake8 black isort wheel docstring-parser
- name: Lint
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
name: Tests on Python ${{ matrix.python-version }}
steps:
- name: Set up python
Expand Down
1 change: 1 addition & 0 deletions changes/418.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.12 support
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
license = { file = "LICENSE" }
authors = [{ name = "Owkin, Inc." }]
Expand Down
2 changes: 1 addition & 1 deletion substra/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.53.0"
__version__ = "0.54.0a1"
16 changes: 14 additions & 2 deletions substra/sdk/backends/local/compute/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def _get_cmd_template_inputs_outputs(
]
return command_template

def _tmp_is_three_nine(self):
"""Temporary helper function to remove as soon as support of Python 3.9 is dropped."""
import platform

return platform.python_version_tuple()[1] == "9"

Comment on lines +138 to +143
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have this in a Linear card or something to remember that we can get rid of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the dopr-Python3.9 card

def _prepare_artifact_input(self, task_input, task_key, input_volume, multiple):
outputs = self._db.list(
schemas.Type.OutputAsset,
Expand All @@ -150,15 +156,21 @@ def _prepare_artifact_input(self, task_input, task_key, input_volume, multiple):
assert output.kind == schemas.AssetKind.model, "The task_input value must be an artifact, not a performance"
filename = _generate_filename()
path_to_input = input_volume / filename
Path(output.asset.address.storage_address).link_to(path_to_input)
if self._tmp_is_three_nine():
Path(output.asset.address.storage_address).link_to(path_to_input)
else:
Path(path_to_input).hardlink_to(output.asset.address.storage_address)

return TaskResource(id=task_input.identifier, value=f"{TPL_VOLUME_INPUTS}/{filename}", multiple=multiple)

def _prepare_dataset_input(
self, dataset: models.Dataset, task_input: models.InputRef, input_volume: str, multiple: bool
):
path_to_opener = input_volume / Filenames.OPENER.value
Path(dataset.opener.storage_address).link_to(path_to_opener)
if self._tmp_is_three_nine():
Path(dataset.opener.storage_address).link_to(path_to_opener)
else:
Path(path_to_opener).hardlink_to(dataset.opener.storage_address)
return TaskResource(
id=task_input.identifier,
value=f"{TPL_VOLUME_INPUTS}/{Filenames.OPENER.value}",
Expand Down
8 changes: 4 additions & 4 deletions tests/data_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

DEFAULT_DATA_SAMPLE_FILENAME = "data.csv"

DEFAULT_SUBSTRATOOLS_VERSION = (
f"latest-nvidiacuda11.8.0-base-ubuntu22.04-python{sys.version_info.major}.{sys.version_info.minor}"
)
DEFAULT_SUBSTRATOOLS_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}-slim"

DEFAULT_SUBSTRATOOLS_DOCKER_IMAGE = f"ghcr.io/substra/substra-tools:{DEFAULT_SUBSTRATOOLS_VERSION}"
DEFAULT_SUBSTRATOOLS_DOCKER_IMAGE = f"python:{DEFAULT_SUBSTRATOOLS_VERSION}"

DEFAULT_OPENER_SCRIPT = f"""
import csv
Expand Down Expand Up @@ -246,6 +244,8 @@ def _save_predictions(y_pred, path):
DEFAULT_FUNCTION_DOCKERFILE = f"""
FROM {DEFAULT_SUBSTRATOOLS_DOCKER_IMAGE}
COPY function.py .
RUN apt-get update && apt-get install -y git
RUN python3 -m pip install git+https://github.com/Substra/substra-tools.git@main
ENTRYPOINT ["python3", "function.py", "--function-name", "{{function_name}}"]
"""

Expand Down
Loading