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

project: Format and sort imports #765

Merged
merged 3 commits into from
Nov 5, 2024
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: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespaces = false

[tool.ruff.lint]
extend-select = [
"I", # isort
"UP", # pyupgrade
]
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion src/west/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
53 changes: 39 additions & 14 deletions src/west/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 per line is a significant waste of screen estate but no big deal...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting these long lines to help out a lot for git diffs though.

)
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.
#
Expand Down
25 changes: 15 additions & 10 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/west/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/west/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/west/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''

Expand Down
11 changes: 5 additions & 6 deletions src/west/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess

import pytest

from conftest import cmd

assert 'TOXTEMPDIR' in os.environ, "you must run these tests using tox"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_help.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
47 changes: 33 additions & 14 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
19 changes: 14 additions & 5 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down