|
16 | 16 | import sys
|
17 | 17 | import platform
|
18 | 18 | import subprocess
|
19 |
| -import unittest |
20 | 19 | import tempfile
|
21 | 20 | import shutil
|
22 | 21 |
|
@@ -46,23 +45,30 @@ def join_args(args):
|
46 | 45 | return ' '.join(map(shlex.quote, args))
|
47 | 46 |
|
48 | 47 |
|
49 |
| -class CMakeExtension(Extension): |
50 |
| - def __init__(self, name): |
51 |
| - Extension.__init__(self, name, sources=[]) |
52 |
| - |
53 |
| - |
54 | 48 | class OTIO_build_ext(setuptools.command.build_ext.build_ext):
|
55 | 49 | """
|
56 | 50 | def initialize_options(self):
|
57 | 51 | super(setuptools.command.build_ext.build_ext, self).initialize_options()
|
58 | 52 | """
|
59 | 53 |
|
| 54 | + built = False |
| 55 | + |
60 | 56 | def run(self):
|
61 |
| - # This works around the fact that we build _opentime and _otio |
62 |
| - # extensions as a one-shot cmake invocation. Usually we'd build each |
63 |
| - # separately using build_extension. |
64 | 57 | self.announce('running OTIO build_ext', level=2)
|
65 |
| - self.build() |
| 58 | + # Let the original build_ext class do its job. |
| 59 | + # This is rather important because build_ext.run takes care of a |
| 60 | + # couple of things, one of which is to copy the built files into |
| 61 | + # the source tree (in src/py-opentimelineio/opentimelineio) |
| 62 | + # when building in editable mode. |
| 63 | + super().run() |
| 64 | + |
| 65 | + def build_extension(self, _ext: Extension): |
| 66 | + # This works around the fact that we build _opentime and _otio |
| 67 | + # extensions as a one-shot cmake invocation. Setuptools calls |
| 68 | + # build_extension for each Extension registered in the setup function. |
| 69 | + if not self.built: |
| 70 | + self.build() |
| 71 | + self.built = True |
66 | 72 |
|
67 | 73 | def build(self):
|
68 | 74 | self.build_temp_dir = (
|
@@ -256,22 +262,17 @@ class OTIO_build_py(setuptools.command.build_py.build_py):
|
256 | 262 | """Stamps PROJECT_METADATA into __init__ files."""
|
257 | 263 |
|
258 | 264 | def run(self):
|
259 |
| - setuptools.command.build_py.build_py.run(self) |
260 |
| - |
261 |
| - if not self.dry_run: |
| 265 | + super().run() |
| 266 | + |
| 267 | + if not self.dry_run and not self.editable_mode: |
| 268 | + # Only run when not in dry-mode (a dry run should not have any side effect) |
| 269 | + # and in non-editable mode. We don't want to edit files when in editable |
| 270 | + # mode because that could lead to modifications to the source files. |
| 271 | + # Note that setuptools will set self.editable_mode to True |
| 272 | + # when "pip install -e ." is run. |
262 | 273 | _append_version_info_to_init_scripts(self.build_lib)
|
263 | 274 |
|
264 | 275 |
|
265 |
| -def test_otio(): |
266 |
| - """Discovers and runs tests""" |
267 |
| - try: |
268 |
| - # Clear the environment of a preset media linker |
269 |
| - del os.environ['OTIO_DEFAULT_MEDIA_LINKER'] |
270 |
| - except KeyError: |
271 |
| - pass |
272 |
| - return unittest.TestLoader().discover('tests') |
273 |
| - |
274 |
| - |
275 | 276 | # copied from first paragraph of README.md
|
276 | 277 | LONG_DESCRIPTION = """OpenTimelineIO is an interchange format and API for
|
277 | 278 | editorial cut information. OTIO is not a container format for media, rather it
|
@@ -339,8 +340,13 @@ def test_otio():
|
339 | 340 | ),
|
340 | 341 |
|
341 | 342 | ext_modules=[
|
342 |
| - CMakeExtension('_opentimelineio'), |
343 |
| - CMakeExtension('_opentime'), |
| 343 | + # The full and correct module name is required here because |
| 344 | + # setuptools needs to resolve the name to find the built file |
| 345 | + # and copy it into the source tree. (Because yes, editable install |
| 346 | + # means that the install should point to the source tree, which |
| 347 | + # means the .sos need to also be there alongside the python files). |
| 348 | + Extension('opentimelineio._otio', sources=[]), |
| 349 | + Extension('opentimelineio._opentime', sources=[]), |
344 | 350 | ],
|
345 | 351 |
|
346 | 352 | package_dir={
|
@@ -382,8 +388,6 @@ def test_otio():
|
382 | 388 | ]
|
383 | 389 | },
|
384 | 390 |
|
385 |
| - test_suite='setup.test_otio', |
386 |
| - |
387 | 391 | # because we need to open() the adapters manifest, we aren't zip-safe
|
388 | 392 | zip_safe=False,
|
389 | 393 |
|
|
0 commit comments