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

Deprecate python 3.8 support. #902

Merged
merged 26 commits into from
Jan 3, 2025
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
1 change: 0 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
# Empty string is the floating most recent version of python
# (useful to catch new compatibility issues in nightly builds)
- ""
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand Down
59 changes: 51 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ PYTHON_VERSION := $(shell echo "${CONDA_ENV_NAME}" | sed -r -e 's/^mlos[-]?//')
ENV_YML := conda-envs/${CONDA_ENV_NAME}.yml

# Find the non-build python files we should consider as rule dependencies.
PYTHON_FILES := $(shell find ./ -type f -name '*.py' 2>/dev/null | egrep -v -e '^./(mlos_(core|bench|viz)/)?build/' -e '^./doc/source/')
MLOS_CORE_PYTHON_FILES := $(shell find ./mlos_core/ -type f -name '*.py' 2>/dev/null | egrep -v -e '^./mlos_core/build/')
MLOS_BENCH_PYTHON_FILES := $(shell find ./mlos_bench/ -type f -name '*.py' 2>/dev/null | egrep -v -e '^./mlos_bench/build/')
MLOS_VIZ_PYTHON_FILES := $(shell find ./mlos_viz/ -type f -name '*.py' 2>/dev/null | egrep -v -e '^./mlos_viz/build/')
NOTEBOOK_FILES := $(shell find ./ -type f -name '*.ipynb' 2>/dev/null | egrep -v -e '/build/')
SCRIPT_FILES := $(shell find ./ -name '*.sh' -or -name '*.ps1' -or -name '*.cmd')
SQL_FILES := $(shell find ./ -name '*.sql')
MD_FILES := $(shell find ./ -name '*.md' | grep -v '^./doc/')
# Do a single find and multiple filters for better performance.
REPO_FILES := $(shell find . -type f 2>/dev/null | egrep -v -e '^./(mlos_(core|bench|viz)/)?build/' -e '^./doc/source/' -e '^./doc/build/')
PYTHON_FILES := $(filter %.py, $(REPO_FILES))
MLOS_CORE_PYTHON_FILES := $(filter ./mlos_core/%, $(PYTHON_FILES))
MLOS_BENCH_PYTHON_FILES := $(filter ./mlos_bench/%, $(PYTHON_FILES))
MLOS_VIZ_PYTHON_FILES := $(filter ./mlos_viz/%, $(PYTHON_FILES))
NOTEBOOK_FILES := $(filter %.ipynb, $(REPO_FILES))
SCRIPT_FILES := $(filter %.sh %.ps1 %.cmd, $(REPO_FILES))
SQL_FILES := $(filter %.sql, $(REPO_FILES))
MD_FILES := $(filter-out ./doc/%, $(filter %.md, $(REPO_FILES)))

DOCKER := $(shell which docker)
# Make sure the build directory exists.
Expand Down Expand Up @@ -70,6 +72,8 @@ ifneq (,$(filter format,$(MAKECMDGOALS)))
endif

build/format.${CONDA_ENV_NAME}.build-stamp: build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
# TODO: Disabled for now. Will enable and format in a future PR.
#build/format.${CONDA_ENV_NAME}.build-stamp: build/pyupgrade.${CONDA_ENV_NAME}.build-stamp
build/format.${CONDA_ENV_NAME}.build-stamp: build/isort.${CONDA_ENV_NAME}.build-stamp
build/format.${CONDA_ENV_NAME}.build-stamp: build/black.${CONDA_ENV_NAME}.build-stamp
build/format.${CONDA_ENV_NAME}.build-stamp: build/docformatter.${CONDA_ENV_NAME}.build-stamp
Expand All @@ -96,6 +100,35 @@ build/licenseheaders.${CONDA_ENV_NAME}.build-stamp:
-x mlos_bench/setup.py mlos_core/setup.py mlos_viz/setup.py
touch $@

.PHONY: pyupgrade
pyupgrade: build/pyupgrade.${CONDA_ENV_NAME}.build-stamp

ifneq (,$(filter pyupgrade,$(MAKECMDGOALS)))
FORMAT_PREREQS += build/pyupgrade.${CONDA_ENV_NAME}.build-stamp
endif

build/pyupgrade.${CONDA_ENV_NAME}.build-stamp: build/pyupgrade.mlos_core.${CONDA_ENV_NAME}.build-stamp
build/pyupgrade.${CONDA_ENV_NAME}.build-stamp: build/pyupgrade.mlos_bench.${CONDA_ENV_NAME}.build-stamp
build/pyupgrade.${CONDA_ENV_NAME}.build-stamp: build/pyupgrade.mlos_viz.${CONDA_ENV_NAME}.build-stamp
build/pyupgrade.${CONDA_ENV_NAME}.build-stamp:
touch $@

PYUPGRADE_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
PYUPGRADE_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
PYUPGRADE_COMMON_PREREQS += build/conda-env.${CONDA_ENV_NAME}.build-stamp
PYUPGRADE_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

build/pyupgrade.mlos_core.${CONDA_ENV_NAME}.build-stamp: $(MLOS_CORE_PYTHON_FILES)
build/pyupgrade.mlos_bench.${CONDA_ENV_NAME}.build-stamp: $(MLOS_BENCH_PYTHON_FILES)
build/pyupgrade.mlos_viz.${CONDA_ENV_NAME}.build-stamp: $(MLOS_VIZ_PYTHON_FILES)

build/pyupgrade.%.${CONDA_ENV_NAME}.build-stamp: $(PYUPGRADE_COMMON_PREREQS)
# Reformat python file imports with pyupgrade.
conda run -n ${CONDA_ENV_NAME} pyupgrade --py39-plus --exit-zero-even-if-changed $(filter %.py,$+)
touch $@

.PHONY: isort
isort: build/isort.${CONDA_ENV_NAME}.build-stamp

Expand All @@ -118,6 +151,9 @@ ISORT_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
ISORT_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format pyupgrade,$(MAKECMDGOALS)))
ISORT_COMMON_PREREQS += build/pyupgrade.${CONDA_ENV_NAME}.build-stamp
endif
ISORT_COMMON_PREREQS += build/conda-env.${CONDA_ENV_NAME}.build-stamp
ISORT_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

Expand Down Expand Up @@ -149,6 +185,9 @@ BLACK_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
BLACK_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format pyupgrade,$(MAKECMDGOALS)))
BLACK_COMMON_PREREQS += build/pyupgrade.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format isort,$(MAKECMDGOALS)))
BLACK_COMMON_PREREQS += build/isort.${CONDA_ENV_NAME}.build-stamp
endif
Expand Down Expand Up @@ -183,6 +222,9 @@ DOCFORMATTER_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
DOCFORMATTER_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format pyupgrade,$(MAKECMDGOALS)))
DOCFORMATTER_COMMON_PREREQS += build/pyupgrade.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format isort,$(MAKECMDGOALS)))
DOCFORMATTER_COMMON_PREREQS += build/isort.${CONDA_ENV_NAME}.build-stamp
endif
Expand Down Expand Up @@ -757,6 +799,7 @@ endif
.PHONY: nginx_port_env
nginx_port_env:
@echo "Starting nginx docker container for serving docs."
mkdir -p doc/build
./doc/nginx-docker.sh restart
nginx_port=`docker port mlos-doc-nginx | grep 0.0.0.0:8080 | cut -d/ -f1` \
&& echo nginx_port=$${nginx_port} > doc/build/nginx_port.env
Expand Down
47 changes: 0 additions & 47 deletions conda-envs/mlos-3.8.yml

This file was deleted.

3 changes: 2 additions & 1 deletion conda-envs/mlos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies:
# Basic dev environment packages.
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pyupgrade
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -29,6 +29,7 @@ dependencies:
- isort
- docformatter
- licenseheaders
- pylint
- mypy
- pandas-stubs
- types-beautifulsoup4
Expand Down
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def pytest_configure(config: pytest.Config) -> None:
(
"DISPLAY environment variable is set, "
"which can cause problems in some setups (e.g. WSL). "
f"Adjusting matplotlib backend to '{matplotlib.rcParams['backend']}' "
"Adjusting matplotlib backend to "
f"""'{matplotlib.rcParams["backend"]}' """
"to compensate."
)
)
Expand Down
20 changes: 16 additions & 4 deletions doc/copy-source-tree-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ for readme_file_path in README.md mlos_core/README.md mlos_bench/README.md mlos_

cp "$readme_file_path" "doc/source/source_tree_docs/$file_dir/index.md"

case "$OSTYPE" in
darwin*)
sed_args='-i ""'
;;
*gnu*)
sed_args='-i'
;;
default)
echo "Unsupported OS: $OSTYPE"
exit 1
;;
esac

# Tweak source source code links.
# FIXME: This sed expression doesn't work in MacOS.
sed -i -r -e "s|\]\(([^:#)]+)(#[a-zA-Z0-9_-]+)?\)|\]\(https://github.com/microsoft/MLOS/tree/main/$file_dir/\1\2\)|g" \
sed $sed_args -r -e "s|\]\(([^:#)]+)(#[a-zA-Z0-9_-]+)?\)|\]\(https://github.com/microsoft/MLOS/tree/main/$file_dir/\1\2\)|g" \
"doc/source/source_tree_docs/$file_dir/index.md"
# Tweak the lexers for local expansion by pygments instead of github's.
sed -i -r -e 's/```jsonc/```json/' \
sed $sed_args -r -e 's/```jsonc/```json/' \
"doc/source/source_tree_docs/$file_dir/index.md"
done

# Do an explicit fixup for some static content.
sed -i -r -e 's#="[^"]*(_static/[^"]+)"#="../\1"#g' \
sed $sed_args -r -e 's#="[^"]*(_static/[^"]+)"#="../\1"#g' \
"doc/source/source_tree_docs/index.md"
2 changes: 2 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def is_on_github_actions():
("T_co", "class"): "data",
("CoroReturnType", "class"): "data",
("FutureReturnType", "class"): "data",
("NullableT", "class"): "data",
}


Expand Down Expand Up @@ -209,6 +210,7 @@ def setup(app: SphinxApp) -> None:
# sphinx has a hard time finding typealiases and typevars instead of classes.
# See Also: https://github.com/sphinx-doc/sphinx/issues/10974
nitpick_ignore = [
("py:class", "Ellipsis"),
# Internal typevars and aliases:
("py:class", "EnvironType"),
# External typevars and aliases:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@


def _main(fname_input: str, fname_output: str) -> None:
with open(fname_input, "rt", encoding="utf-8") as fh_tunables, open(
fname_output, "wt", encoding="utf-8", newline=""
) as fh_config:
with (
open(fname_input, "rt", encoding="utf-8") as fh_tunables,
open(fname_output, "wt", encoding="utf-8", newline="") as fh_config,
):
for key, val in json.load(fh_tunables).items():
line = f"{key} {val}"
fh_config.write(line + "\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@


def _write_config() -> None:
with open(JSON_CONFIG_FILE, "r", encoding="UTF-8") as fh_json, open(
NEW_CFG, "w", encoding="UTF-8"
) as fh_config:
with (
open(JSON_CONFIG_FILE, "r", encoding="UTF-8") as fh_json,
open(NEW_CFG, "w", encoding="UTF-8") as fh_config,
):
for key, val in json.load(fh_json).items():
fh_config.write(
'GRUB_CMDLINE_LINUX_DEFAULT="$' f'{{GRUB_CMDLINE_LINUX_DEFAULT}} {key}={val}"\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@


def _main(fname_input: str, fname_output: str) -> None:
with open(fname_input, "rt", encoding="utf-8") as fh_tunables, open(
fname_output, "wt", encoding="utf-8", newline=""
) as fh_config:
with (
open(fname_input, "rt", encoding="utf-8") as fh_tunables,
open(fname_output, "wt", encoding="utf-8", newline="") as fh_config,
):
for key, val in json.load(fh_tunables).items():
line = f'GRUB_CMDLINE_LINUX_DEFAULT="${{GRUB_CMDLINE_LINUX_DEFAULT}} {key}={val}"'
fh_config.write(line + "\n")
Expand Down
7 changes: 2 additions & 5 deletions mlos_bench/mlos_bench/event_loop_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
CoroReturnType = TypeVar("CoroReturnType") # pylint: disable=invalid-name
"""Type variable for the return type of an :external:py:mod:`asyncio` coroutine."""

if sys.version_info >= (3, 9):
FutureReturnType: TypeAlias = Future[CoroReturnType]
"""Type variable for the return type of a :py:class:`~concurrent.futures.Future`."""
else:
FutureReturnType: TypeAlias = Future
FutureReturnType: TypeAlias = Future[CoroReturnType]
"""Type variable for the return type of a :py:class:`~concurrent.futures.Future`."""

_LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion mlos_bench/mlos_bench/os_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# pylint: disable=protected-access,disable=unsubscriptable-object
EnvironType: TypeAlias = os._Environ[str]
else:
EnvironType: TypeAlias = os._Environ # pylint: disable=protected-access
assert False, "Unsupported Python version."

# Handle case sensitivity differences between platforms.
# https://stackoverflow.com/a/19023293
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def test_load_cli_config_examples_via_launcher(
assert launcher.global_config["trial_id"] == config["trial_id"]

expected_log_level = logging.getLevelName(config.get("log_level", "INFO"))
if isinstance(expected_log_level, int):
expected_log_level = logging.getLevelName(expected_log_level)
if isinstance(expected_log_level, int): # type: ignore[unreachable]
expected_log_level = logging.getLevelName(expected_log_level) # type: ignore[unreachable]
current_log_level = logging.getLevelName(logging.root.getEffectiveLevel())
assert current_log_level == expected_log_level

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
"""Unit tests for configuration persistence service."""

import os
import sys
from importlib.resources import files

import pytest

from mlos_bench.config.schemas import ConfigSchema
from mlos_bench.services.config_persistence import ConfigPersistenceService
from mlos_bench.util import path_join

if sys.version_info < (3, 9):
from importlib_resources import files
else:
from importlib.resources import files


# pylint: disable=redefined-outer-name


Expand Down
Loading
Loading