forked from urllib3/urllib3
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hatch_build.py
34 lines (25 loc) · 1.31 KB
/
hatch_build.py
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
30
31
32
33
34
from __future__ import annotations
from os import environ, path
from shutil import copytree, rmtree
from typing import Any
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
SHOULD_PREVENT_FORK_OVERRIDE = environ.get("URLLIB3_NO_OVERRIDE", None) == "true"
class CustomBuildHook(BuildHookInterface):
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
#: Clean-up in case of previously missed proper exit
if path.exists("./src/urllib3_future"):
rmtree("./src/urllib3_future")
#: Copying the main package and duplicate it. Provide an escape hatch.
copytree("./src/urllib3", "./src/urllib3_future")
#: Aimed at OS package manager, so that they don't override accidentally urllib3.
if SHOULD_PREVENT_FORK_OVERRIDE and path.exists("./src/urllib3"):
rmtree("./src/urllib3")
def finalize(
self, version: str, build_data: dict[str, Any], artifact_path: str
) -> None:
#: We shall restore the original package before exiting
if SHOULD_PREVENT_FORK_OVERRIDE and not path.exists("./src/urllib3"):
copytree("./src/urllib3_future", "./src/urllib3")
#: Removing the temporary duplicate
if path.exists("./src/urllib3_future"):
rmtree("./src/urllib3_future")