diff --git a/build/fbcode_builder/getdeps/fetcher.py b/build/fbcode_builder/getdeps/fetcher.py index d2fb9f7da1..1bd0d78d86 100644 --- a/build/fbcode_builder/getdeps/fetcher.py +++ b/build/fbcode_builder/getdeps/fetcher.py @@ -28,8 +28,8 @@ from .runcmd import run_cmd try: - from urlparse import urlparse from urllib import urlretrieve + from urlparse import urlparse except ImportError: from urllib.parse import urlparse from urllib.request import urlretrieve diff --git a/eden/fs/cli/overlay.py b/eden/fs/cli/overlay.py index 8d41f3e88f..1ffbc187f0 100644 --- a/eden/fs/cli/overlay.py +++ b/eden/fs/cli/overlay.py @@ -218,8 +218,8 @@ class Overlay: return (header, self.parse_dir_inode_data(data)) def parse_dir_inode_data(self, data: bytes) -> OverlayDir: - from thrift.util import Serializer from thrift.protocol import TCompactProtocol + from thrift.util import Serializer # Initialize entries to the empty dictionary. # This value will be used if the serialized data does not have any value @@ -388,8 +388,8 @@ class Overlay: self._write_inode(inode_number, OverlayHeader.TYPE_FILE, b"") def write_empty_dir(self, inode_number: int) -> None: - from thrift.util import Serializer from thrift.protocol import TCompactProtocol + from thrift.util import Serializer empty_tree = OverlayDir() protocol_factory = TCompactProtocol.TCompactProtocolFactory() diff --git a/eden/integration/lib/service_test_case.py b/eden/integration/lib/service_test_case.py index 356d2a483c..da45913b9a 100644 --- a/eden/integration/lib/service_test_case.py +++ b/eden/integration/lib/service_test_case.py @@ -20,9 +20,10 @@ from .testcase import test_replicator if sys.platform.startswith("linux"): - from .systemd import SystemdService, SystemdUserServiceManager, temp_systemd from eden.fs.cli.systemd import edenfs_systemd_service_name + from .systemd import SystemdService, SystemdUserServiceManager, temp_systemd + try: import pystemd # noqa: F401 diff --git a/eden/mononoke/tests/integration/integration_runner_real.py b/eden/mononoke/tests/integration/integration_runner_real.py index c827e249f3..48882ba35a 100644 --- a/eden/mononoke/tests/integration/integration_runner_real.py +++ b/eden/mononoke/tests/integration/integration_runner_real.py @@ -406,10 +406,10 @@ def run( ): manifest = os.path.abspath(manifest) if is_libfb_present(): - from libfb.py.log import set_simple_logging from eden.mononoke.tests.integration.facebook.lib_runner import ( load_manifest_env, ) + from libfb.py.log import set_simple_logging set_simple_logging(logging.INFO) manifest_env: ManifestEnv = load_manifest_env(manifest) diff --git a/eden/scm/contrib/perf.py b/eden/scm/contrib/perf.py index 108ace97c0..5d09a6f624 100644 --- a/eden/scm/contrib/perf.py +++ b/eden/scm/contrib/perf.py @@ -174,8 +174,8 @@ else: try: - import edemscm.mercurial.registrar import edemscm.mercurial.configitems + import edemscm.mercurial.registrar import edenscm.mercurial as mercurial configtable = {} @@ -444,8 +444,8 @@ def perfdatapack(ui, repo, packpath, **opts): def _packtestfn(ui, packpath, opts, func): - from edenscm.hgext.remotefilelog.datapack import datapack, fastdatapack from bindings import revisionstore + from edenscm.hgext.remotefilelog.datapack import datapack, fastdatapack kinds = [ ("Python", datapack), diff --git a/eden/scm/edenscm/__init__.py b/eden/scm/edenscm/__init__.py index 5be9be105c..f8d30c074f 100644 --- a/eden/scm/edenscm/__init__.py +++ b/eden/scm/edenscm/__init__.py @@ -12,9 +12,10 @@ def _fixsys(): Fix sys.stdin if it's None. """ + import os + # Do not expose those modules to edenscm.__dict__ import sys - import os dirname = os.path.dirname diff --git a/eden/scm/edenscm/hgext/commitcloud/httpsservice.py b/eden/scm/edenscm/hgext/commitcloud/httpsservice.py index 99825bedb0..b1a95992df 100644 --- a/eden/scm/edenscm/hgext/commitcloud/httpsservice.py +++ b/eden/scm/edenscm/hgext/commitcloud/httpsservice.py @@ -10,12 +10,11 @@ import gzip import os import socket import ssl -import time import tempfile +import time from multiprocessing.pool import ThreadPool from subprocess import PIPE, Popen - from edenscm.mercurial import error, json, perftrace, pycompat, util, commands from edenscm.mercurial.i18n import _ diff --git a/eden/scm/edenscm/hgext/convert/subversion.py b/eden/scm/edenscm/hgext/convert/subversion.py index be921a3084..e61dd62827 100644 --- a/eden/scm/edenscm/hgext/convert/subversion.py +++ b/eden/scm/edenscm/hgext/convert/subversion.py @@ -42,6 +42,8 @@ NoRepo = common.NoRepo # these bindings. try: + import warnings + # pyre-fixme[21]: Could not find `svn`. import svn @@ -51,13 +53,13 @@ try: # pyre-fixme[21]: Could not find module `svn.core`. import svn.core + # pyre-fixme[21]: Could not find module `svn.delta`. + import svn.delta + # pyre-fixme[21]: Could not find module `svn.ra`. import svn.ra - # pyre-fixme[21]: Could not find module `svn.delta`. - import svn.delta from . import transport - import warnings warnings.filterwarnings("ignore", module="svn.core", category=DeprecationWarning) svn.core.SubversionException # trigger import to catch error diff --git a/eden/scm/edenscm/hgext/debugshell.py b/eden/scm/edenscm/hgext/debugshell.py index 7b4b02d49b..a15e4de136 100644 --- a/eden/scm/edenscm/hgext/debugshell.py +++ b/eden/scm/edenscm/hgext/debugshell.py @@ -116,8 +116,8 @@ def debugshell(ui, repo, *args, **opts): def _startipython(ui, repo): - from IPython.terminal.ipapp import load_default_config from IPython.terminal.embed import InteractiveShellEmbed + from IPython.terminal.ipapp import load_default_config bannermsg = "loaded repo: %s\n" "using source: %s" % ( repo and repo.root or "(none)", diff --git a/eden/scm/edenscm/mercurial/pycompat.py b/eden/scm/edenscm/mercurial/pycompat.py index cc79792f26..3ef0294b6a 100644 --- a/eden/scm/edenscm/mercurial/pycompat.py +++ b/eden/scm/edenscm/mercurial/pycompat.py @@ -30,17 +30,13 @@ ispypy = r"__pypy__" in sys.builtin_module_names if sys.version_info[0] < 3: import cookielib - import cPickle as pickle - import httplib - import Queue as _queue - import SocketServer as socketserver else: - import http.cookiejar as cookielib # noqa: F401 import http.client as httplib # noqa: F401 + import http.cookiejar as cookielib # noqa: F401 import pickle # noqa: F401 import queue as _queue import socketserver # noqa: F401 diff --git a/eden/scm/edenscm/mercurial/urllibcompat.py b/eden/scm/edenscm/mercurial/urllibcompat.py index 080bc76a14..6f86c18838 100644 --- a/eden/scm/edenscm/mercurial/urllibcompat.py +++ b/eden/scm/edenscm/mercurial/urllibcompat.py @@ -133,14 +133,10 @@ if sys.version_info[0] >= 3: else: import BaseHTTPServer - import CGIHTTPServer - import SimpleHTTPServer - - import urllib2 import urllib - + import urllib2 import urlparse urlreq._registeraliases( diff --git a/eden/scm/i18n/check-translation.py b/eden/scm/i18n/check-translation.py index de8a24a0b6..830f0d0874 100755 --- a/eden/scm/i18n/check-translation.py +++ b/eden/scm/i18n/check-translation.py @@ -214,8 +214,8 @@ def check(pofile, fatal=True, warning=False): ######################################## if __name__ == "__main__": - import sys import optparse + import sys optparser = optparse.OptionParser( """%prog [options] pofile ... diff --git a/eden/scm/setup.py b/eden/scm/setup.py index 093e29d7ab..a960754732 100644 --- a/eden/scm/setup.py +++ b/eden/scm/setup.py @@ -18,6 +18,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function + import contextlib import ctypes import ctypes.util @@ -160,12 +161,10 @@ else: ispypy = "PyPy" in sys.version -from distutils.core import setup +import distutils +from distutils import file_util from distutils import log from distutils.ccompiler import new_compiler -from distutils.core import Command, Extension -from distutils.dir_util import copy_tree -from distutils.dist import Distribution from distutils.command.build import build from distutils.command.build_ext import build_ext from distutils.command.build_py import build_py @@ -173,13 +172,16 @@ from distutils.command.build_scripts import build_scripts from distutils.command.install import install from distutils.command.install_lib import install_lib from distutils.command.install_scripts import install_scripts -from distutils.spawn import spawn, find_executable -from distutils import file_util +from distutils.core import Command, Extension +from distutils.core import setup +from distutils.dir_util import copy_tree +from distutils.dist import Distribution from distutils.errors import CCompilerError, DistutilsError, DistutilsExecError +from distutils.spawn import spawn, find_executable from distutils.sysconfig import get_config_var from distutils.version import StrictVersion + from distutils_rust import RustBinary, BuildRustExt, InstallRustExt -import distutils havefb = os.path.exists("fb") isgetdepsbuild = os.environ.get("GETDEPS_BUILD") == "1" diff --git a/eden/scm/setup3.py b/eden/scm/setup3.py index f6e88ad329..f490f64e17 100644 --- a/eden/scm/setup3.py +++ b/eden/scm/setup3.py @@ -96,12 +96,10 @@ def filter(f, it): ispypy = "PyPy" in sys.version -from distutils.core import setup +import distutils +from distutils import file_util from distutils import log from distutils.ccompiler import new_compiler -from distutils.core import Command, Extension -from distutils.dir_util import copy_tree -from distutils.dist import Distribution from distutils.command.build import build from distutils.command.build_ext import build_ext from distutils.command.build_py import build_py @@ -109,13 +107,16 @@ from distutils.command.build_scripts import build_scripts from distutils.command.install import install from distutils.command.install_lib import install_lib from distutils.command.install_scripts import install_scripts -from distutils.spawn import spawn, find_executable -from distutils import file_util +from distutils.core import Command, Extension +from distutils.core import setup +from distutils.dir_util import copy_tree +from distutils.dist import Distribution from distutils.errors import CCompilerError, DistutilsError, DistutilsExecError +from distutils.spawn import spawn, find_executable from distutils.sysconfig import get_config_var from distutils.version import StrictVersion + from distutils_rust import RustBinary, BuildRustExt, InstallRustExt -import distutils havefb = os.path.exists("fb") isgetdepsbuild = os.environ.get("GETDEPS_BUILD") == "1" diff --git a/eden/scm/tests/hghave.py b/eden/scm/tests/hghave.py index 122c1ccc9e..eb2416ffd2 100644 --- a/eden/scm/tests/hghave.py +++ b/eden/scm/tests/hghave.py @@ -587,6 +587,7 @@ def has_defaultcacerts(): @check("defaultcacertsloaded", "detected presence of loaded system CA certs") def has_defaultcacertsloaded(): import ssl + from edenscm.mercurial import sslutil, ui as uimod if not has_defaultcacerts(): diff --git a/eden/scm/tests/run-tests.py b/eden/scm/tests/run-tests.py index e60b476d72..880e261634 100755 --- a/eden/scm/tests/run-tests.py +++ b/eden/scm/tests/run-tests.py @@ -121,11 +121,11 @@ pygmentspresent = False if os.name != "nt": try: # is pygments installed import pygments - import pygments.lexers as lexers - import pygments.lexer as lexer import pygments.formatters as formatters - import pygments.token as token + import pygments.lexer as lexer + import pygments.lexers as lexers import pygments.style as style + import pygments.token as token pygmentspresent = True difflexer = lexers.DiffLexer() diff --git a/eden/scm/tests/sitecustomize.py b/eden/scm/tests/sitecustomize.py index fa0f794fc5..291aa9072f 100644 --- a/eden/scm/tests/sitecustomize.py +++ b/eden/scm/tests/sitecustomize.py @@ -5,9 +5,10 @@ import os if os.environ.get("COVERAGE_PROCESS_START"): try: - import coverage import uuid + import coverage + covpath = os.path.join(os.environ["COVERAGE_DIR"], "cov.%s" % uuid.uuid1()) cov = coverage.coverage(data_file=covpath, auto_data=True) cov._warn_no_data = False diff --git a/eden/scm/tests/test-command-template-t.py b/eden/scm/tests/test-command-template-t.py index 6c88879988..2d2218051b 100644 --- a/eden/scm/tests/test-command-template-t.py +++ b/eden/scm/tests/test-command-template-t.py @@ -13,12 +13,11 @@ import os import sys import warnings +from edenscm.mercurial import namespaces from edenscm.mercurial import pycompat from testutil.autofix import eq from testutil.dott import feature, sh, testtmp # noqa: F401 -from edenscm.mercurial import namespaces - is_py3 = sys.version_info[0] >= 3 sh % "setconfig 'extensions.treemanifest=!'" diff --git a/eden/scm/tests/test-demandimport.py b/eden/scm/tests/test-demandimport.py index 57f09d05cb..02b3947544 100644 --- a/eden/scm/tests/test-demandimport.py +++ b/eden/scm/tests/test-demandimport.py @@ -9,6 +9,7 @@ demandimport.enable() import os import subprocess import sys + from hghave import require require(["py2"]) diff --git a/eden/scm/tests/test-revset-age-t.py b/eden/scm/tests/test-revset-age-t.py index 6419f5b72f..a678d51d51 100644 --- a/eden/scm/tests/test-revset-age-t.py +++ b/eden/scm/tests/test-revset-age-t.py @@ -6,11 +6,10 @@ from __future__ import absolute_import -from testutil.dott import feature, sh, testtmp # noqa: F401 +import time from edenscm.mercurial.extensions import wrappedfunction - -import time +from testutil.dott import feature, sh, testtmp # noqa: F401 # Setup repo diff --git a/eden/scm/tests/testutil/dott/shlib/__init__.py b/eden/scm/tests/testutil/dott/shlib/__init__.py index 1a4147a076..b031be26db 100644 --- a/eden/scm/tests/testutil/dott/shlib/__init__.py +++ b/eden/scm/tests/testutil/dott/shlib/__init__.py @@ -52,8 +52,8 @@ def editsyspath(modname, relpaths): # Soon, the only way to run this script is to via "hg debugpython" and # all sys.path mess can be removed. try: - from edenscmnative import diffhelpers from edenscm import mercurial + from edenscmnative import diffhelpers except (AttributeError, ImportError): editsyspath("edenscm", ["..", "../../.."]) @@ -72,8 +72,8 @@ if DUMMYSSH is None: try: - from edenscm.mercurial import encoding, util, pycompat import bindings + from edenscm.mercurial import encoding, util, pycompat except ImportError: raise RuntimeError("Cannot find edenscm")