Skip to content

Commit 919ecdd

Browse files
authored
Merge pull request #2172 from IntelPython/do-not-use-setup-py-develop
Remove use of `python setup.py develop/install` in the project
2 parents 70920d3 + 7962541 commit 919ecdd

File tree

12 files changed

+703
-536
lines changed

12 files changed

+703
-536
lines changed

.github/workflows/conda-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ jobs:
633633
do
634634
pushd $d
635635
conda activate --stack ${{ env.BUILD_ENV_NAME }}
636-
CC=icx CXX=icpx python setup.py develop -G Ninja || exit 1
636+
CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja || exit 1
637637
conda deactivate
638638
python -m pytest tests || exit 1
639639
popd

.github/workflows/generate-docs.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,7 @@ jobs:
7575
source /opt/intel/oneapi/setvars.sh
7676
wget https://github.com/vovkos/doxyrest/releases/download/doxyrest-2.1.2/doxyrest-2.1.2-linux-amd64.tar.xz
7777
tar xf doxyrest-2.1.2-linux-amd64.tar.xz
78-
python setup.py develop -G Ninja --build-type=Release \
79-
-- \
80-
-DCMAKE_C_COMPILER:PATH=$(which icx) \
81-
-DCMAKE_CXX_COMPILER:PATH=$(which icpx) \
82-
-DDPCTL_GENERATE_DOCS=ON \
83-
-DDPCTL_ENABLE_DOXYREST=ON \
84-
-DDoxyrest_DIR=`pwd`/doxyrest-2.1.2-linux-amd64 \
85-
-DCMAKE_VERBOSE_MAKEFILE=ON
78+
python scripts/gen_docs.py --doxyrest-root=`pwd`/doxyrest-2.1.2-linux-amd64 --verbose || exit 1
8679
python -c "import dpctl; print(dpctl.__version__)" || exit 1
8780
pushd "$(find _skbuild -name cmake-build)" || exit 1
8881
cmake --build . --target Sphinx || exit 1

.github/workflows/os-llvm-sycl-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ jobs:
146146
shell: bash -l {0}
147147
run: |
148148
source set_allvars.sh
149-
CC=clang CXX=clang++ python setup.py develop -G Ninja
149+
python scripts/build_locally.py --c-compiler=clang --cxx-compiler=clang++ \
150+
--compiler-root=${SYCL_BUNDLE_FOLDER}/dpcpp_compiler/bin || exit 1
150151
151152
- name: Run lsplatforms
152153
shell: bash -l {0}

CONTRIBUTING.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,8 @@ To check the code coverage for your code, follow these steps:
203203
coverage html
204204
```
205205

206-
The code coverage builds the C sources with debug symbols. For this
207-
reason, the coverage script builds the package in `develop` mode of
208-
`setup.py`.
209-
210-
The coverage results for the C and Python sources are printed to the
206+
The code coverage builds the C sources with debug symbols, and the
207+
coverage results for the C and Python sources are printed to the
211208
terminal during the build (`libsyclinterface`) and pytest execution (Python).
212209
The detailed coverage reports for the `libsyclinterface` library are saved to the
213210
`dpctl-c-api-coverage` directory. The Python coverage reports are saved to

docs/doc_sources/contributor_guides/building.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,16 @@ To develop, run:
129129

130130
.. code-block:: bash
131131
132-
python setup.py develop -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx
132+
python setup.py build_ext --inplace -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx
133+
python -m pip install -e .
133134
134135
.. tab-item:: Windows
135136
:sync: win
136137

137138
.. code-block:: bat
138139
139-
python setup.py develop -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx
140+
python setup.py build_ext --inplace -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx
141+
python -m pip install -e .
140142
141143
142144
Developing can be streamlined using the driver script:
@@ -169,7 +171,8 @@ the relevant CMake variables, for example:
169171

170172
.. code-block:: bash
171173
172-
python setup.py develop -- -G Ninja -DCMAKE_C_COMPILER:PATH=$(which clang) -DCMAKE_CXX_COMPILER:PATH=$(which clang++)
174+
python setup.py build_ext --inplace -G Ninja -DCMAKE_C_COMPILER:PATH=$(which clang) -DCMAKE_CXX_COMPILER:PATH=$(which clang++)
175+
python -m pip install -e .
173176
174177
175178
Or you can use the driver script:

examples/cython/sycl_buffer/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ oneMKL.
1414

1515
> **NOTE:** Make sure oneAPI is activated, $ONEAPI_ROOT must be set.
1616
17-
To compile the example, run:
17+
To compile the example on Linux, run:
18+
```bash
19+
CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja
1820
```
19-
python setup.py develop
21+
22+
On Windows, run:
23+
```bash
24+
CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja
2025
```
2126

2227
## Running

examples/cython/use_dpctl_sycl/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ written in Cython.
99

1010
## Building
1111

12+
To build the example on Linux, run:
1213
```bash
13-
python setup.py develop
14+
CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja
15+
```
16+
17+
On Windows, run:
18+
```bash
19+
CC=icx CXX=icx python setup.py build_ext --inplace -G Ninja
1420
```
1521

1622
## Testing

examples/pybind11/onemkl_gemv/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
> **NOTE:** Install scikit-build and dpcpp before next steps.
77
8-
To build, run:
9-
```sh
10-
python setup.py develop -- -G "Ninja" \
8+
To build on Linux, run:
9+
```bash
10+
python setup.py build_ext --inplace -- -G "Ninja" \
1111
-DCMAKE_C_COMPILER:PATH=icx \
1212
-DCMAKE_CXX_COMPILER:PATH=icpx \
1313
-DTBB_LIBRARY_DIR=$CONDA_PREFIX/lib \
@@ -16,6 +16,17 @@ python setup.py develop -- -G "Ninja" \
1616
-DTBB_INCLUDE_DIR=${CONDA_PREFIX}/include
1717
```
1818

19+
To build on Windows, run:
20+
```bash
21+
python setup.py build_ext --inplace -- -G "Ninja" \
22+
-DCMAKE_C_COMPILER:PATH=icx \
23+
-DCMAKE_CXX_COMPILER:PATH=icx \
24+
-DTBB_LIBRARY_DIR=$CONDA_PREFIX/lib \
25+
-DMKL_LIBRARY_DIR=${CONDA_PREFIX}/lib \
26+
-DMKL_INCLUDE_DIR=${CONDA_PREFIX}/include \
27+
-DTBB_INCLUDE_DIR=${CONDA_PREFIX}/include
28+
```
29+
1930
## Running
2031

2132
To run the example, use:

scripts/_build_helper.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2025 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
import shutil
19+
import subprocess
20+
import sys
21+
22+
23+
def resolve_compilers(
24+
oneapi: bool,
25+
c_compiler: str,
26+
cxx_compiler: str,
27+
compiler_root: str,
28+
):
29+
is_linux = "linux" in sys.platform
30+
31+
if oneapi or (
32+
c_compiler is None and cxx_compiler is None and compiler_root is None
33+
):
34+
return "icx", ("icpx" if is_linux else "icx")
35+
36+
if (
37+
(c_compiler is None or not os.path.isabs(c_compiler))
38+
and (cxx_compiler is None or not os.path.isabs(cxx_compiler))
39+
and (not compiler_root or not os.path.exists(compiler_root))
40+
):
41+
raise RuntimeError(
42+
"--compiler-root option must be set when using non-default DPC++ "
43+
"layout unless absolute paths are provided for both compilers"
44+
)
45+
46+
# default values
47+
if c_compiler is None:
48+
c_compiler = "icx"
49+
if cxx_compiler is None:
50+
cxx_compiler = "icpx" if is_linux else "icx"
51+
52+
for name, opt_name in (
53+
(c_compiler, "--c-compiler"),
54+
(cxx_compiler, "--cxx-compiler"),
55+
):
56+
if os.path.isabs(name):
57+
path = name
58+
else:
59+
path = os.path.join(compiler_root, name)
60+
if not os.path.exists(path):
61+
raise RuntimeError(f"{opt_name} value {name} not found")
62+
return c_compiler, cxx_compiler
63+
64+
65+
def run(cmd: list[str], env: dict[str, str] = None, cwd: str = None):
66+
print("+", " ".join(cmd))
67+
subprocess.check_call(
68+
cmd, env=env or os.environ.copy(), cwd=cwd or os.getcwd()
69+
)
70+
71+
72+
def capture_cmd_output(cmd: list[str], cwd: str = None):
73+
print("+", " ".join(cmd))
74+
return (
75+
subprocess.check_output(cmd, cwd=cwd or os.getcwd())
76+
.decode("utf-8")
77+
.strip("\n")
78+
)
79+
80+
81+
def err(msg: str, script: str):
82+
raise RuntimeError(f"[{script}] error: {msg}")
83+
84+
85+
def log_cmake_args(cmake_args: list[str], script: str):
86+
print(f"[{script}] Using CMake args:\n{' '.join(cmake_args)}")
87+
88+
89+
def make_cmake_args(
90+
c_compiler: str = None,
91+
cxx_compiler: str = None,
92+
level_zero: bool = True,
93+
glog: bool = False,
94+
verbose: bool = False,
95+
other_opts: str = None,
96+
):
97+
args = [
98+
f"-DCMAKE_C_COMPILER:PATH={c_compiler}" if c_compiler else "",
99+
f"-DCMAKE_CXX_COMPILER:PATH={cxx_compiler}" if cxx_compiler else "",
100+
f"-DDPCTL_ENABLE_L0_PROGRAM_CREATION={'ON' if level_zero else 'OFF'}",
101+
f"-DDPCTL_ENABLE_GLOG:BOOL={'ON' if glog else 'OFF'}",
102+
]
103+
104+
if verbose:
105+
args.append("-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
106+
if other_opts:
107+
args.extend(other_opts.split())
108+
109+
return args
110+
111+
112+
def build_extension(
113+
setup_dir: str,
114+
env: dict[str, str],
115+
cmake_args: list[str],
116+
cmake_executable: str = None,
117+
generator: str = None,
118+
build_type: str = None,
119+
):
120+
cmd = [sys.executable, "setup.py", "build_ext", "--inplace"]
121+
if cmake_executable:
122+
cmd.append(f"--cmake-executable={cmake_executable}")
123+
if generator:
124+
cmd.append(f"--generator={generator}")
125+
if build_type:
126+
cmd.append(f"--build-type={build_type}")
127+
if cmake_args:
128+
cmd.append("--")
129+
cmd += cmake_args
130+
run(
131+
cmd,
132+
env=env,
133+
cwd=setup_dir,
134+
)
135+
136+
137+
def install_editable(setup_dir: str, env: dict[str, str]):
138+
run(
139+
[
140+
sys.executable,
141+
"-m",
142+
"pip",
143+
"install",
144+
"-e",
145+
".",
146+
"--no-build-isolation",
147+
],
148+
env=env,
149+
cwd=setup_dir,
150+
)
151+
152+
153+
def clean_build_dir(setup_dir: str):
154+
if (
155+
not isinstance(setup_dir, str)
156+
or not setup_dir
157+
or not os.path.isdir(setup_dir)
158+
):
159+
raise RuntimeError(f"Invalid setup directory provided: '{setup_dir}'")
160+
target = os.path.join(setup_dir, "_skbuild")
161+
if os.path.exists(target):
162+
print(f"Cleaning build directory: {target}")
163+
try:
164+
shutil.rmtree(target)
165+
except Exception as e:
166+
print(f"Failed to remove build directory: '{target}'")
167+
raise e

0 commit comments

Comments
 (0)