• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
19
20    pathlib = pathlib2
21except ImportError:
22    pathlib2 = None
23
24    try:
25        import pathlib
26    except ImportError:
27        pathlib = None
28
29try:
30    import scandir
31
32    use_scandir_package = True
33    use_builtin_scandir = False
34except ImportError:
35    try:
36        from os import scandir  # noqa: F401
37
38        use_builtin_scandir = True
39        use_scandir_package = False
40    except ImportError:
41        use_builtin_scandir = False
42        use_scandir_package = False
43
44use_scandir = use_scandir_package or use_builtin_scandir
45