-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
65 lines (49 loc) · 1.67 KB
/
setup.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
from contextlib import suppress
from pathlib import Path
from setuptools import Command, setup
from setuptools.command.build import build
class CustomCommand(Command):
def initialize_options(self) -> None:
self.bdist_dir = None
def finalize_options(self) -> None:
with suppress(Exception):
self.bdist_dir = Path(self.get_finalized_command("bdist_wheel").bdist_dir)
def run(self) -> None:
if self.bdist_dir:
root_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, root_dir)
from tasks import generator
self.bdist_dir.mkdir(parents=True, exist_ok=True)
generator.main()
class CustomBuild(build):
sub_commands = [("build_custom", None), *build.sub_commands] # noqa: RUF012
options = {}
if os.environ.get("REGENERATE_PARSER"):
cmdclass = {"build": CustomBuild, "build_custom": CustomCommand}
options["cmdclass"] = cmdclass
if os.environ.get("COMPILE_WITH_MYPYC"):
from mypyc.build import mypycify
options["ext_modules"] = mypycify(
[
"peg_parser/tokenize.py",
"peg_parser/tokenizer.py",
"peg_parser/subheader.py",
"peg_parser/parser.py",
]
)
if os.environ.get("COMPILE_WITH_CYTHON"):
from Cython.Build import cythonize
options["ext_modules"] = cythonize(
[
"peg_parser/tokenize.py",
"peg_parser/tokenizer.py",
"peg_parser/subheader.py",
"peg_parser/parser.py",
],
show_all_warnings=True,
annotate=True,
compiler_directives={"language_level": "3"},
)
setup(**options)