Coverage for /pythoncovmergedfiles/medio/medio/src/python-crc32c/src/google_crc32c/__config__.py: 29%

21 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 07:01 +0000

1# Copyright 2018 Google LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# https://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15import os 

16import sys 

17 

18 

19def modify_path(): 

20 """Modify the module search path.""" 

21 # Only modify path on Windows. 

22 if os.name != "nt": 

23 return 

24 

25 path = os.environ.get("PATH") 

26 if path is None: 

27 return 

28 

29 try: 

30 try: 

31 # Python 3.9+ 

32 from importlib.resources import files as _resources_files 

33 except ImportError: 

34 # Python 3.7 & 3.8 

35 from importlib_resources import files as _resources_files # type: ignore 

36 extra_dll_dir = str(_resources_files("google_crc32c") / "extra-dll") 

37 if os.path.isdir(extra_dll_dir): 

38 # Python 3.7 use path 

39 os.environ["PATH"] = path + os.pathsep + extra_dll_dir 

40 # Python 3.8+ uses add_dll_directory. 

41 if sys.version_info[0] == 3 and sys.version_info[1] >= 8: 

42 os.add_dll_directory(extra_dll_dir) 

43 except ImportError: 

44 pass 

45 

46modify_path()