aboutsummaryrefslogtreecommitdiff
path: root/setup.py
blob: 064398cae353c8ecc2e5728fb7f7ce1886066234 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
from pathlib import Path
from setuptools import Command, setup
from setuptools.command.sdist import sdist
from setuptools.command.build import build


class SubmoduleMissingException(Exception):
    pass


class CustomSubmoduleCheck(Command):
    def initialize_options(self) -> None:
        pass

    def finalize_options(self) -> None:
        pass

    def run(self) -> None:
        efd_path = Path("pyecsca/ec/efd")
        if not list(efd_path.iterdir()):
            raise SubmoduleMissingException(
                "The EFD submodule of pyecsca is missing, did you initialize the git submodules?"
            )
        std_path = Path("pyecsca/ec/std")
        if not list(std_path.iterdir()):
            raise SubmoduleMissingException(
                "The std-curves submodule of pyecsca is missing, did you initialize the git submodules?"
            )


class CustomSdist(sdist):
    sub_commands = [("check_submodules", None)] + sdist.sub_commands


class CustomBuild(build):
    sub_commands = [("check_submodules", None)] + build.sub_commands


setup(
    cmdclass={
        "sdist": CustomSdist,
        "build": CustomBuild,
        "check_submodules": CustomSubmoduleCheck,
    }
)