Skip to content

Commit 26105ac

Browse files
authored
Use pip install ininstall_base.py; remove deprecated setup.py references (#399)
Update installation instructions to include verbose flag by default, showing CMake output.
1 parent 88a19db commit 26105ac

File tree

8 files changed

+55
-50
lines changed

8 files changed

+55
-50
lines changed

.github/workflows/array_api.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ jobs:
3535
conda install -c conda-forge numpy mypy cmake pytest pybind11 scikit-build patchelf tqdm &&
3636
conda remove --force-remove -y ninja || true
3737
- name: Install pykokkos-base
38-
working-directory: base
3938
run: |
4039
export CMAKE_BUILD_PARALLEL_LEVEL=2 &&
41-
python setup.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=5
40+
python install_base.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=5
4241
- name: Install pykokkos
4342
run: |
4443
python -m pip install .

.github/workflows/main_ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ jobs:
2626
python -m pip install --upgrade pip
2727
python -m pip install --upgrade numpy mypy==1.0.1 cmake pytest pybind11 scikit-build patchelf
2828
- name: Install pykokkos-base
29-
working-directory: base
3029
run: |
3130
export CMAKE_BUILD_PARALLEL_LEVEL=2
32-
python setup.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=5
31+
python install_base.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=5
3332
- name: Install pykokkos
3433
run: |
3534
python -m pip install .

.github/workflows/nightly.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ jobs:
3737
cmake --build . --parallel 2
3838
cmake --install .
3939
- name: Install pykokkos-base
40-
working-directory: base
4140
run: |
4241
export CMAKE_BUILD_PARALLEL_LEVEL=2
43-
python setup.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DKokkos_DIR=/tmp/kokkos_install/lib/cmake/Kokkos/ -DENABLE_INTERNAL_KOKKOS=OFF
42+
python install_base.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DKokkos_DIR=/tmp/kokkos_install/lib/cmake/Kokkos/ -DENABLE_INTERNAL_KOKKOS=OFF
4443
- name: Install pykokkos
4544
run: |
4645
python -m pip install .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ conda env update -n pyk -f base/environment.yml
3636
conda activate pyk
3737

3838
# Install pykokkos-base from the root directory
39-
python install_base.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=3 -DENABLE_CUDA=ON -DENABLE_THREADS=OFF -DENABLE_OPENMP=ON
39+
python install_base.py install --verbose -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF -DENABLE_VIEW_RANKS=3 -DENABLE_CUDA=ON -DENABLE_THREADS=OFF -DENABLE_OPENMP=ON
4040
```
4141

4242
#### Installing pykokkos

base/README.md

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ In order to write native Kokkos in Python, see [pykokkos](https://github.com/kok
5353

5454
## Installation
5555

56-
You can install this package via CMake or Python's `setup.py`. The important cmake options are:
56+
You can install this package via CMake or via `pip install ./`. The important CMake options are:
5757

5858
- `ENABLE_VIEW_RANKS` (integer)
5959
- `ENABLE_LAYOUTS` (bool)
@@ -82,8 +82,7 @@ If the `ENABLE_INTERNAL_KOKKOS` option is not specified the first time CMake is
8282
find an existing Kokkos installation. If no existing installation is found, it will build and install
8383
Kokkos from a submodule. When Kokkos is added as a submodule, you can configure the submodule
8484
as you would normally configure Kokkos. However, due to some general awkwardness configuring cmake
85-
from `setup.py` (especially via `pip install`), CMake tries to "automatically" configure
86-
reasonable default CMake settings for the Kokkos submodule.
85+
when configuring via pip builds, CMake tries to "automatically" configure reasonable default CMake settings for the Kokkos submodule.
8786

8887
Here are the steps when Kokkos is added as a submodule:
8988

@@ -108,28 +107,10 @@ Here are the steps when Kokkos is added as a submodule:
108107
cmake -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF /path/to/source
109108
```
110109

111-
### Configuring Options via `setup.py`
110+
### Configuring Options
112111

113-
There are three ways to configure the options:
114-
115-
1. Via the Python argparse options `--enable-<option>` and `--disable-<option>`
116-
2. Setting the `PYKOKKOS_BASE_SETUP_ARGS` environment variable to the CMake options
117-
3. Passing in the CMake options after a `--`
118-
119-
All three lines below are equivalent (deprecated format):
120-
121-
```console
122-
python setup.py install --enable-layouts --disable-memory-traits
123-
PYKOKKOS_BASE_SETUP_ARGS="-DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF" python setup.py install
124-
python setup.py install -- -DENABLE_LAYOUTS=ON -DENABLE_MEMORY_TRAITS=OFF
125-
```
126-
127-
### Configuring Options via `pip`
128-
129-
Pip does not handle build options well. Thus, it is recommended to use the `PYKOKKOS_BASE_SETUP_ARGS`
130-
environment variable noted above.
131-
132-
We suggest using the following line to install pykokkos-base:
112+
For pip installs, set `PYKOKKOS_BASE_SETUP_ARGS` to a space-delimited list of CMake `-D...`
113+
options, then run:
133114

134115
```
135116
PYKOKKOS_BASE_SETUP_ARGS="-DKokkos_ENABLE_THREADS=OFF \
@@ -143,8 +124,7 @@ PYKOKKOS_BASE_SETUP_ARGS="-DKokkos_ENABLE_THREADS=OFF \
143124

144125
`--verbose` is optional, but it shows installation progress in real time.
145126

146-
> `pip install ./` will build against the latest release in the PyPi repository.
147-
> In order to pip install from this repository, use `pip install --user -e .`
127+
> `pip install ./` installs from this checkout. For editable development, use `pip install -e .`.
148128
149129
## Differences vs. Kokkos C++
150130

base/setup.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,8 @@ def add_arg_bool_option(lc_name, disp_name, default=None):
9191
default=[],
9292
type=str,
9393
nargs="*",
94-
help="{}{}{}".format(
95-
"Pass arguments to cmake. Use w/ pip installations",
96-
"and --install-option, e.g. --install-option=--cmake-args=",
97-
'"-DENABLE_LAYOUTS=ON -DKokkos_DIR=/usr/local/lib/cmake/Kokkos"',
98-
),
94+
help="Pass arguments to CMake. For pip installs, "
95+
"set PYKOKKOS_BASE_SETUP_ARGS instead.",
9996
)
10097

10198
args, left = parser.parse_known_args()
@@ -139,8 +136,8 @@ def add_arg_bool_option(lc_name, disp_name, default=None):
139136
cmake_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={darwin_version}"]
140137

141138
# DO THIS LAST!
142-
# support PYKOKKOS_BASE_SETUP_ARGS environment variables because
143-
# --install-option for pip is a pain to use
139+
# Support PYKOKKOS_BASE_SETUP_ARGS environment variables so pip builds don't
140+
# need deprecated/awkward command-line build argument plumbing.
144141
# PYKOKKOS_BASE_SETUP_ARGS should be space-delimited set of cmake arguments, e.g.:
145142
# export PYKOKKOS_BASE_SETUP_ARGS="-DENABLE_LAYOUTS=OFF -DENABLE_MEMORY_TRAITS=ON"
146143
env_cmake_args = os.environ.get("PYKOKKOS_BASE_SETUP_ARGS", None)

docs/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ install ``base`` with required CMake flags (example performs an install with Op
7777

7878
.. code-block:: bash
7979
80-
python install_base.py install -- \
80+
python install_base.py install --verbose -- \
8181
-DENABLE_VIEW_RANKS=3 \ # maximum number of view ranks enabled
8282
-DENABLE_MEMORY_TRAITS=OFF \ # disable memory space concept
8383
-DENABLE_THREADS=OFF \ # disable pthreads execution space

install_base.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
python install_base.py install -- [FLAGS]
99
1010
This is equivalent to:
11-
cd base/ python setup.py install -- [FLAGS]
11+
cd base/ python -m pip install . (with PYKOKKOS_BASE_SETUP_ARGS set)
1212
"""
1313

1414
import os
@@ -24,20 +24,51 @@ def main():
2424
if not os.path.exists(base_dir):
2525
print(f"Error: base directory not found at {base_dir}")
2626
sys.exit(1)
27-
28-
setup_py = os.path.join(base_dir, "setup.py")
29-
if not os.path.exists(setup_py):
30-
print(f"Error: setup.py not found at {setup_py}")
31-
sys.exit(1)
3227
original_dir = os.getcwd()
3328
os.chdir(base_dir)
3429

3530
try:
36-
# Run setup.py with all the arguments passed to this script
37-
cmd = [sys.executable, "setup.py"] + sys.argv[1:]
31+
argv = sys.argv[1:]
32+
if not argv:
33+
raise SystemExit(
34+
"Usage: python install_base.py install -- -D<...> [other CMake -D flags]"
35+
)
36+
37+
# Allow users to pass verbosity flags through this wrapper.
38+
pip_verbose = ("--verbose" in argv) or ("-v" in argv)
39+
40+
# Parse CMake flags after `--`.
41+
#
42+
# Typical invocation:
43+
# python install_base.py install -- -DENABLE_LAYOUTS=ON -DENABLE_VIEW_RANKS=3
44+
cmake_flags = []
45+
if "--" in argv:
46+
idx = argv.index("--")
47+
cmake_flags = argv[idx + 1 :]
48+
else:
49+
# Backwards-compat: if someone calls `python install_base.py install -D...`
50+
# treat everything except the leading `install` as CMake flags.
51+
cmake_flags = [a for a in argv if a != "install"]
52+
53+
# Ensure wrapper verbosity flags don't leak into CMake arguments.
54+
# These are only meant to affect `pip install`, not the -D... CMake args.
55+
cmake_flags = [a for a in cmake_flags if a not in ("-v", "--verbose")]
56+
57+
env = os.environ.copy()
58+
existing = env.get("PYKOKKOS_BASE_SETUP_ARGS", "").strip()
59+
if cmake_flags:
60+
cmake_str = " ".join(cmake_flags).strip()
61+
env["PYKOKKOS_BASE_SETUP_ARGS"] = (
62+
f"{existing} {cmake_str}".strip() if existing else cmake_str
63+
)
64+
65+
cmd = [sys.executable, "-m", "pip", "install", "."]
66+
if pip_verbose:
67+
cmd.append("--verbose")
68+
3869
print(f"Running: {' '.join(cmd)}")
3970
print(f"Working directory: {os.getcwd()}")
40-
result = subprocess.run(cmd)
71+
result = subprocess.run(cmd, env=env)
4172
sys.exit(result.returncode)
4273
finally:
4374
os.chdir(original_dir)

0 commit comments

Comments
 (0)