Skip to content

Commit

Permalink
build(PYTHON): python to 3.11 and ansible to ^11
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Dec 4, 2024
1 parent ee8dcb3 commit 6b7e2cb
Show file tree
Hide file tree
Showing 15 changed files with 646 additions and 678 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.9.16]
python-version: [3.11.8]

steps:
- name: Apply Test -- Branch Filter
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.9.16]
python-version: [3.11.8]

steps:
- name: Attach Release Binaries -- Branch Filter
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
max-parallel: 4
matrix:
include:
- python-version: 3.9
- python-version: 3.11

steps:
- name: Container Build -- Checkout
Expand Down Expand Up @@ -438,7 +438,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.9]
python-version: [3.11]

steps:
- name: Workflow Lint -- Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -480,7 +480,7 @@ jobs:
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.9.16]
python-version: [3.11.8]

steps:
- name: OSX Build -- Branch Filter
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.11"

sphinx:
builder: html
Expand Down
4 changes: 2 additions & 2 deletions assets/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BUILD_ARG_PYTHON_VERSION=3.9
ARG BUILD_ARG_PYTHON_VERSION=3.11

FROM python:$BUILD_ARG_PYTHON_VERSION-slim AS base

Expand All @@ -14,7 +14,7 @@ ENV PROJECT_NAME "mac_maker"
ENV PIB_CONFIG_FILE_LOCATION "/app/assets/cli.yml"

ENV VERSION_GITLEAKS "v7.2.0"
ENV VERSION_POETRY "poetry<1.4.0"
ENV VERSION_POETRY "poetry>=1.8.0,<1.9.0"
ENV VERSION_TOMLL "v1.9.4"

# Mark Container
Expand Down
3 changes: 2 additions & 1 deletion assets/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
commands:
- 'bandit -r "${PROJECT_NAME}" -c .bandit.rc --ini .bandit -x tests'
- 'echo "\nPoetry is exporting the lockfile standby..."'
- 'poetry export --without-hashes -f requirements.txt | safety check -i 42923 -i 54229 -i 54230 -i 54564 -i 66667 -i 70612 -i 73302 -i 74261 --stdin'
- 'poetry export --without-hashes -f requirements.txt | safety check --stdin'
success: "Security Test Passed!"
failure: "Security Test Failed!"
- name: "test"
Expand All @@ -71,6 +71,7 @@
- name: "types"
path_method: "project_root"
commands:
- 'pip install --upgrade "mypy>=1.13.0"'
- 'mypy --strict --show-error-codes --implicit-reexport ${PROJECT_NAME}'
success: "Type Check Passed!"
failure: "Type Check Failed!"
4 changes: 2 additions & 2 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ workflows:
envs:
- BITRISE_DEPLOY_DIR: "/Users/vagrant/artifacts"
- OS_VERSION: "12"
- PYTHON_VERSION: "3.9.16"
- PYTHON_VERSION: "3.11.16"
steps:
- git-clone@8: {}
- script@1:
Expand Down Expand Up @@ -59,7 +59,7 @@ workflows:
envs:
- BITRISE_DEPLOY_DIR: "/Users/vagrant/artifacts"
- OS_VERSION: "13"
- PYTHON_VERSION: "3.9.16"
- PYTHON_VERSION: "3.11.16"
steps:
- git-clone@8: {}
- script@1:
Expand Down
7 changes: 5 additions & 2 deletions mac_maker/ansible_controller/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ class AnsibleProcess:
error_exit_code = 127

def __init__(
self, ansible_module: str, ansible_class: str, state: TypeState
self,
ansible_module: str,
ansible_class: str,
state: TypeState,
) -> None:
self.log = logging.getLogger(config.LOGGER_NAME)
self.state = state
self.ansible_class = ansible_class
self.ansible_module = ansible_module

def spawn(self, command: str) -> None:
"""Spawns an Ansible CLI Command in it's own process.
"""Spawns an Ansible CLI Command in its own process.
:param command: The Ansible CLI Command to spawn.
"""
Expand Down
45 changes: 29 additions & 16 deletions mac_maker/ansible_controller/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_init(self) -> None:
self.assertEqual(self.process.ansible_class, self.mock_class)


@mock.patch(PROCESS_MODULE + ".os")
@mock.patch(PROCESS_MODULE + ".importlib.import_module")
@mock.patch(PROCESS_MODULE + ".cmd_loop")
@mock.patch(PROCESS_MODULE + ".environment.Environment.setup")
Expand Down Expand Up @@ -127,12 +126,13 @@ def logs_for_main_process_with_interrupt(self) -> List[str]:
)
]

def test__spawn__forked_process(
@mock.patch(PROCESS_MODULE + ".os")
def test_spawn__forked_process(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
split_command = shlex.split(self.command)
m_import.side_effect = [self.mock_cli_module]
Expand All @@ -145,12 +145,13 @@ def test__spawn__forked_process(
self.mock_cli_class.assert_called_once_with(split_command)
self.mock_cli_class.return_value.run.assert_called_once_with()

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
m_import.side_effect = [self.mock_cli_module]
m_os.fork.return_value = 0
Expand All @@ -163,12 +164,13 @@ def test__spawn__forked_process__logs(
self.logs_for_forked_process(),
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__dynamic_imports(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
m_import.side_effect = [self.mock_cli_module]
m_os.fork.return_value = 0
Expand All @@ -178,12 +180,13 @@ def test__spawn__forked_process__dynamic_imports(
m_cmdloop.exit_shell.assert_called_once_with(0, 0)
self.assertEqual(m_import.call_args_list, [mock.call(self.mock_module)])

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__environment(
self,
m_os: mock.Mock,
m_env: mock.Mock,
m_cmdloop: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 0
m_import.side_effect = [self.mock_cli_module]
Expand All @@ -194,12 +197,13 @@ def test__spawn__forked_process__environment(
m_cmdloop.exit_shell.assert_called_once_with(0, 0)
m_os.chdir.assert_called_once_with(self.process.state['profile_data_path'])

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__interrupt(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
__: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 0
m_os.chdir.side_effect = KeyboardInterrupt("Boom!")
Expand All @@ -210,12 +214,13 @@ def test__spawn__forked_process__interrupt(
self.process.error_exit_code, 0
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__interrupt__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
___: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 0
m_os.chdir.side_effect = KeyboardInterrupt("Boom!")
Expand All @@ -228,12 +233,13 @@ def test__spawn__forked_process__interrupt__logs(
self.logs_for_forked_process()[0:2],
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__exception(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 0
m_import.side_effect = [self.mock_cli_module]
Expand All @@ -245,12 +251,13 @@ def test__spawn__forked_process__exception(
self.process.error_exit_code, 0
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__forked_process__exception__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
m_import: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 0
m_import.side_effect = [self.mock_cli_module]
Expand All @@ -264,12 +271,13 @@ def test__spawn__forked_process__exception__logs(
self.logs_for_forked_process()[0:4],
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
__: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.return_value = (0, 0)
Expand All @@ -283,12 +291,13 @@ def test__spawn__main_process(
m_os.fork.assert_called_once()
m_os.waitpid.assert_called_once_with(1, 0)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
___: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.return_value = (0, 0)
Expand All @@ -304,12 +313,13 @@ def test__spawn__main_process__logs(
self.logs_for_main_process_without_error(),
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process__child_error(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
__: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.return_value = (0, 256)
Expand All @@ -323,12 +333,13 @@ def test__spawn__main_process__child_error(
m_os.fork.assert_called_once()
m_os.waitpid.assert_called_once_with(1, 0)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process__child_error__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
___: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.return_value = (0, 256)
Expand All @@ -342,12 +353,13 @@ def test__spawn__main_process__child_error__logs(
self.logs_for_main_process_with_error(),
)

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process__interrupt(
self,
m_os: mock.Mock,
_: mock.Mock,
m_cmdloop: mock.Mock,
__: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.side_effect = KeyboardInterrupt("Boom!")
Expand All @@ -358,12 +370,13 @@ def test__spawn__main_process__interrupt(
m_cmdloop.exit.assert_called_with(self.process.error_exit_code, 1)
m_cmdloop.interrupt.assert_not_called()

@mock.patch(PROCESS_MODULE + ".os")
def test__spawn__main_process_interrupt__logs(
self,
m_os: mock.Mock,
_: mock.Mock,
__: mock.Mock,
___: mock.Mock,
m_os: mock.Mock,
) -> None:
m_os.fork.return_value = 1
m_os.waitpid.side_effect = KeyboardInterrupt("Boom!")
Expand Down
2 changes: 1 addition & 1 deletion mac_maker/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# type: ignore[misc]
# mypy: disable-error-code="misc"
"""The Mac Maker CLI."""

from typing import Optional
Expand Down
5 changes: 2 additions & 3 deletions mac_maker/jobs/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test the VersionCommand class."""

from importlib.metadata import version
from unittest import TestCase, mock

import pkg_resources
from .. import version as jobs_module

JOBS_MODULE = jobs_module.__name__
Expand All @@ -19,6 +19,5 @@ def test_invoke(self, m_echo: mock.Mock) -> None:
self.command.invoke()

m_echo.assert_called_once_with(
"Mac Maker Version: "
f"{pkg_resources.get_distribution('mac_maker').version}",
f"Mac Maker Version: {version('mac_maker')}",
)
8 changes: 3 additions & 5 deletions mac_maker/jobs/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""A simple job to report the version of the Mac Maker CLI."""

from importlib.metadata import version

import click
import pkg_resources
from . import bases


Expand All @@ -11,7 +12,4 @@ class VersionJob(bases.SimpleJobBase):
def invoke(self) -> None:
"""Report the Mac Maker version."""

click.echo(
"Mac Maker Version: "
f"{pkg_resources.get_distribution('mac_maker').version}",
)
click.echo(f"Mac Maker Version: {version('mac_maker')}")
2 changes: 1 addition & 1 deletion mac_maker/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from click.testing import CliRunner
from parameterized import parameterized_class
from .. import cli as cli_module
from ..cli import cli # type: ignore[attr-defined]
from ..cli import cli
from .fixtures import fixtures_git

CLI_MODULE = cli_module.__name__
Expand Down
Loading

0 comments on commit 6b7e2cb

Please sign in to comment.