Skip to content

Commit

Permalink
Sort import statements (excluding mlflow for now) (mlflow#9409)
Browse files Browse the repository at this point in the history
Signed-off-by: harupy <[email protected]>
Signed-off-by: Clark Hollar <[email protected]>
  • Loading branch information
harupy authored and clarkh-ncino committed Aug 23, 2023
1 parent f9e5e63 commit 4b91a87
Show file tree
Hide file tree
Showing 297 changed files with 1,805 additions and 1,678 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ repos:
args: ["--no-config", "--print-width", "100"]
- repo: local
hooks:
- id: ruff
name: ruff
entry: ruff
language: system
types_or: [python]
stages: [commit]

- id: black
name: black
entry: black
Expand All @@ -30,13 +37,6 @@ repos:
args: ["--rcfile=pylintrc"]
stages: [commit]

- id: ruff
name: ruff
entry: ruff
language: system
types: [python]
stages: [commit]

- id: disallow-rule-ids
name: disallow-rule-ids
entry: python ./dev/disallow_rule_ids.py
Expand Down
5 changes: 3 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
import os
import posixpath
import pytest
import shutil
import json
import subprocess

import pytest

from mlflow.environment_variables import _MLFLOW_TESTING


Expand Down
2 changes: 1 addition & 1 deletion dev/generate_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import argparse
import sys
import yaml

import yaml

AUTOGENERATED_HEADER = """\
# This file is automatically generated by running the dev/generate_requirements.py script. Do not
Expand Down
7 changes: 4 additions & 3 deletions dev/get_minimum_required_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
Usage:
python dev/get_minimum_required_python.py -p scikit-learn -v 1.1.0 --python-versions "3.8"
"""
import argparse
import typing as t

import requests
from packaging.version import Version
from packaging.specifiers import SpecifierSet
import typing as t
import argparse
from packaging.version import Version


def get_requires_python(package: str, version: str) -> t.Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion dev/list_changed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
---------------------------------------------------------------------------
"""
import argparse
import json
import os
import urllib.request
import json


def parse_args():
Expand Down
5 changes: 3 additions & 2 deletions dev/preview_docs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import requests
import argparse
import os
import time
from urllib.parse import urlparse

import requests


class Session(requests.Session):
def get(self, *args, **kwargs):
Expand Down
9 changes: 5 additions & 4 deletions dev/set_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
python dev/set_matrix.py --versions 1.1.1
```
"""
import sys
import argparse
import functools
import json
import os
import re
import shutil
import functools
import sys
import typing as t
from collections import defaultdict

import yaml
import requests
import yaml
from packaging.specifiers import SpecifierSet
from packaging.version import Version as OriginalVersion, InvalidVersion
from packaging.version import InvalidVersion
from packaging.version import Version as OriginalVersion
from pydantic import BaseModel, validator

VERSIONS_YAML_PATH = "mlflow/ml-package-versions.yml"
Expand Down
7 changes: 4 additions & 3 deletions dev/show_package_release_dates.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import asyncio
import json
import sys
import subprocess
import asyncio
import aiohttp
import sys
import traceback

import aiohttp


def get_distributions():
res = subprocess.check_output(
Expand Down
6 changes: 3 additions & 3 deletions dev/update_changelog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
import os
import re
import subprocess
from datetime import datetime
from collections import defaultdict
from datetime import datetime
from pathlib import Path
from typing import NamedTuple, List, Any
from typing import Any, List, NamedTuple

import click
import requests
Expand Down
5 changes: 3 additions & 2 deletions dev/update_ml_package_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
$ python dev/update_ml_package_versions.py
"""
import json
from pathlib import Path
from packaging.version import Version
import re
import urllib.request
from pathlib import Path

import yaml
from packaging.version import Version


def read_file(path):
Expand Down
3 changes: 2 additions & 1 deletion dev/update_pypi_package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import argparse
import json
import posixpath
import requests
import sys
from datetime import datetime
from html.parser import HTMLParser

import requests


def parse_args(args):
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion dev/update_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import argparse

import requests
from packaging.version import Version, InvalidVersion
from packaging.version import InvalidVersion, Version
from ruamel.yaml import YAML


Expand Down
2 changes: 1 addition & 1 deletion pylint_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pylint_plugins.import_checker import ImportChecker
from pylint_plugins.assign_checker import AssignChecker
from pylint_plugins.import_checker import ImportChecker


def register(linter):
Expand Down
2 changes: 1 addition & 1 deletion pylint_plugins/assign_checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import astroid
from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker

from pylint_plugins.errors import USELESS_ASSIGNMENT, to_msgs

Expand Down
2 changes: 1 addition & 1 deletion pylint_plugins/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import NamedTuple, Dict, Tuple
from functools import reduce
from typing import Dict, NamedTuple, Tuple


class Message(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion pylint_plugins/import_checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import astroid
from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from pylint.lint import PyLinter

from pylint_plugins.errors import LAZY_BUILTIN_IMPORT, to_msgs
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ select = [
"E",
"F",
"C4",
"I",
"PLR0402",
"PT001",
"PT002",
Expand Down Expand Up @@ -72,7 +73,11 @@ extend-exclude = [

[tool.ruff.per-file-ignores]
"dev/*" = ["T201", "PT018"]
"mlflow/*" = ["PT018"]
"mlflow/*" = [
"PT018",
# TODO: Sort imports in files under `mlflow` as well
"I",
]

[tool.ruff.flake8-pytest-style]
mark-parentheses = false
Expand All @@ -81,3 +86,6 @@ raises-require-match-for = ["*"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.isort]
forced-separate = ["tests"]
7 changes: 3 additions & 4 deletions tests/artifacts/test_artifacts.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import pathlib
import uuid
from unittest import mock
from collections import namedtuple
from typing import NamedTuple
from unittest import mock

import pytest

import mlflow
from mlflow.exceptions import MlflowException
from mlflow.utils.file_utils import path_to_local_file_uri, mkdir, local_file_uri_to_path
from collections import namedtuple
from mlflow.utils.file_utils import local_file_uri_to_path, mkdir, path_to_local_file_uri
from mlflow.utils.os import is_windows


Artifact = namedtuple("Artifact", ["uri", "content"])


Expand Down
3 changes: 1 addition & 2 deletions tests/autologging/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import pytest

from mlflow.environment_variables import _MLFLOW_AUTOLOGGING_TESTING
from mlflow.utils import logging_utils
from mlflow.utils.autologging_utils import is_testing
from mlflow.environment_variables import _MLFLOW_AUTOLOGGING_TESTING


PATCH_DESTINATION_FN_DEFAULT_RESULT = "original_result"

Expand Down
18 changes: 10 additions & 8 deletions tests/autologging/test_autologging_behaviors_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

import importlib
import logging
import pytest
import sys
import warnings
from concurrent.futures import ThreadPoolExecutor
from io import StringIO
from itertools import permutations
from unittest import mock

import pytest

import mlflow
from mlflow import MlflowClient
from mlflow.utils import gorilla
from mlflow.utils.autologging_utils import (
safe_patch,
get_autologging_config,
autologging_is_disabled,
get_autologging_config,
safe_patch,
)

from tests.autologging.fixtures import test_mode_off
from tests.autologging.fixtures import reset_stderr # noqa: F401

from tests.autologging.fixtures import (
reset_stderr, # noqa: F401
test_mode_off,
)

AUTOLOGGING_INTEGRATIONS_TO_TEST = {
mlflow.sklearn: "sklearn",
Expand Down Expand Up @@ -206,7 +208,7 @@ def test_autolog_reverts_patched_code_when_disabled():

def test_autolog_respects_disable_flag_across_import_orders():
def test():
from sklearn import svm, datasets
from sklearn import datasets, svm

iris = datasets.load_iris()
svc = svm.SVC(C=2.0, degree=5, kernel="rbf")
Expand Down Expand Up @@ -312,9 +314,9 @@ def test_autolog_globally_configured_flag_set_correctly():
from mlflow.utils.autologging_utils import AUTOLOGGING_INTEGRATIONS

AUTOLOGGING_INTEGRATIONS.clear()
import sklearn # noqa: F401
import pyspark
import pyspark.ml # noqa: F401
import sklearn # noqa: F401

integrations_to_test = ["sklearn", "spark", "pyspark.ml"]
mlflow.autolog()
Expand Down
14 changes: 9 additions & 5 deletions tests/autologging/test_autologging_behaviors_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
from concurrent.futures import ThreadPoolExecutor
from io import StringIO

import numpy as np
import pytest

import mlflow
from mlflow.utils.logging_utils import eprint
from mlflow.utils.autologging_utils import autologging_integration, safe_patch
from mlflow.utils.logging_utils import eprint

import pytest
import numpy as np
from tests.autologging.fixtures import test_mode_off, patch_destination
from tests.autologging.fixtures import reset_stderr # noqa: F401
from tests.autologging.fixtures import (
patch_destination,
reset_stderr, # noqa: F401
test_mode_off,
)


@pytest.fixture
Expand Down
9 changes: 5 additions & 4 deletions tests/autologging/test_autologging_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import time
import pytest
from unittest import mock

import pytest

import mlflow
from mlflow.exceptions import MlflowException
from mlflow import MlflowClient
from mlflow.exceptions import MlflowException
from mlflow.utils import _truncate_dict
from mlflow.utils.autologging_utils import MlflowAutologgingQueueingClient
from mlflow.utils.validation import (
MAX_ENTITY_KEY_LENGTH,
MAX_METRICS_PER_BATCH,
MAX_PARAM_VAL_LENGTH,
MAX_TAG_VAL_LENGTH,
MAX_PARAMS_TAGS_PER_BATCH,
MAX_METRICS_PER_BATCH,
MAX_TAG_VAL_LENGTH,
)


Expand Down
Loading

0 comments on commit 4b91a87

Please sign in to comment.