Skip to content

Commit

Permalink
Upgrade to python 3.10 (#134)
Browse files Browse the repository at this point in the history
* Upgrade to python 3.10

* Remove 3.8 and 3.9 from ci
  • Loading branch information
twizmwazin authored May 9, 2024
1 parent daa9200 commit 3b15145
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
rust-target:
- 'x86_64-pc-windows-msvc'
- 'i686-pc-windows-msvc'
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
fail-fast: false
name: Tests on Python ${{ matrix.python-version }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "maturin"
name = "binharness"
description = "A framework to analyze programs running in environments"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.10"
license = {file = "LICENSE"}
authors = [{name = "Kevin Phoenix", email = "[email protected]"}]
maintainers = [{name = "Kevin Phoenix", email = "[email protected]"}]
Expand Down Expand Up @@ -93,7 +93,7 @@ required-imports = ["from __future__ import annotations"]
]

[tool.mypy]
python_version = "3.8"
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
warn_redundant_casts = true
Expand Down
5 changes: 4 additions & 1 deletion python/binharness/agentenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import stat
from functools import cached_property
from pathlib import Path
from typing import Sequence, cast
from typing import TYPE_CHECKING, cast

from bh_agent_client import BhAgentClient

Expand All @@ -15,6 +15,9 @@
from binharness.types.stat import FileStat
from binharness.util import normalize_args

if TYPE_CHECKING:
from collections.abc import Sequence


class AgentIO(IO[bytes]):
"""AgentIO implements the IO interface for agents."""
Expand Down
4 changes: 3 additions & 1 deletion python/binharness/common/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import platform
from pathlib import Path
from typing import TYPE_CHECKING, Generator, cast
from typing import TYPE_CHECKING, cast

from binharness.types.executor import InjectableExecutor
from binharness.types.injection import ExecutableInjection
from binharness.types.io import IO
from binharness.util import generate_random_suffix, read_lines

if TYPE_CHECKING:
from collections.abc import Generator

from binharness import Process, Target


Expand Down
5 changes: 4 additions & 1 deletion python/binharness/localenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import tempfile
import typing
from pathlib import Path
from typing import AnyStr, Sequence
from typing import AnyStr

from binharness.types.environment import Environment
from binharness.types.io import IO
from binharness.types.process import Process
from binharness.types.stat import FileStat
from binharness.util import normalize_args

if typing.TYPE_CHECKING:
from collections.abc import Sequence


class LocalIO(IO[AnyStr]):
"""A file-like object for the local environment."""
Expand Down
14 changes: 8 additions & 6 deletions python/binharness/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def export_target(target: Target, export_path: Path) -> None:
This function is the inverse of import_target.
"""
with tempfile.TemporaryDirectory() as raw_tmpdir, zipfile.ZipFile(
export_path, "w"
) as archive:
with (
tempfile.TemporaryDirectory() as raw_tmpdir,
zipfile.ZipFile(export_path, "w") as archive,
):
tmpdir = Path(raw_tmpdir)
target.environment.retrieve_files(
[
Expand All @@ -52,9 +53,10 @@ def import_target(environment: Environment, import_path: Path) -> Target:
This function is the inverse of export_target.
"""
with tempfile.TemporaryDirectory() as raw_tempdir, zipfile.ZipFile(
import_path
) as zip_file:
with (
tempfile.TemporaryDirectory() as raw_tempdir,
zipfile.ZipFile(import_path) as zip_file,
):
tmpdir = Path(raw_tempdir)
try:
metadata_io = zip_file.read(_META_FILENAME)
Expand Down
3 changes: 2 additions & 1 deletion python/binharness/types/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, AnyStr, Sequence
from typing import TYPE_CHECKING, AnyStr

if TYPE_CHECKING:
from collections.abc import Sequence
from pathlib import Path

from binharness import IO, Process
Expand Down
5 changes: 3 additions & 2 deletions python/binharness/types/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from __future__ import annotations

from typing import TYPE_CHECKING, AnyStr, ContextManager, Protocol
from contextlib import AbstractContextManager
from typing import TYPE_CHECKING, AnyStr, Protocol

if TYPE_CHECKING:
from types import TracebackType


class IO(ContextManager["IO[AnyStr]"], Protocol[AnyStr]):
class IO(AbstractContextManager["IO[AnyStr]"], Protocol[AnyStr]):
"""A file-like object."""

def close(self: IO[AnyStr]) -> None:
Expand Down
3 changes: 2 additions & 1 deletion python/binharness/types/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from __future__ import annotations

from abc import ABC, abstractmethod, abstractproperty
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Sequence
from pathlib import Path

from binharness.types.environment import Environment
Expand Down
8 changes: 5 additions & 3 deletions python/binharness/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import shlex
import string
from pathlib import Path
from typing import TYPE_CHECKING, Generator, Sequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Generator, Sequence

from binharness.types.io import IO


Expand All @@ -20,9 +22,9 @@ def normalize_args(*args: Path | str | Sequence[Path | str]) -> Sequence[str]:

flattened_args: list[str] = []
for arg in args:
if isinstance(arg, (str, Path)):
if isinstance(arg, str | Path):
flattened_args.append(str(arg))
elif isinstance(arg, (list, set, tuple)):
elif isinstance(arg, list | set | tuple):
flattened_args.extend(str(a) for a in arg)
return flattened_args

Expand Down
4 changes: 3 additions & 1 deletion python/tests/bootstrap/test_ssh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Generator
from typing import TYPE_CHECKING

import mockssh
import pytest
Expand All @@ -11,6 +11,8 @@
from binharness.types.target import Target

if TYPE_CHECKING:
from collections.abc import Generator

from paramiko import SSHClient

SAMPLE_USER_KEY = str(Path(mockssh.__file__).parent / "sample-user-key")
Expand Down
4 changes: 3 additions & 1 deletion python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import platform
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Generator
from typing import TYPE_CHECKING

import pytest

Expand All @@ -12,6 +12,8 @@
from binharness.localenvironment import LocalEnvironment

if TYPE_CHECKING:
from collections.abc import Generator

from binharness.agentenvironment import AgentEnvironment
from binharness.types.environment import Environment

Expand Down
26 changes: 14 additions & 12 deletions python/tests/test_target_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ def test_local_target_import_without_metadata(env: Environment) -> None:
with tempfile.TemporaryDirectory() as raw_tmpdir:
tmpdir = Path(raw_tmpdir)
export_target(target, tmpdir / "test_export.zip")
with zipfile.ZipFile(
tmpdir / "test_export.zip", "r"
) as old_zip, zipfile.ZipFile(
tmpdir / "test_export_modified.zip",
"w",
) as new_zip:
with (
zipfile.ZipFile(tmpdir / "test_export.zip", "r") as old_zip,
zipfile.ZipFile(
tmpdir / "test_export_modified.zip",
"w",
) as new_zip,
):
for member in old_zip.infolist():
if member.filename != ".bh-target-metadata":
new_zip.writestr(member, old_zip.read(member.filename))
Expand All @@ -60,12 +61,13 @@ def test_local_target_import_invalid_metadata_archive(env: Environment) -> None:
with tempfile.TemporaryDirectory() as raw_tmpdir:
tmpdir = Path(raw_tmpdir)
export_target(target, tmpdir / "test_export.zip")
with zipfile.ZipFile(
tmpdir / "test_export.zip", "r"
) as old_zip, zipfile.ZipFile(
tmpdir / "test_export_modified.zip",
"w",
) as new_zip:
with (
zipfile.ZipFile(tmpdir / "test_export.zip", "r") as old_zip,
zipfile.ZipFile(
tmpdir / "test_export_modified.zip",
"w",
) as new_zip,
):
for info in old_zip.infolist():
if info.filename != ".bh-target-metadata":
new_zip.writestr(info.filename, old_zip.read(info))
Expand Down

0 comments on commit 3b15145

Please sign in to comment.