Skip to content

File: Broken/Hatch.py

Broken.Hatch

BrokenHook

Bases: MetadataHookInterface

Source code in Broken/Hatch.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class BrokenHook(MetadataHookInterface):
    def update(self, metadata: dict) -> None:
        if (monorepo := os.environ.get("MONOREPO_ROOT")):
            monorepo = Path(monorepo)

            # Get the version from the main package
            exec((monorepo/"Broken"/"Version.py").read_text(), (ctx := {}))
            version = metadata["version"] = ctx["__version__"]

            # Replaces all list items inline
            def patch(items: list[str]) -> None:
                for (x, item) in enumerate(items):
                    item = item.replace("0.0.0", version)

                    # Pin versions on release binaries
                    if (os.environ.get("PYAPP_RELEASE", "0") == "1"):
                        item = item.replace("~=", "==")
                        item = item.replace(">=", "==")

                    items[x] = item

            # Patch all normal and optional dependencies
            list(map(patch, metadata.get("optional-dependencies", {}).values()))
            patch(metadata.get("dependencies", {}))

update

update(metadata: dict) -> None
Source code in Broken/Hatch.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def update(self, metadata: dict) -> None:
    if (monorepo := os.environ.get("MONOREPO_ROOT")):
        monorepo = Path(monorepo)

        # Get the version from the main package
        exec((monorepo/"Broken"/"Version.py").read_text(), (ctx := {}))
        version = metadata["version"] = ctx["__version__"]

        # Replaces all list items inline
        def patch(items: list[str]) -> None:
            for (x, item) in enumerate(items):
                item = item.replace("0.0.0", version)

                # Pin versions on release binaries
                if (os.environ.get("PYAPP_RELEASE", "0") == "1"):
                    item = item.replace("~=", "==")
                    item = item.replace(">=", "==")

                items[x] = item

        # Patch all normal and optional dependencies
        list(map(patch, metadata.get("optional-dependencies", {}).values()))
        patch(metadata.get("dependencies", {}))