Skip to content

Commit

Permalink
Reimplement strtobool for Python 3.12 compatibility (SVRENG-267) (#68)
Browse files Browse the repository at this point in the history
* Reimplement strtobool for Python 3.12 compatibility

`distutils` was removed in Python 3.12, which means `distutils.util.strtobool` got
removed along with it. The guidance from PEP-632--which laid the foundation to
deprecate `distutils`--was to reimplement the `strtobool` (or other functions not
directly addressed by the text of the PEP.

This PR does just that, using CPython 3.11's `distutils` as a reference, and uses
the implementation of `strtobool` along with its test to form the basis for the
function within a utility module.

Additionally, this PR:
- Adds Ruff import ordering. This was missed from #66, since the isort-like behavior
is only enabled if the `I` set of rules is enabled; here, we simply extend the
default set via `lint.extend-select`.
- Adds `pytest` as a dev dependency, and adds pytest into the Makefile and GitHub
Actions workflows as appropriate.

Finally, the version is bumped to 0.8.16, so we can have a clear marker of which
version supports Python 3.12. That said, 0.8.15 is still compatible on CLI workers
with boardwalkd running 0.8.16.

Resolves #67.

Backblaze internal tracking: SVRENG-267

* Correct the checklist item relating to version string updates.

The VERSION file is no longer used.
  • Loading branch information
asullivan-blze authored Apr 3, 2024
1 parent 1eb9040 commit e8054f5
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
## How was this tested?

## Checklist
- [ ] Have you updated the VERSION file (if applicable)?
- [ ] Have you updated the `version` in the `[tool.poetry]` section of
the `pyproject.toml` file (if applicable)?
5 changes: 4 additions & 1 deletion .github/workflows/make-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ jobs:
# - run: poetry add ansible --no-interaction

#----------------------------------------------
# run test suite
# run test suites
#----------------------------------------------
# Run pytest
- run: make test-pytest

# Check code formatting and import sorting
- run: make test-ruff

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
__pycache__/
.pytest_cache/
.ruff_cache/
.boardwalk/
.boardwalkd/
.DS_store
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ clean:
src/boardwalkd/__pycache__ \
.boardwalk \
.boardwalkd \
.pytest_cache \
.ruff_cache \
|| :
podman image rm localhost/boardwalk || :
podman image rm $$(podman images 'localhost/boardwalk' --quiet) || :

# Installs modules in editable mode
.PHONY: develop
Expand Down Expand Up @@ -68,7 +70,12 @@ install-web-deps:

# Runs all available tests
.PHONY: test
test: test-ruff test-pyright test-semgrep
test: test-pytest test-ruff test-pyright test-semgrep

# Run pytest
.PHONY: test-pytest
test-pytest: develop
poetry run pytest

# Run all available Ruff checks
.PHONY: test-ruff
Expand Down
106 changes: 77 additions & 29 deletions poetry.lock

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

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "boardwalk"
version = "0.8.15"
version = "0.8.16"
description = "Boardwalk is a linear Ansible workflow engine"
readme = "README.md"
authors = [
Expand Down Expand Up @@ -46,6 +46,7 @@ tornado = ">=6.2"
pyright = "==1.1.350"
semgrep = ">=1.66.0"
ruff = "^0.3.4"
pytest = "^8.1.1"

[tool.poetry.scripts]
boardwalk = "boardwalk.cli:cli"
Expand All @@ -55,6 +56,9 @@ boardwalkd = "boardwalkd.cli:cli"
extend-exclude = [
"typings/*",
]
lint.extend-select = [
"I",
]

[tool.pyright]
exclude = [
Expand Down
15 changes: 13 additions & 2 deletions src/boardwalk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@

from .manifest import (
Job as Job,
path as path,
)
from .manifest import (
Workflow as Workflow,
)
from .manifest import (
WorkflowConfig as WorkflowConfig,
)
from .manifest import (
Workspace as Workspace,
)
from .manifest import (
WorkspaceConfig as WorkspaceConfig,
)
from .manifest import (
path as path,
)
from .state import RemoteStateModel as RemoteStateModel


if TYPE_CHECKING:
from boardwalk.ansible import (
AnsibleTasksType as AnsibleTasksType,
)
from boardwalk.ansible import (
InventoryHostVars as InventoryHostVars,
)
7 changes: 3 additions & 4 deletions src/boardwalk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
import os
import signal
import sys
from distutils.util import strtobool
from importlib.metadata import version as lib_version
from typing import Literal, TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

import click

from boardwalk.app_exceptions import BoardwalkException

from boardwalk.cli_catch import catch, release
from boardwalk.cli_init import init
from boardwalk.cli_login import login
from boardwalk.cli_run import check, run
from boardwalk.cli_workspace import workspace
from boardwalk.manifest import (
get_ws,
ManifestNotFound,
NoActiveWorkspace,
WorkspaceNotFound,
get_ws,
)
from boardwalk.utils import strtobool

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion src/boardwalk/cli_catch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import click

from boardwalk.app_exceptions import BoardwalkException
from boardwalk.manifest import get_ws, NoActiveWorkspace
from boardwalk.manifest import NoActiveWorkspace, get_ws

logger = logging.getLogger(__name__)

Expand Down
5 changes: 2 additions & 3 deletions src/boardwalk/cli_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
from __future__ import annotations

import logging

from pathlib import Path
from typing import TYPE_CHECKING, TypedDict

import click

from boardwalk.ansible import (
ansible_runner_run_tasks,
AnsibleRunError,
AnsibleRunnerFailedHost,
AnsibleRunnerGeneralError,
AnsibleRunnerUnreachableHost,
ansible_runner_run_tasks,
)
from boardwalk.app_exceptions import BoardwalkException
from boardwalk.host import Host
from boardwalk.manifest import get_ws, NoActiveWorkspace, Workspace
from boardwalk.manifest import NoActiveWorkspace, Workspace, get_ws

if TYPE_CHECKING:
from ansible_runner import RunnerEvent
Expand Down
8 changes: 4 additions & 4 deletions src/boardwalk/cli_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import socket
import sys
import time
from distutils.util import strtobool
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -29,18 +28,19 @@
from tornado.simple_httpclient import HTTPTimeoutError

from boardwalk.ansible import (
ansible_inventory,
ansible_runner_errors_to_output,
AnsibleRunError,
AnsibleRunnerBaseException,
AnsibleRunnerFailedHost,
AnsibleRunnerGeneralError,
AnsibleRunnerUnreachableHost,
ansible_inventory,
ansible_runner_errors_to_output,
)
from boardwalk.app_exceptions import BoardwalkException
from boardwalk.host import Host, RemoteHostLocked
from boardwalk.manifest import get_boardwalkd_url, get_ws, NoActiveWorkspace, Workspace
from boardwalk.manifest import NoActiveWorkspace, Workspace, get_boardwalkd_url, get_ws
from boardwalk.state import RemoteStateModel, RemoteStateWorkflow, RemoteStateWorkspace
from boardwalk.utils import strtobool

if TYPE_CHECKING:
from typing import ItemsView
Expand Down
2 changes: 1 addition & 1 deletion src/boardwalk/cli_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import click

from boardwalk.app_exceptions import BoardwalkException
from boardwalk.manifest import get_ws, NoActiveWorkspace, Workspace, WorkspaceNotFound
from boardwalk.manifest import NoActiveWorkspace, Workspace, WorkspaceNotFound, get_ws

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/boardwalk/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket
from base64 import b64decode
from datetime import datetime
from typing import Any, TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from pydantic import BaseModel, Extra

Expand Down
Loading

0 comments on commit e8054f5

Please sign in to comment.