Skip to content

Commit d3660b6

Browse files
amyreesefacebook-github-bot
authored andcommitted
apply import merging for fbcode (10 of 11)
Summary: Applies new import merging and sorting from µsort v1.0. When merging imports, µsort will make a best-effort to move associated comments to match merged elements, but there are known limitations due to the diynamic nature of Python and developer tooling. These changes should not produce any dangerous runtime changes, but may require touch-ups to satisfy linters and other tooling. Note that µsort uses case-insensitive, lexicographical sorting, which results in a different ordering compared to isort. This provides a more consistent sorting order, matching the case-insensitive order used when sorting import statements by module name, and ensures that "frog", "FROG", and "Frog" always sort next to each other. For details on µsort's sorting and merging semantics, see the user guide: https://usort.readthedocs.io/en/stable/guide.html#sorting Reviewed By: lisroach Differential Revision: D36402249 fbshipit-source-id: 93618434ae891f091dde1e067c67a3c19445653b
1 parent 0948d80 commit d3660b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+128
-151
lines changed

docs/versions_html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from string import Template
2626
from typing import List, Optional
2727

28-
from packaging.version import Version, InvalidVersion
28+
from packaging.version import InvalidVersion, Version
2929

3030
VERSIONS_HTML_TEMPLATE = Template(
3131
"""

scripts/component_integration_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import example_app_defs as examples_app_defs_providers
1616
import torchx.components.integration_tests.component_provider as component_provider
17-
from integ_test_utils import BuildInfo, MissingEnvError, build_images, push_images
17+
from integ_test_utils import build_images, BuildInfo, MissingEnvError, push_images
1818
from torchx.cli.colors import BLUE, ENDC, GRAY
1919
from torchx.components.integration_tests.integ_tests import IntegComponentTest
2020
from torchx.schedulers import get_scheduler_factories

scripts/kfpint.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@
4545
import tempfile
4646
import time
4747
from contextlib import contextmanager
48-
from typing import Optional, Iterator, Any, TypeVar, Callable
48+
from typing import Any, Callable, Iterator, Optional, TypeVar
4949

5050
import kfp
5151

5252
# pyre-ignore-all-errors[21] # Cannot find module utils
5353
# pyre-ignore-all-errors[11]
5454
from integ_test_utils import (
55-
MissingEnvError,
55+
build_images,
56+
BuildInfo,
5657
getenv_asserts,
58+
MissingEnvError,
59+
push_images,
5760
run,
5861
run_in_bg,
59-
BuildInfo,
60-
build_images,
61-
push_images,
6262
)
6363
from pyre_extensions import none_throws
6464
from urllib3.exceptions import MaxRetryError

scripts/kube_dist_trainer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import argparse
1313
import os
1414

15-
from integ_test_utils import BuildInfo, MissingEnvError, build_images, push_images
15+
from integ_test_utils import build_images, BuildInfo, MissingEnvError, push_images
1616
from pyre_extensions import none_throws
1717
from torchx.examples.apps.lightning_classy_vision.component import trainer_dist
1818
from torchx.runner import get_runner
19-
from torchx.specs import AppState, Resource, named_resources
19+
from torchx.specs import AppState, named_resources, Resource
2020

2121

2222
# pyre-ignore-all-errors[21] # Cannot find module utils

torchx/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# LICENSE file in the root directory of this source tree.
77

88
from .version import ( # noqa F401; noqa F401
9-
TORCHX_IMAGE as IMAGE,
109
__version__ as __version__,
10+
TORCHX_IMAGE as IMAGE,
1111
)

torchx/cli/cmd_log.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
import threading
1313
import time
1414
from queue import Queue
15-
from typing import Optional, List, Tuple, TextIO
15+
from typing import List, Optional, TextIO, Tuple
1616

1717
from pyre_extensions import none_throws
1818
from torchx import specs
1919
from torchx.cli.cmd_base import SubCommand
20-
from torchx.cli.colors import GREEN, ENDC
21-
from torchx.runner import Runner, get_runner
20+
from torchx.cli.colors import ENDC, GREEN
21+
from torchx.runner import get_runner, Runner
2222
from torchx.schedulers.api import Stream
23-
from torchx.specs.api import make_app_handle, is_started
23+
from torchx.specs.api import is_started, make_app_handle
2424

2525
logger: logging.Logger = logging.getLogger(__name__)
2626

torchx/cli/cmd_run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
from torchx.cli.argparse_util import CONFIG_DIRS, torchxconfig_run
2020
from torchx.cli.cmd_base import SubCommand
2121
from torchx.cli.cmd_log import get_logs
22-
from torchx.runner import Runner, config, get_runner
22+
from torchx.runner import config, get_runner, Runner
2323
from torchx.runner.config import load_sections
2424
from torchx.schedulers import get_default_scheduler_name, get_scheduler_factories
2525
from torchx.specs.finder import (
26+
_Component,
2627
ComponentNotFoundException,
2728
ComponentValidationException,
28-
_Component,
2929
get_builtin_source,
3030
get_components,
3131
)

torchx/cli/cmd_runopts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010

1111
from torchx.cli.cmd_base import SubCommand
12-
from torchx.cli.colors import GREEN, ENDC
12+
from torchx.cli.colors import ENDC, GREEN
1313
from torchx.runner.api import get_runner
1414

1515
logger: logging.Logger = logging.getLogger(__name__)

torchx/cli/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from torchx.cli.cmd_run import CmdBuiltins, CmdRun
1818
from torchx.cli.cmd_runopts import CmdRunopts
1919
from torchx.cli.cmd_status import CmdStatus
20-
from torchx.cli.colors import ENDC, GRAY, BLUE
20+
from torchx.cli.colors import BLUE, ENDC, GRAY
2121
from torchx.util.entrypoints import load_group
2222

2323

torchx/cli/test/cmd_log_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from typing import Iterator, Optional
1313
from unittest.mock import MagicMock, patch
1414

15-
from torchx.cli.cmd_log import ENDC, GREEN, get_logs, validate
15+
from torchx.cli.cmd_log import ENDC, get_logs, GREEN, validate
1616
from torchx.runner.api import Runner
1717
from torchx.schedulers.api import Stream
18-
from torchx.specs import AppDef, Role, parse_app_handle, AppStatus, AppState, AppHandle
18+
from torchx.specs import AppDef, AppHandle, AppState, AppStatus, parse_app_handle, Role
1919

2020

2121
class SentinelError(Exception):

torchx/cli/test/cmd_run_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Generator
1818
from unittest.mock import MagicMock, patch
1919

20-
from torchx.cli.cmd_run import CmdBuiltins, CmdRun, _parse_component_name_and_args
20+
from torchx.cli.cmd_run import _parse_component_name_and_args, CmdBuiltins, CmdRun
2121
from torchx.schedulers.local_scheduler import SignalException
2222

2323

torchx/cli/test/main_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import os
1010
import unittest
1111
from pathlib import Path
12-
from unittest.mock import patch, MagicMock
12+
from unittest.mock import MagicMock, patch
1313

1414
from torchx.cli.cmd_base import SubCommand
15-
from torchx.cli.main import main, get_sub_cmds
15+
from torchx.cli.main import get_sub_cmds, main
1616

1717

1818
_root: Path = Path(__file__).parent

torchx/components/integration_tests/integ_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dataclasses import asdict
1111
from json import dumps
1212
from types import ModuleType
13-
from typing import Callable, Dict, List, Type, cast
13+
from typing import Callable, cast, Dict, List, Type
1414

1515
from pyre_extensions import none_throws
1616
from torchx.cli.cmd_log import get_logs

torchx/examples/apps/lightning_classy_vision/component.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
import torchx
4040
import torchx.specs as specs
41-
from torchx.specs import Resource, macros, named_resources
41+
from torchx.specs import macros, named_resources, Resource
4242

4343

4444
# %%

torchx/examples/apps/lightning_classy_vision/data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import os.path
1616
import tarfile
17-
from typing import Optional, Callable
17+
from typing import Callable, Optional
1818

1919
import fsspec
2020
import numpy

torchx/examples/apps/lightning_classy_vision/interpret.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@
3333
sys.path.append(".")
3434

3535
from torchx.examples.apps.lightning_classy_vision.data import (
36-
TinyImageNetDataModule,
37-
download_data,
3836
create_random_data,
37+
download_data,
38+
TinyImageNetDataModule,
3939
)
4040
from torchx.examples.apps.lightning_classy_vision.model import TinyImageNetModel
4141

4242
# FIXME: captum must be imported after torch otherwise it causes python to crash
4343
if True:
4444
import numpy as np
45-
from captum.attr import IntegratedGradients
46-
from captum.attr import visualization as viz
45+
from captum.attr import IntegratedGradients, visualization as viz
4746

4847

4948
def parse_args(argv: List[str]) -> argparse.Namespace:

torchx/examples/apps/lightning_classy_vision/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
import os.path
1616
import subprocess
17-
from typing import Tuple, Optional, List
17+
from typing import List, Optional, Tuple
1818

1919
import fsspec
2020
import pytorch_lightning as pl
2121
import torch
2222
import torch.jit
2323
from torch.nn import functional as F
2424
from torchmetrics import Accuracy
25-
from torchvision.models.resnet import ResNet, BasicBlock
25+
from torchvision.models.resnet import BasicBlock, ResNet
2626

2727

2828
class TinyImageNetModel(pl.LightningModule):

torchx/examples/apps/lightning_classy_vision/test/model_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import unittest
88

99
import torch
10-
from torchx.examples.apps.lightning_classy_vision.model import (
11-
TinyImageNetModel,
12-
)
10+
from torchx.examples.apps.lightning_classy_vision.model import TinyImageNetModel
1311

1412

1513
class ModelTest(unittest.TestCase):

torchx/examples/apps/lightning_classy_vision/train.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
from pytorch_lightning.callbacks import ModelCheckpoint
2929
from pytorch_lightning.loggers import TensorBoardLogger
3030
from torchx.examples.apps.lightning_classy_vision.data import (
31-
TinyImageNetDataModule,
3231
create_random_data,
3332
download_data,
33+
TinyImageNetDataModule,
3434
)
3535
from torchx.examples.apps.lightning_classy_vision.model import (
36-
TinyImageNetModel,
3736
export_inference_model,
37+
TinyImageNetModel,
3838
)
3939
from torchx.examples.apps.lightning_classy_vision.profiler import SimpleLoggingProfiler
4040

torchx/pipelines/kfp/test/adapter_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os.path
99
import tempfile
1010
import unittest
11-
from typing import List, Callable
11+
from typing import Callable, List
1212

1313
import torchx
1414
import yaml

torchx/runner/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
from torchx.runner.api import Runner, get_runner # noqa: F401 F403
8+
from torchx.runner.api import get_runner, Runner # noqa: F401 F403

torchx/runner/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def my_component(a: int) -> specs.AppDef:
140140
from pathlib import Path
141141
from typing import Dict, Iterable, List, Optional, TextIO
142142

143-
from torchx.schedulers import Scheduler, get_schedulers
143+
from torchx.schedulers import get_schedulers, Scheduler
144144
from torchx.specs import CfgVal, get_type_name
145145
from torchx.specs.api import runopt
146146

torchx/runner/events/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dataclasses import asdict, dataclass
1010
from datetime import datetime
1111
from enum import Enum
12-
from typing import Optional, Union, TYPE_CHECKING
12+
from typing import Optional, TYPE_CHECKING, Union
1313

1414
if TYPE_CHECKING:
1515
from torch import monitor

torchx/runner/events/test/lib_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import logging
1010
import unittest
1111
from typing import List
12-
from unittest.mock import patch, MagicMock
12+
from unittest.mock import MagicMock, patch
1313

1414
from torchx.runner.events import (
1515
_get_or_create_logger,
16-
SourceType,
17-
TorchxEvent,
1816
log_event,
1917
record,
18+
SourceType,
19+
TorchxEvent,
2020
)
2121

2222
try:

torchx/runner/test/api_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from unittest.mock import MagicMock, patch
1515

1616
from pyre_extensions import none_throws
17-
from torchx.runner import Runner, get_runner
17+
from torchx.runner import get_runner, Runner
1818
from torchx.schedulers.api import DescribeAppResponse, Scheduler
1919
from torchx.schedulers.local_scheduler import (
2020
LocalDirectoryImageProvider,

torchx/runner/test/config_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
apply,
2020
dump,
2121
get_config,
22+
get_configs,
2223
load,
2324
load_sections,
24-
get_configs,
2525
)
26-
from torchx.schedulers import Scheduler, get_schedulers
26+
from torchx.schedulers import get_schedulers, Scheduler
2727
from torchx.schedulers.api import DescribeAppResponse, Stream
2828
from torchx.specs import AppDef, AppDryRunInfo, CfgVal, runopts
2929

torchx/schedulers/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from typing import Iterable, List, Mapping, Optional
1414

1515
from torchx.specs import (
16-
NONE,
17-
NULL_RESOURCE,
1816
AppDef,
1917
AppDryRunInfo,
2018
AppState,
2119
CfgVal,
20+
NONE,
21+
NULL_RESOURCE,
2222
Role,
2323
RoleStatus,
2424
runopts,

torchx/schedulers/aws_batch_scheduler.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,38 @@
3939
from dataclasses import dataclass
4040
from datetime import datetime
4141
from typing import (
42+
Any,
43+
Callable,
4244
Dict,
4345
Iterable,
4446
Mapping,
4547
Optional,
46-
Any,
47-
TYPE_CHECKING,
4848
Tuple,
49+
TYPE_CHECKING,
4950
TypeVar,
50-
Callable,
5151
)
5252

5353
import torchx
5454
import yaml
5555
from torchx.schedulers.api import (
5656
AppDryRunInfo,
5757
DescribeAppResponse,
58+
filter_regex,
5859
Scheduler,
5960
Stream,
60-
filter_regex,
6161
)
6262
from torchx.schedulers.devices import get_device_mounts
6363
from torchx.schedulers.ids import make_unique
6464
from torchx.specs.api import (
6565
AppDef,
6666
AppState,
67-
Role,
67+
BindMount,
68+
CfgVal,
69+
DeviceMount,
6870
macros,
71+
Role,
6972
runopts,
70-
CfgVal,
71-
BindMount,
7273
VolumeMount,
73-
DeviceMount,
7474
)
7575
from torchx.workspace.docker_workspace import DockerWorkspace
7676

torchx/schedulers/devices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77
import warnings
8-
from typing import Mapping, Callable, List, Dict
8+
from typing import Callable, Dict, List, Mapping
99

1010
from torchx.specs.api import DeviceMount
1111

0 commit comments

Comments
 (0)