Skip to content

Commit

Permalink
[python]: Improve build error message when building non-fabricated pa…
Browse files Browse the repository at this point in the history
…ckage

Instead of outputting a ModuleNotFoundError when attempting to build the
cocoex Python package without running `scripts/fabricate` beforehand,
output an informative error message that tells you how to resolve the
issue.

Fixes #1
  • Loading branch information
olafmersmann committed Aug 14, 2024
1 parent bdbe047 commit ff2bae0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions build/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import sys
import numpy as np

from pathlib import Path
from setuptools import Extension, setup


## Ensure source files are present:
BASE_DIR = Path(__file__).parent.absolute()
COCOEX_DIR = Path("src") / "cocoex"
MISSING = []
for fname in ["coco.c", "coco.h"]:
full_fname = BASE_DIR / COCOEX_DIR / fname
if not full_fname.exists():
MISSING.append(str(COCOEX_DIR / fname))

if len(MISSING) > 0:
print(f"""BUILD ERROR
Missing source files: {", ".join(MISSING)}
Could not find some generated source files. These are required to build the
Python package. If you are building in-tree from a git checkout of the
'numbbo/coco-experiment' repository, did you forget to run the
`scripts/fabricate` script to generate the COCO source bundles?
If you are not building in-tree or ran `scripts/fabricate`, please file an
issue on Github: https://github.com/numbbo/coco-experiment/issues
""")
sys.exit(-1)


## Configure Cython build
extensions = []
extensions.append(Extension(name="cocoex.interface",
sources=["src/cocoex/coco.c", "src/cocoex/interface.pyx"],
Expand Down

0 comments on commit ff2bae0

Please sign in to comment.