Skip to content

Commit b7db201

Browse files
authored
Merge pull request #420 from light-curve/readme-build-from-src
Dev guide for readme
2 parents 8aa94a7 + 8caf9c6 commit b7db201

File tree

1 file changed

+142
-4
lines changed

1 file changed

+142
-4
lines changed

light-curve/README.md

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ versions.
3737
periodogram performance, which is not a default build option. For Windows x86-64 we provide wheel with no Ceres and no
3838
GSL support, which is not a default build option.
3939
- "src": the package is confirmed to be built and pass unit tests locally, but testing and package building is not
40-
supported by CI. It is required to have the [GNU scientific library (GSL)](https://www.gnu.org/software/gsl/) v2.1+
41-
and the [Rust toolchain](https://rust-lang.org) v1.67+ to install it via `pip install`. `ceres-solver` and `fftw` may
42-
be installed locally or built from source, in the later case you would also need C/C++ compiler and `cmake`.
40+
supported by CI. See ["Build from source"] section bellow for the details.
4341
- "not tested": building from the source code is not tested, please report us building status via issue/PR/email.
4442

4543
macOS wheels require relatively new OS versions, please open an issue if you require support of older Macs,
@@ -48,6 +46,8 @@ see https://github.com/light-curve/light-curve-python/issues/376 for the details
4846
We stopped publishing PyPy wheels (https://github.com/light-curve/light-curve-python/issues/345), please feel free to
4947
open an issue if you need them.
5048

49+
See [bellow](#build-from-source) for the details on how to build the package from the source code.
50+
5151
## Feature evaluators
5252

5353
Most of the classes implement various feature evaluators useful for light-curve based
@@ -116,7 +116,8 @@ help(lc.BazinFit)
116116
### Available features
117117

118118
See the complete list of available feature evaluators and documentation
119-
in [`light-curve-feature` Rust crate docs](https://docs.rs/light-curve-feature/latest/light_curve_feature/features/index.html).
119+
in [
120+
`light-curve-feature` Rust crate docs](https://docs.rs/light-curve-feature/latest/light_curve_feature/features/index.html).
120121
Italic names are experimental features.
121122
While we usually say "magnitude" and use "m" as a time-series value, some of the features are supposed to be used with
122123
flux light-curves.
@@ -631,6 +632,143 @@ actual = dmdt.points(t, m)
631632
assert_array_equal(actual, desired)
632633
```
633634

635+
## Developer guide
636+
637+
### Prepare environment
638+
639+
Install Rust toolchain and Python 3.8+.
640+
It is recommended to use [`rustup`](https://rustup.rs/) to install Rust toolchain and update it with `rustup update`
641+
periodically.
642+
643+
Clone the code, create and activate a virtual environment.
644+
645+
```bash
646+
git clone https://github.com/light-curve/light-curve-python.git
647+
cd light-curve-python/light-curve
648+
python3 -m venv venv
649+
source venv/bin/activate
650+
```
651+
652+
Install the package in editable mode (see more details about building from source [bellow](#build-from-source)).
653+
654+
```bash
655+
python -mpip install maturin
656+
# --release would take longer, but the package would be faster
657+
# Put other Cargo flags if needed, e.g. --no-default-features --features=fftw-source,ceres-source
658+
maturin develop --extras=dev
659+
```
660+
661+
Next time you can just run `source venv/bin/activate` to activate the environment and `maturin develop` to rebuild
662+
Rust code if changed.
663+
You don't need to reinstall the package if you change Python code.
664+
You also don't need to add `--extras=dev` next time, it is needed only to install development dependencies.
665+
666+
You are also encouraged to install `pre-commit` hooks to keep the codebase clean.
667+
You can get it with `pip` (see the [documentation](https://pre-commit.com/#install) for other ways), and then install
668+
the hooks with
669+
670+
```bash
671+
pre-commit install
672+
```
673+
674+
### Run tests and benchmarks
675+
676+
All test-related dependencies are installed with `--extras=dev` flag, so you don't need to install anything else.
677+
You can run tests with `pytest`:
678+
679+
```bash
680+
python -mpytest
681+
```
682+
683+
Benchmarks are disabled by default, you can enable them with `--benchmark-enable` flag:
684+
685+
```bash
686+
python -mpytest --benchmark-enable
687+
```
688+
689+
See [Benchamrks](#benchmarks) section for more details.
690+
691+
### Build from source
692+
693+
#### Dependencies and Cargo features
694+
695+
The package has a number of compile-time features, mostly to control which C/C++ dependencies are used.
696+
The list of these Cargo features may be passed to `maturin` with `--features` flag, it is also
697+
recommended to use `--no-default-features` to avoid building unnecessary dependencies.
698+
699+
The following features are available:
700+
701+
- `abi3` (default) - enables CPython ABI3 compatibility, turn it off for other interpreters or if you believe that code
702+
would be faster without it (our benchmarks show that it is not the case).
703+
- `ceres-source` (default) - enables [Ceres solver](http://ceres-solver.org/) support, and builds it from sources. You
704+
need C++ compiler and cmake available on your system. Known to not work on Windows. It is used as an optional
705+
optimization alrotithm for `BazinFit` and `VillarFit`.
706+
- `ceres-system` - enables Ceres solver support, but links with a dynamic library. You need to have a compatible version
707+
of Ceres installed on your system.
708+
- `fftw-source` (default) - enables [FFTW](http://www.fftw.org/) support, and builds it from sources. You need C
709+
compiler available on your system. Note that at least one of `fftw-*` features must be activated.
710+
- `fftw-system` - enables FFTW support, but links with a dynamic library. You need to have a compatible version of FFTW
711+
installed on your system.
712+
- `fftw-mkl` - enables FFTW support with Intel MKL backend. Intel MKL will be downloaded automatically during the build.
713+
Highly recommended for Intel CPUs to achieve up to 2x faster "fast" periodogram calculation.
714+
- `gsl` (default) - enables [GNU scientific library](https://www.gnu.org/software/gsl/) support. You need a compatible
715+
version of GSL installed on your system. It is used as an optional optimization algorithm for `BazinFit` and
716+
`VillarFit`.
717+
- `mimalloc` (default) - enables [mimalloc](https://github.com/microsoft/mimalloc) memory allocator support. Our
718+
benchmarks show up to 2x speedup for some simple features, but it may lead to larger memory consumption.
719+
720+
#### Build with maturin
721+
722+
You can build the package with `maturin` (a Python package for building and publishing Rust crates as Python packages).
723+
This example shows how to build the package with minimal dependencies.
724+
725+
```bash
726+
python -mpip install maturin
727+
maturin build --release --locked --no-default-features --features=abi3,fftw-source,mimalloc
728+
````
729+
730+
Here we use `--release` to build the package in release mode (slower build, faster execution), `--locked` to ensure
731+
reproducible builds, `--no-default-features` to disable default features, and `--features=abi3,fftw-source,mimalloc`
732+
to enable FFTW (builds from vendored sources), ABI3 compatibility, and mimalloc memory allocator.
733+
734+
#### Build with `build`
735+
736+
You can also build the package with `build` (a Python package for building and installing Python packages from source).
737+
738+
```bash
739+
python -mpip install build
740+
MATURIN_PEP517_ARGS="--locked --no-default-features --features=abi3,fftw-source,mimalloc" python -m build
741+
```
742+
743+
#### Build with cibuildwheel
744+
745+
`ciwbuildwheel` is a project that builds wheels for Python packages on CI servers, we use it to build wheels with
746+
GitHub Actions.
747+
You can use it locally to build wheels on your platform (change platform identifier to one
748+
from [the list of supported](https://cibuildwheel.pypa.io/en/stable/options/#build-skip):
749+
750+
```bash
751+
python -mpip install cibuildwheel
752+
python -m cibuildwheel --only=cp38-manylinux_x86_64
753+
```
754+
755+
Please notice that we use different Cargo feature set for different platforms, which is defined in `pyproject.toml`.
756+
You can build Windows wheels on Windows, Linux wheels on any platform with Docker installed (Qemu may be needed for
757+
cross-architecture builds), and macOS wheels on macOS.
758+
On Windows and macOS some additional dependencies will be installed automatically, please check
759+
the [cibuildwheel documentation](https://cibuildwheel.pypa.io/) and `pyproject.toml` for details.
760+
Also, macOS builds require `MACOSX_DEPLOYMENT_TARGET` to be set to the current version of macOS, because dependent
761+
libraries installed from `homebrew` are built with this target:
762+
763+
```bash
764+
export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion | awk -F '.' '{print $1"."0}')
765+
python -m cibuildwheel --only=cp38-macosx_arm64
766+
unset MACOSX_DEPLOYMENT_TARGET
767+
```
768+
769+
Since we use ABI3 compatibility, you can build wheels for a single Python version (currently 3.8+) and they will work
770+
with any later version of CPython.
771+
634772
## Citation
635773

636774
If you found this project useful for your research please

0 commit comments

Comments
 (0)