Skip to content
Snippets Groups Projects
Commit e87ef819 authored by Christophe Guillon's avatar Christophe Guillon
Browse files

[Setup] Use symlinks in editable mode post install

In editable mode, post installation of files use symlinks
instead of copy.
This allow to the either rebuild with pip or directly with the
build backend, for instance:
- make -C build install
- ninja -C build install # with Ninja backend
parent 1422bcae
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !154. Comments created here will be created in the context of that merge request.
...@@ -34,6 +34,14 @@ After changes in a python file, no action is required, for changes in .cpp/.h fi ...@@ -34,6 +34,14 @@ After changes in a python file, no action is required, for changes in .cpp/.h fi
pip install --no-build-isolation -v -e . pip install --no-build-isolation -v -e .
``` ```
Or simply use the build backend (generated files in the `build/` directory have been symlinked
during the first editable install):
```bash
make -C build install -j $(nproc)
# or for instance with ninja backend
ninja -C build install
```
In this mode, the C++ compilation build system is located in the local `build/` directory. In this mode, the C++ compilation build system is located in the local `build/` directory.
Refer to the doc string in `setup.py`for more details on editable mode. Refer to the doc string in `setup.py`for more details on editable mode.
......
...@@ -47,7 +47,7 @@ Development Status :: 2 - Pre-Alpha ...@@ -47,7 +47,7 @@ Development Status :: 2 - Pre-Alpha
""" """
import shutil import shutil
import pathlib from pathlib import Path
import subprocess import subprocess
import multiprocessing import multiprocessing
...@@ -57,7 +57,7 @@ from setuptools import setup, Extension ...@@ -57,7 +57,7 @@ from setuptools import setup, Extension
from setuptools import find_packages from setuptools import find_packages
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
SETUP_DIR = pathlib.Path(__file__).parent SETUP_DIR = Path(__file__).parent
def parse_requirements(): def parse_requirements():
with open(SETUP_DIR / "requirements.txt", "r") as inf: with open(SETUP_DIR / "requirements.txt", "r") as inf:
...@@ -90,19 +90,28 @@ class CMakeBuild(build_ext): ...@@ -90,19 +90,28 @@ class CMakeBuild(build_ext):
else: else:
self.editable_mode = False self.editable_mode = False
def _post_install_copy(self, fname, dst_dir):
Path(dst_dir).mkdir(parents=True, exist_ok=True)
dst_file = Path(dst_dir) / Path(fname).name
if not self.editable_mode:
shutil.copy(str(fname), str(dst_file))
else:
dst_file.unlink(missing_ok=True)
os.symlink(str(fname), str(dst_file))
def run(self): def run(self):
# This lists the number of processors available on the machine # This lists the number of processors available on the machine
# The compilation will use half of them # The compilation will use half of them
# Note that for ninja backend this is not necessary # Note that for ninja backend this is not necessary
max_jobs = str(ceil(multiprocessing.cpu_count() / 2)) max_jobs = str(ceil(multiprocessing.cpu_count() / 2))
cwd = pathlib.Path().absolute() cwd = Path().absolute()
build_temp = cwd / "build" build_temp = cwd / "build"
if not build_temp.exists(): if not build_temp.exists():
build_temp.mkdir(parents=True, exist_ok=True) build_temp.mkdir(parents=True, exist_ok=True)
build_lib = pathlib.Path(self.build_lib) build_lib = Path(self.build_lib)
if not build_lib.exists(): if not build_lib.exists():
build_lib.mkdir(parents=True, exist_ok=True) build_lib.mkdir(parents=True, exist_ok=True)
...@@ -135,11 +144,11 @@ class CMakeBuild(build_ext): ...@@ -135,11 +144,11 @@ class CMakeBuild(build_ext):
if ((file.endswith('.so') or file.endswith('.pyd')) and if ((file.endswith('.so') or file.endswith('.pyd')) and
root != str(aidge_package) and root != str(aidge_package) and
not root.startswith(str(build_lib))): not root.startswith(str(build_lib))):
currentFile = pathlib.Path(root) / file currentFile = Path(root) / file
shutil.copy(str(currentFile), str(aidge_package)) self._post_install_copy(currentFile, aidge_package)
# Copy version.txt in aidge_package # Copy version.txt in aidge_package
shutil.copy(str(SETUP_DIR / "version.txt"), str(aidge_package)) self._post_install_copy(SETUP_DIR / "version.txt", str(aidge_package))
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment