1# Licensed under the Apache License, Version 2.0 (the "License"); 2# you may not use this file except in compliance with the License. 3# You may obtain a copy of the License at 4# 5# http://www.apache.org/licenses/LICENSE-2.0 6# 7# Unless required by applicable law or agreed to in writing, software 8# distributed under the License is distributed on an "AS IS" BASIS, 9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10# See the License for the specific language governing permissions and 11# limitations under the License. 12 13"""Imports external packages that replace or emulate internal packages. 14If the external module is not present, the build-in module is imported. 15""" 16 17try: 18 import pathlib2 19except ImportError: 20 pathlib2 = None 21 22try: 23 import scandir 24 25 use_scandir_package = True 26 use_builtin_scandir = False 27except ImportError: 28 try: 29 from os import scandir # noqa: F401 30 31 use_builtin_scandir = True 32 use_scandir_package = False 33 except ImportError: 34 use_builtin_scandir = False 35 use_scandir_package = False 36 37use_scandir = use_scandir_package or use_builtin_scandir 38