test_files.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import contextlib
3 import os
4 import string
5 import subprocess
6 import sys
7 import tarfile
8 import zipfile
9 
10 # These tests must be run explicitly
11 # They require CMake 3.15+ (--install)
12 
13 DIR = os.path.abspath(os.path.dirname(__file__))
14 MAIN_DIR = os.path.dirname(os.path.dirname(DIR))
15 
16 
17 main_headers = {
18  "include/pybind11/attr.h",
19  "include/pybind11/buffer_info.h",
20  "include/pybind11/cast.h",
21  "include/pybind11/chrono.h",
22  "include/pybind11/common.h",
23  "include/pybind11/complex.h",
24  "include/pybind11/eigen.h",
25  "include/pybind11/embed.h",
26  "include/pybind11/eval.h",
27  "include/pybind11/functional.h",
28  "include/pybind11/iostream.h",
29  "include/pybind11/numpy.h",
30  "include/pybind11/operators.h",
31  "include/pybind11/options.h",
32  "include/pybind11/pybind11.h",
33  "include/pybind11/pytypes.h",
34  "include/pybind11/stl.h",
35  "include/pybind11/stl_bind.h",
36 }
37 
38 detail_headers = {
39  "include/pybind11/detail/class.h",
40  "include/pybind11/detail/common.h",
41  "include/pybind11/detail/descr.h",
42  "include/pybind11/detail/init.h",
43  "include/pybind11/detail/internals.h",
44  "include/pybind11/detail/typeid.h",
45 }
46 
47 cmake_files = {
48  "share/cmake/pybind11/FindPythonLibsNew.cmake",
49  "share/cmake/pybind11/pybind11Common.cmake",
50  "share/cmake/pybind11/pybind11Config.cmake",
51  "share/cmake/pybind11/pybind11ConfigVersion.cmake",
52  "share/cmake/pybind11/pybind11NewTools.cmake",
53  "share/cmake/pybind11/pybind11Targets.cmake",
54  "share/cmake/pybind11/pybind11Tools.cmake",
55 }
56 
57 py_files = {
58  "__init__.py",
59  "__main__.py",
60  "_version.py",
61  "commands.py",
62  "setup_helpers.py",
63 }
64 
65 headers = main_headers | detail_headers
66 src_files = headers | cmake_files
67 all_files = src_files | py_files
68 
69 
70 sdist_files = {
71  "pybind11",
72  "pybind11/include",
73  "pybind11/include/pybind11",
74  "pybind11/include/pybind11/detail",
75  "pybind11/share",
76  "pybind11/share/cmake",
77  "pybind11/share/cmake/pybind11",
78  "pyproject.toml",
79  "setup.cfg",
80  "setup.py",
81  "LICENSE",
82  "MANIFEST.in",
83  "README.md",
84  "PKG-INFO",
85 }
86 
87 local_sdist_files = {
88  ".egg-info",
89  ".egg-info/PKG-INFO",
90  ".egg-info/SOURCES.txt",
91  ".egg-info/dependency_links.txt",
92  ".egg-info/not-zip-safe",
93  ".egg-info/top_level.txt",
94 }
95 
96 
97 def test_build_sdist(monkeypatch, tmpdir):
98 
99  monkeypatch.chdir(MAIN_DIR)
100 
101  out = subprocess.check_output(
102  [
103  sys.executable,
104  "setup.py",
105  "sdist",
106  "--formats=tar",
107  "--dist-dir",
108  str(tmpdir),
109  ]
110  )
111  if hasattr(out, "decode"):
112  out = out.decode()
113 
114  (sdist,) = tmpdir.visit("*.tar")
115 
116  with tarfile.open(str(sdist)) as tar:
117  start = tar.getnames()[0] + "/"
118  version = start[9:-1]
119  simpler = set(n.split("/", 1)[-1] for n in tar.getnames()[1:])
120 
121  with contextlib.closing(
122  tar.extractfile(tar.getmember(start + "setup.py"))
123  ) as f:
124  setup_py = f.read()
125 
126  with contextlib.closing(
127  tar.extractfile(tar.getmember(start + "pyproject.toml"))
128  ) as f:
129  pyproject_toml = f.read()
130 
131  files = set("pybind11/{}".format(n) for n in all_files)
132  files |= sdist_files
133  files |= set("pybind11{}".format(n) for n in local_sdist_files)
134  files.add("pybind11.egg-info/entry_points.txt")
135  files.add("pybind11.egg-info/requires.txt")
136  assert simpler == files
137 
138  with open(os.path.join(MAIN_DIR, "tools", "setup_main.py.in"), "rb") as f:
139  contents = (
140  string.Template(f.read().decode())
141  .substitute(version=version, extra_cmd="")
142  .encode()
143  )
144  assert setup_py == contents
145 
146  with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
147  contents = f.read()
148  assert pyproject_toml == contents
149 
150 
151 def test_build_global_dist(monkeypatch, tmpdir):
152 
153  monkeypatch.chdir(MAIN_DIR)
154  monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")
155 
156  out = subprocess.check_output(
157  [
158  sys.executable,
159  "setup.py",
160  "sdist",
161  "--formats=tar",
162  "--dist-dir",
163  str(tmpdir),
164  ]
165  )
166  if hasattr(out, "decode"):
167  out = out.decode()
168 
169  (sdist,) = tmpdir.visit("*.tar")
170 
171  with tarfile.open(str(sdist)) as tar:
172  start = tar.getnames()[0] + "/"
173  version = start[16:-1]
174  simpler = set(n.split("/", 1)[-1] for n in tar.getnames()[1:])
175 
176  with contextlib.closing(
177  tar.extractfile(tar.getmember(start + "setup.py"))
178  ) as f:
179  setup_py = f.read()
180 
181  with contextlib.closing(
182  tar.extractfile(tar.getmember(start + "pyproject.toml"))
183  ) as f:
184  pyproject_toml = f.read()
185 
186  files = set("pybind11/{}".format(n) for n in all_files)
187  files |= sdist_files
188  files |= set("pybind11_global{}".format(n) for n in local_sdist_files)
189  assert simpler == files
190 
191  with open(os.path.join(MAIN_DIR, "tools", "setup_global.py.in"), "rb") as f:
192  contents = (
193  string.Template(f.read().decode())
194  .substitute(version=version, extra_cmd="")
195  .encode()
196  )
197  assert setup_py == contents
198 
199  with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
200  contents = f.read()
201  assert pyproject_toml == contents
202 
203 
204 def tests_build_wheel(monkeypatch, tmpdir):
205  monkeypatch.chdir(MAIN_DIR)
206 
207  subprocess.check_output(
208  [sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)]
209  )
210 
211  (wheel,) = tmpdir.visit("*.whl")
212 
213  files = set("pybind11/{}".format(n) for n in all_files)
214  files |= {
215  "dist-info/LICENSE",
216  "dist-info/METADATA",
217  "dist-info/RECORD",
218  "dist-info/WHEEL",
219  "dist-info/entry_points.txt",
220  "dist-info/top_level.txt",
221  }
222 
223  with zipfile.ZipFile(str(wheel)) as z:
224  names = z.namelist()
225 
226  trimmed = set(n for n in names if "dist-info" not in n)
227  trimmed |= set(
228  "dist-info/{}".format(n.split("/", 1)[-1]) for n in names if "dist-info" in n
229  )
230  assert files == trimmed
231 
232 
233 def tests_build_global_wheel(monkeypatch, tmpdir):
234  monkeypatch.chdir(MAIN_DIR)
235  monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")
236 
237  subprocess.check_output(
238  [sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)]
239  )
240 
241  (wheel,) = tmpdir.visit("*.whl")
242 
243  files = set("data/data/{}".format(n) for n in src_files)
244  files |= set("data/headers/{}".format(n[8:]) for n in headers)
245  files |= {
246  "dist-info/LICENSE",
247  "dist-info/METADATA",
248  "dist-info/WHEEL",
249  "dist-info/top_level.txt",
250  "dist-info/RECORD",
251  }
252 
253  with zipfile.ZipFile(str(wheel)) as z:
254  names = z.namelist()
255 
256  beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
257  trimmed = set(n[len(beginning) + 1 :] for n in names)
258 
259  assert files == trimmed
bool hasattr(handle obj, handle name)
Definition: pytypes.h:403
def test_build_global_dist(monkeypatch, tmpdir)
Definition: test_files.py:151
void split(const G &g, const PredecessorMap< KEY > &tree, G &Ab1, G &Ab2)
Definition: graph-inl.h:255
def tests_build_wheel(monkeypatch, tmpdir)
Definition: test_files.py:204
Definition: pytypes.h:928
def test_build_sdist(monkeypatch, tmpdir)
Definition: test_files.py:97
def tests_build_global_wheel(monkeypatch, tmpdir)
Definition: test_files.py:233
size_t len(handle h)
Definition: pytypes.h:1514
Definition: pytypes.h:1325


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:03