Skip to content

Commit

Permalink
Pin Python version to 3.11.x
Browse files Browse the repository at this point in the history
## Why pin the Python version?

Because we _can_ put everybody on the same version.
This way,
we make it less likely different people will hit different issues.

## Why use Python 3.11?

It is well established,
binary wheels exist for it in PyPI,
it is available on UBI 8 and 9, and on Fedora starting with Fedora 37.

## Why say `python = ">=3.11.5, <3.12.0"`?

The syntax uses basic math instead of tildes and carets,
which not everybody might've learned what they mean.
That makes the requirement easier to read and understand.

Signed-off-by: Jiri Daněk <[email protected]>
  • Loading branch information
jiridanek committed Feb 13, 2024
1 parent 5b6d750 commit 65e8302
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 92 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ jobs:
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'poetry'

- name: Configure poetry
run: |
poetry env use "${{ steps.setup-python.outputs.python-path }}"
- run: poetry check --lock

- name: Install ruff
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/dry_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'poetry'

- name: Execute ods-ci dryrun
run: |
mv ods_ci/test-variables.yml.example ods_ci/test-variables.yml
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ and its upstream project, [Open Data Hub](https://opendatahub.io/).
# Requirements
1. Linux distribution that supports Selenium automation on top of either a Chromium/Google-Chrome web browser using [ChromeDriver](https://chromedriver.chromium.org) or Firefox web browser using [geckodriver](https://github.com/mozilla/geckodriver):
* relevant web driver binaries can be downloaded here: [ChromeDriver](https://googlechromelabs.github.io/chrome-for-testing) or [geckodriver](https://github.com/mozilla/geckodriver/releases)
* the `ChromeDriver` version must match the installed version of Chromium/Google-Chrome, for `geckodriver` see the release notes for paritcular release
* the `ChromeDriver` version must match the installed version of Chromium/Google-Chrome, for `geckodriver` see the release notes for particular release
* install your web driver so that it's visible by Robot Framework during tests execution, e.g. into `~/.local/bin` path

2. [Poetry](https://python-poetry.org/docs/#installation) tool installed and added to your `$PATH`.
Expand Down Expand Up @@ -53,7 +53,7 @@ and its upstream project, [Open Data Hub](https://opendatahub.io/).

* This run_robot_test.sh is a wrapper for creating the python virtual environment and running the Robot Framework CLI.
* The wrapper script has several arguments and you can find details in the dedicated document file. See [run_args.md](ods_ci/docs/RUN_ARGUMENTS.md)
* As alternative, you can run any of the test cases by creating the python virual environment, install the packages in [poetry.lock](poetry.lock) and running the `robot` command directly
* As alternative, you can run any of the test cases by creating the python virtual environment, install the packages in [poetry.lock](poetry.lock) and running the `robot` command directly


# Contributing
Expand Down
18 changes: 18 additions & 0 deletions ods_ci/run_robot_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ if command -v yq &> /dev/null
fi

if [[ ${SKIP_INSTALL} -eq 0 ]]; then
# look for pre-created poetry .venv
virtenv="${HOME}/.local/ods-ci/.venv"
if [[ -d "${virtenv}" ]]; then
echo "Using a pre-created virtual environment in '${virtenv}' for poetry to save time."
Expand All @@ -327,6 +328,23 @@ if [[ ${SKIP_INSTALL} -eq 0 ]]; then
else
echo "Pre-created virtual environment has not been found in '${virtenv}'. All dependencies will be installed from scratch."
fi
# ensure python 3.11
python=$(poetry env info --executable)
if [[ -n "${python}" ]] && ${python} -c 'import sys; sys.exit(0 if sys.version_info[0:2] == (3, 11) else 1)'; then
echo "Python '${python}' will be used"
else
echo "Python '${python}' is not of the correct version"
python311=$(which python3.11)
if [[ -n "${python311}" ]]; then
echo "Configuring poetry to use Python ${python311}"
poetry env use "${python311}"
else
echo "[ERROR] Python 3.11 was not found!"
echo "Install Python 3.11 on your machine. On Fedora, do 'sudo dnf install -y python3.11-devel'"
echo "then run 'poetry env use /path/to/python3.11' and then try running robot again"
exit 1
fi
fi

poetry --no-interaction install --sync
fi
Expand Down
14 changes: 7 additions & 7 deletions ods_ci/utils/scripts/Sender/EmailSender.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from os.path import basename
from typing import Any, List, Optional
from typing import Any

from Sender import Sender

Expand All @@ -24,16 +24,16 @@ def __init__(self):
self._message = MIMEMultipart()

def prepare_payload(
self, text: str = "", attachments: Optional[List[Any]] = None
self, text: str = "", attachments: list[Any] | None = None
) -> None:
self._message.attach(MIMEText(text))
if attachments is not None:
for filepath in attachments:
with open(filepath, "rb") as file:
part = MIMEApplication(file.read(), Name=basename(filepath))
part[
"Content-Disposition"
] = 'attachment; filename="%s"' % basename(filepath)
part["Content-Disposition"] = (
'attachment; filename="%s"' % basename(filepath)
)
self._message.attach(part)

def prepare_header(self):
Expand Down Expand Up @@ -67,10 +67,10 @@ def set_sender_address(self, sender_address: str) -> None:
def get_sender_address(self) -> str:
return self._sender_address

def set_receiver_addresses(self, receiver_addresses: List) -> None:
def set_receiver_addresses(self, receiver_addresses: list) -> None:
self._receiver_addresses = receiver_addresses

def get_receiver_addresses(self) -> List:
def get_receiver_addresses(self) -> list:
return self._receiver_addresses

def set_subject(self, subject: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions ods_ci/utils/scripts/Sender/Sender.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from abc import ABC, abstractmethod
from typing import Any, List, Optional
from typing import Any


class Sender(ABC):
@abstractmethod
def prepare_payload(
self, text: str = "", attachments: Optional[List[Any]] = None
self, text: str = "", attachments: list[Any] | None = None
) -> None:
pass

Expand Down
80 changes: 2 additions & 78 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ authors = ["RHODS QE <[email protected]>"]
readme = "README.md"
packages = [{include = "ods_ci"}]

# https://python-poetry.org/docs/dependency-specification
[tool.poetry.dependencies]
python = "^3.8.1"
python = ">=3.11.5, <3.12.0"
reportportal-client = "^5.2.5"
robotframework = "^6"
robotframework-debuglibrary = ">=2.0.0"
Expand Down Expand Up @@ -47,7 +48,7 @@ profile = "black"
line_length = 88 # align with black's default

[tool.ruff]
target-version = "py38"
target-version = "py311"
line-length = 88 # align with black's default

# https://docs.astral.sh/ruff/rules
Expand Down

0 comments on commit 65e8302

Please sign in to comment.