From ffb52b256bfb934630dd9e0d0c7240f58998a7f6 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 17 Sep 2019 18:41:05 +0700 Subject: [PATCH] perf: do not import http.server each run It is only used in tests. --- dvc/utils/compat.py | 6 ------ tests/utils/httpd.py | 9 +++++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dvc/utils/compat.py b/dvc/utils/compat.py index f45becc9c..5b17c7708 100644 --- a/dvc/utils/compat.py +++ b/dvc/utils/compat.py @@ -103,8 +103,6 @@ def ignore_file_not_found(): if is_py2: from urlparse import urlparse, urlunparse, urljoin # noqa: F401 from urllib import urlencode # noqa: F401 - from BaseHTTPServer import HTTPServer # noqa: F401 - from SimpleHTTPServer import SimpleHTTPRequestHandler # noqa: F401 import ConfigParser # noqa: F401 from io import open # noqa: F401 import pathlib2 as pathlib # noqa: F401 @@ -150,10 +148,6 @@ elif is_py3: urljoin, # noqa: F401 ) from io import StringIO, BytesIO # noqa: F401 - from http.server import ( # noqa: F401 - HTTPServer, # noqa: F401 - SimpleHTTPRequestHandler, # noqa: F401 - ) # noqa: F401 import configparser as ConfigParser # noqa: F401 from collections.abc import Mapping # noqa: F401 diff --git a/tests/utils/httpd.py b/tests/utils/httpd.py index 6e90598c3..ff902e71a 100644 --- a/tests/utils/httpd.py +++ b/tests/utils/httpd.py @@ -2,9 +2,14 @@ import hashlib import os import threading -from RangeHTTPServer import RangeRequestHandler +# Moved in Python 2 -> 3, used only here. +# Not adding to dvc.utils.compat to not load http.server for non-test runs. +try: + from http.server import HTTPServer +except ImportError: + from BaseHTTPServer import HTTPServer -from dvc.utils.compat import HTTPServer +from RangeHTTPServer import RangeRequestHandler class TestRequestHandler(RangeRequestHandler):