30 Shim interface for python wheel setup
33 from setuptools.command.build_py
import build_py
as _build_py
34 from setuptools.command.egg_info
import egg_info
as _egg_info
35 from wheel.bdist_wheel
import bdist_wheel
as _bdist_wheel
37 class build_py(_build_py):
39 Compatibility shim for build_py
41 def initialize_options(self):
43 Shim interface for all options
46 _build_py.initialize_options(self)
50 wc = self.get_finalized_command(
"bdist_wheel", 0)
51 self.exclude_source_files = wc
and wc.exclude_source_files
52 self.bdist_wheel =
True
54 self.bdist_wheel =
False
55 self.exclude_source_files =
False
57 def finalize_options(self):
59 Shim interface to finalize all inputs
62 if self.exclude_source_files:
66 _build_py.finalize_options(self)
68 def byte_compile(self, files):
70 Shim interface for class attribute byte_compile
73 if self.exclude_source_files:
75 if os.path.isfile(file):
78 log.info(
'removing source file %s', file)
81 else: _build_py.byte_compile(self, files)
85 Shim interface to execute the process
87 if not self.bdist_wheel
and not self.exclude_source_files:
88 command = [sys.executable,
"setup.py",
"bdist_wheel"]
89 if kwargs.get(
"platform_tag",
False): command.append(
"--platform-tag")
90 if kwargs.get(
"exclude_source_files",
False): command.append(
"--exclude-source-files")
92 subprocess.check_call(command)
97 class bdist_wheel(_bdist_wheel):
99 Compatibility shim for bdist_wheel
102 _bdist_wheel.user_options.append((
'exclude-source-files',
None,
"Remove all .py files from the generated wheel"))
103 _bdist_wheel.user_options.append((
'platform-tag',
None,
"Enforce the creation of a platform-tag"))
105 def initialize_options(self):
107 Shim interface for all options
110 _bdist_wheel.initialize_options(self)
112 self.python_tag =
None
113 self.exclude_source_files =
False
114 self.platform_tag =
False
116 def finalize_options(self):
118 Shim interface to finalize all inputs
121 _bdist_wheel.finalize_options(self)
123 self.python_tag = kwargs.get(
"python_tag",
"py2.py3")
125 if self.python_tag
in [
None,
"py2.py3"]: self.root_is_pure =
True
129 Shim interface to execute the process
132 _bdist_wheel.run(self)
135 if self.platform_tag:
137 platform_tag = re.sub(
r'[^0-9a-zA-Z]+',
'_', util.get_platform())
138 build_wheel = [os.path.join(os.getcwd(),
"dist",x)
for x
in os.listdir(os.path.join(os.getcwd(),
"dist"))
if x.endswith(
".whl")][-1]
139 subprocess.check_call([sys.executable,
"-m",
"wheel",
"tags",
"--platform-tag", platform_tag, build_wheel])
141 os.remove(os.path.join(os.getcwd(),
"dist",build_wheel))
144 if os.getenv(
"pyx_poetry_main_pid",
""):
146 os.remove(os.path.join(os.getcwd(),
"setup.py"))
147 os.kill(int(os.getenv(
"pyx_poetry_main_pid")), getattr(signal,
"CTRL_C_EVENT",signal.SIGTERM))
150 class egg_info(_egg_info):
152 Compatibility shim for egg_info
156 Shim interface to execute the process
162 nl = os.path.join(self.egg_info,
"top_level.txt")
163 if os.path.exists(nl): self.delete_file(nl)
166 if args: settings = args[-1]
169 settings.update({
"setup_requires":[
'wheel>=0.30;python_version>="2.7"',
'wheel==0.29;python_version<"2.7"'],
170 "cmdclass":{
"bdist_wheel": bdist_wheel,
"build_py": build_py,
"egg_info": egg_info}})
173 from poetry.console.application
import Application
174 configuration = Application().poetry.local_config
175 except (ImportError, RuntimeError)
as _: configuration = {}
178 description = configuration.get(
"readme",[])
180 if ((isinstance(description,str)
and description.endswith(
".md"))
or
181 any(x.endswith(
".md")
for x
in description)):
182 settings.update({
"long_description_content_type":
"text/markdown"})
184 else: settings.update({
"long_description_content_type":
"text/x-rst"})
187 include_keys = [
"classifiers",
"keywords",
"urls",
"repository",
"documentation"]
188 settings.update({k: v
for k, v
in configuration.items()
if k
in include_keys})
190 urls = settings.pop(
"urls",{});
191 urls.update({k.title(): v
for k, v
in settings.items()
if k
in [
"repository",
"documentation"]})
192 _ = [settings.pop(k,
None)
for k
in [
"repository",
"documentation"]]
194 settings.update({
"project_urls":urls})
197 exclude_keys = [
"python_tag",
"platform_tag",
"exclude_source_files"]
198 settings.update({k: kwargs[k]
for k
in set(list(kwargs.keys())) - set(exclude_keys)})
202 if settings.get(
"maintainer",
"")
and settings.get(
"maintainer",
"")
in [
"None"]:
203 settings.pop(
"maintainer"); settings.pop(
"maintainer_email")
207 try: settings.pop(
"py_modules")
211 if not os.getenv(
"pyx_poetry_main_pid",
""): os.environ[
"pyx_poetry_main_pid"] = str(os.getppid())