-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
78 lines (65 loc) · 2.39 KB
/
setup.py
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
68
69
70
71
72
73
74
75
76
77
78
"""Setuptools config only used for Python 2.7 compatibility.
"""
from setuptools import setup
from setuptools.command.install import install
import os
import subprocess
ROOT = os.path.dirname(os.path.realpath(__file__))
DEPENDENCIES = ["pytest >= 4, < 9"]
class CreateCmakeConfig(install):
"""Custom command to create and share pytest config."""
def run(self):
"""Execute builder."""
import pytest
build_path = os.path.join(ROOT, "build")
if not os.path.exists(build_path):
os.makedirs(build_path)
# CMake search procedure is limited to CMake package configuration files
# and does not work with modules. Hence, we are generating a
# configuration file based on the CMake modules created.
# https://cmake.org/cmake/help/latest/command/find_package.html
config_path = os.path.join(build_path, "PytestConfig.cmake")
with open(config_path, "w") as stream:
stream.write(
"include(${CMAKE_CURRENT_LIST_DIR}/FindPytest.cmake)\n"
)
# Generate CMake config version file for client to target a specific
# version of Pytest within CMake projects.
version_config_path = os.path.join(
build_path, "PytestConfigVersion.cmake"
)
script_path = os.path.join(
build_path, "PytestConfigVersionScript.cmake"
)
with open(script_path, "w") as stream:
stream.write(
"include(CMakePackageConfigHelpers)\n"
"write_basic_package_version_file(\n"
" \"{path}\"\n"
" VERSION {version}\n"
" COMPATIBILITY AnyNewerVersion\n"
")".format(
path=str(version_config_path),
version=pytest.__version__,
)
)
subprocess.call(["cmake", "-P", str(script_path), "-VV"])
return install.run(self)
setup(
name="pytest-cmake",
version="0.11.3",
data_files=[
(
"share/Pytest/cmake",
[
"build/PytestConfig.cmake",
"build/PytestConfigVersion.cmake",
"cmake/FindPytest.cmake",
"cmake/PytestAddTests.cmake"
]
)
],
cmdclass={"install": CreateCmakeConfig},
install_requires=DEPENDENCIES,
setup_requires=DEPENDENCIES,
)