-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
67 lines (49 loc) · 1.67 KB
/
setup.py
File metadata and controls
67 lines (49 loc) · 1.67 KB
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
66
67
import atexit
import shutil
import sys
import tempfile
from setuptools import setup
from setuptools.command.build import build
from setuptools.command.build_ext import build_ext
from setuptools.command.build_py import build_py
from setuptools.command.egg_info import egg_info
# Create a single temp directory for all build operations
_TEMP_BUILD_DIR = None
def get_temp_build_dir(pkg_name):
global _TEMP_BUILD_DIR
if _TEMP_BUILD_DIR is None:
_TEMP_BUILD_DIR = tempfile.mkdtemp(prefix=f"{pkg_name}_build_")
atexit.register(lambda: shutil.rmtree(_TEMP_BUILD_DIR, ignore_errors=True))
return _TEMP_BUILD_DIR
class TempDirBuildMixin:
def initialize_options(self):
super().initialize_options()
temp_dir = get_temp_build_dir(self.distribution.get_name())
self.build_base = temp_dir
class TempDirEggInfoMixin:
def initialize_options(self):
super().initialize_options()
temp_dir = get_temp_build_dir(self.distribution.get_name())
self.egg_base = temp_dir
class CustomBuild(TempDirBuildMixin, build):
pass
class CustomBuildPy(TempDirBuildMixin, build_py):
pass
class CustomBuildExt(TempDirBuildMixin, build_ext):
pass
class CustomEggInfo(TempDirEggInfoMixin, egg_info):
def initialize_options(self):
# Don't use temp dir for editable installs
if "--editable" in sys.argv or "-e" in sys.argv:
egg_info.initialize_options(self)
else:
super().initialize_options()
setup(
name="finecode",
cmdclass={
"build": CustomBuild,
"build_py": CustomBuildPy,
"build_ext": CustomBuildExt,
"egg_info": CustomEggInfo,
},
)