From baea1b15c5c9acb201b49187879470cba06575e0 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 4 Nov 2024 19:43:36 +0100 Subject: [PATCH 1/3] src: Format and sort imports Apply isort on files in src/ Signed-off-by: Pieter De Gendt --- src/west/app/config.py | 2 +- src/west/app/main.py | 53 ++++++++++++++++++++++++++++----------- src/west/app/project.py | 25 ++++++++++-------- src/west/commands.py | 12 ++++----- src/west/configuration.py | 11 ++++---- src/west/log.py | 6 ++--- src/west/manifest.py | 11 ++++---- 7 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/west/app/config.py b/src/west/app/config.py index 074f74b8..63454bab 100644 --- a/src/west/app/config.py +++ b/src/west/app/config.py @@ -6,8 +6,8 @@ import argparse +from west.commands import CommandError, WestCommand from west.configuration import ConfigFile -from west.commands import WestCommand, CommandError CONFIG_DESCRIPTION = '''\ West configuration file handling. diff --git a/src/west/app/main.py b/src/west/app/main.py index 9536bf6a..50bcee49 100755 --- a/src/west/app/main.py +++ b/src/west/app/main.py @@ -12,36 +12,61 @@ ''' import argparse -from collections import OrderedDict -import colorama -from io import StringIO import logging import os -from pathlib import Path, PurePath import platform import shlex import shutil import signal import sys -from subprocess import CalledProcessError import tempfile import textwrap import traceback +from collections import OrderedDict +from io import StringIO +from pathlib import Path, PurePath +from subprocess import CalledProcessError from typing import NamedTuple, Optional -from west import log +import colorama + import west.configuration -from west.commands import WestCommand, extension_commands, \ - CommandError, ExtensionCommandError, Verbosity -from west.app.project import List, ManifestCommand, Compare, Diff, Status, \ - SelfUpdate, ForAll, Grep, Init, Update, Topdir +from west import log from west.app.config import Config -from west.manifest import Manifest, MalformedConfig, MalformedManifest, \ - ManifestVersionError, ManifestImportFailed, _ManifestImportDepth, \ - ManifestProject, MANIFEST_REV_BRANCH -from west.util import quote_sh_list, west_topdir, WestNotFound +from west.app.project import ( + Compare, + Diff, + ForAll, + Grep, + Init, + List, + ManifestCommand, + SelfUpdate, + Status, + Topdir, + Update, +) +from west.commands import ( + CommandError, + ExtensionCommandError, + Verbosity, + WestCommand, + extension_commands, +) +from west.manifest import ( + MANIFEST_REV_BRANCH, + MalformedConfig, + MalformedManifest, + Manifest, + ManifestImportFailed, + ManifestProject, + ManifestVersionError, + _ManifestImportDepth, +) +from west.util import WestNotFound, quote_sh_list, west_topdir from west.version import __version__ + class EarlyArgs(NamedTuple): # Data type for storing "early" argument parsing results. # diff --git a/src/west/app/project.py b/src/west/app/project.py index b806a5a8..d5f4c705 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -6,30 +6,35 @@ '''West project commands''' import argparse -from functools import partial import logging import os -from os.path import abspath, relpath -from pathlib import PurePath, Path -import shutil import shlex +import shutil import subprocess import sys import textwrap import time +from functools import partial +from os.path import abspath, relpath +from pathlib import Path, PurePath from time import perf_counter from urllib.parse import urlparse -from west.configuration import Configuration from west import util -from west.commands import WestCommand, CommandError, Verbosity -from west.manifest import ImportFlag, Manifest, \ - ManifestProject, _manifest_content_at, ManifestImportFailed -from west.manifest import is_group as is_project_group +from west.commands import CommandError, Verbosity, WestCommand +from west.configuration import Configuration from west.manifest import MANIFEST_REV_BRANCH as MANIFEST_REV -from west.manifest import Submodule from west.manifest import QUAL_MANIFEST_REV_BRANCH as QUAL_MANIFEST_REV from west.manifest import QUAL_REFS_WEST as QUAL_REFS +from west.manifest import ( + ImportFlag, + Manifest, + ManifestImportFailed, + ManifestProject, + Submodule, + _manifest_content_at, +) +from west.manifest import is_group as is_project_group # # Project-related or multi-repo commands, like "init", "update", diff --git a/src/west/commands.py b/src/west/commands.py index 278ad709..42246d8c 100644 --- a/src/west/commands.py +++ b/src/west/commands.py @@ -4,19 +4,19 @@ # # SPDX-License-Identifier: Apache-2.0 -from abc import ABC, abstractmethod import argparse -from collections import OrderedDict -from dataclasses import dataclass -from enum import IntEnum import importlib.util import itertools import os -from pathlib import Path import re import shutil import subprocess import sys +from abc import ABC, abstractmethod +from collections import OrderedDict +from dataclasses import dataclass +from enum import IntEnum +from pathlib import Path from types import ModuleType from typing import Callable, NoReturn, Optional @@ -26,7 +26,7 @@ from west.configuration import Configuration from west.manifest import Manifest, Project -from west.util import escapes_directory, quote_sh_list, PathType +from west.util import PathType, escapes_directory, quote_sh_list '''\ This package provides WestCommand, which is the common abstraction all diff --git a/src/west/configuration.py b/src/west/configuration.py index aa220dbc..6c61520d 100644 --- a/src/west/configuration.py +++ b/src/west/configuration.py @@ -37,14 +37,15 @@ import configparser import os -from pathlib import PureWindowsPath, Path import platform -from enum import Enum -from typing import Any, Optional, TYPE_CHECKING, Union -from collections.abc import Iterable import warnings +from collections.abc import Iterable +from enum import Enum +from pathlib import Path, PureWindowsPath +from typing import TYPE_CHECKING, Any, Optional, Union + +from west.util import WEST_DIR, PathType, WestNotFound, west_dir -from west.util import WEST_DIR, west_dir, WestNotFound, PathType class MalformedConfig(Exception): '''The west configuration was malformed. diff --git a/src/west/log.py b/src/west/log.py index 6d8faa44..1a624060 100644 --- a/src/west/log.py +++ b/src/west/log.py @@ -20,13 +20,13 @@ ''' import sys -from typing import NoReturn import warnings - -from west import configuration as config +from typing import NoReturn import colorama +from west import configuration as config + VERBOSE_NONE = 0 '''Default verbosity level, no dbg() messages printed.''' diff --git a/src/west/manifest.py b/src/west/manifest.py index 3a3379dd..4acfde2a 100644 --- a/src/west/manifest.py +++ b/src/west/manifest.py @@ -7,27 +7,26 @@ Parser and abstract data types for west manifests. ''' -from collections import deque import enum import errno import logging import os -from pathlib import PurePosixPath, Path import re import shlex import subprocess import sys -from typing import Any, Callable, NoReturn, \ - NamedTuple, Optional, TYPE_CHECKING, Union +from collections import deque from collections.abc import Iterable +from pathlib import Path, PurePosixPath +from typing import TYPE_CHECKING, Any, Callable, NamedTuple, NoReturn, Optional, Union -from packaging.version import parse as parse_version import pykwalify.core import yaml +from packaging.version import parse as parse_version from west import util +from west.configuration import ConfigFile, Configuration, MalformedConfig from west.util import PathType -from west.configuration import Configuration, ConfigFile, MalformedConfig # # Public constants From b99f020b19c2652aad535c9185f72ce9868bdf6d Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 4 Nov 2024 19:44:52 +0100 Subject: [PATCH 2/3] tests: Format and sort imports Apply isort on files in tests/ Signed-off-by: Pieter De Gendt --- tests/conftest.py | 5 +++-- tests/test_alias.py | 1 - tests/test_config.py | 5 ++--- tests/test_help.py | 4 ++-- tests/test_manifest.py | 47 +++++++++++++++++++++++++++++------------- tests/test_project.py | 19 ++++++++++++----- 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7de6be58..2d1f7615 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,16 +3,17 @@ # SPDX-License-Identifier: Apache-2.0 import os -from pathlib import Path, PurePath import platform import shutil import subprocess import sys import textwrap +from pathlib import Path, PurePath -from west import configuration as config import pytest +from west import configuration as config + GIT = shutil.which('git') # Git capabilities are discovered at runtime in diff --git a/tests/test_alias.py b/tests/test_alias.py index 6dba3984..88ad7e45 100644 --- a/tests/test_alias.py +++ b/tests/test_alias.py @@ -6,7 +6,6 @@ import subprocess import pytest - from conftest import cmd assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox" diff --git a/tests/test_config.py b/tests/test_config.py index d8c80437..e31d7cd4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,16 +5,15 @@ import configparser import os import pathlib -from typing import Any, Optional import subprocess +from typing import Any, Optional import pytest +from conftest import cmd from west import configuration as config from west.util import PathType -from conftest import cmd - assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox" SYSTEM = config.ConfigFile.SYSTEM diff --git a/tests/test_help.py b/tests/test_help.py index 967e0a42..8fb54d68 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -1,13 +1,13 @@ # Copyright (c) 2020, Nordic Semiconductor ASA import itertools - import os import sys -from west.app.main import BUILTIN_COMMAND_GROUPS from conftest import cmd +from west.app.main import BUILTIN_COMMAND_GROUPS + assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox" def test_builtin_help_and_dash_h(west_init_tmpdir): diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 270d859c..274820a6 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -9,30 +9,49 @@ # it's particularly inconvenient to test something without a real git # repository, go ahead and make one in a temporary directory. -from copy import deepcopy -from glob import glob import logging import os -from pathlib import PurePath, Path import platform import subprocess -from unittest.mock import patch import textwrap +from copy import deepcopy +from glob import glob +from pathlib import Path, PurePath +from unittest.mock import patch import pytest import yaml - -from west.manifest import Manifest, Project, ManifestProject, \ - MalformedManifest, ManifestVersionError, ManifestImportFailed, \ - manifest_path, ImportFlag, validate, MANIFEST_PROJECT_INDEX, \ - _ManifestImportDepth, is_group, SCHEMA_VERSION -from west.configuration import Configuration, ConfigFile, MalformedConfig +from conftest import ( + GIT, + add_commit, + add_tag, + check_proj_consistency, + checkout_branch, + create_branch, + create_repo, + create_workspace, + rev_parse, +) + +from west.configuration import ConfigFile, Configuration, MalformedConfig # White box checks for the schema version. -from west.manifest import _VALID_SCHEMA_VERS - -from conftest import create_workspace, create_repo, checkout_branch, \ - create_branch, add_commit, add_tag, rev_parse, GIT, check_proj_consistency +from west.manifest import ( + _VALID_SCHEMA_VERS, + MANIFEST_PROJECT_INDEX, + SCHEMA_VERSION, + ImportFlag, + MalformedManifest, + Manifest, + ManifestImportFailed, + ManifestProject, + ManifestVersionError, + Project, + _ManifestImportDepth, + is_group, + manifest_path, + validate, +) assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox" diff --git a/tests/test_project.py b/tests/test_project.py index 31608bc2..491347ec 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -9,13 +9,22 @@ from pathlib import Path, PurePath import pytest +from conftest import ( + GIT, + WINDOWS, + add_commit, + add_tag, + check_output, + check_proj_consistency, + cmd, + create_branch, + create_repo, + create_workspace, + rev_parse, +) -from west.manifest import Manifest, ManifestProject, Project, \ - ManifestImportFailed from west.manifest import ImportFlag as MIF -from conftest import create_branch, create_workspace, create_repo, \ - add_commit, add_tag, check_output, cmd, GIT, rev_parse, \ - check_proj_consistency, WINDOWS +from west.manifest import Manifest, ManifestImportFailed, ManifestProject, Project assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox" From 802d5302b57014ab1ad5ef0d9a608f789ede7b6f Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 4 Nov 2024 19:45:42 +0100 Subject: [PATCH 3/3] project: Extend ruff with isort checks Check for isort issues when running ruff check. Signed-off-by: Pieter De Gendt --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a25338d0..dbf8ace8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,7 @@ namespaces = false [tool.ruff.lint] extend-select = [ + "I", # isort "UP", # pyupgrade ] ignore = [