-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitecustomize.py
More file actions
29 lines (21 loc) · 879 Bytes
/
sitecustomize.py
File metadata and controls
29 lines (21 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Repo-local Python startup shim for broken PlatformIO penv installs.
This project is sometimes opened with a PlatformIO virtualenv missing the
top-level ``requests`` package even though pip's vendored copy is present.
Python imports ``sitecustomize`` automatically on startup when it exists on
``sys.path``; because the project root is on ``sys.path`` for local commands,
we can map the missing imports before PlatformIO initializes.
"""
from __future__ import annotations
import importlib
import sys
def _alias_package(name: str, vendor_name: str) -> None:
if name in sys.modules:
return
try:
importlib.import_module(name)
return
except ModuleNotFoundError:
pass
sys.modules[name] = importlib.import_module(vendor_name)
_alias_package("requests", "pip._vendor.requests")
_alias_package("certifi", "pip._vendor.certifi")