Tips#
git#
Update fork
git remote add upstream {url_to_remote}
git fetch upstream
git rebase upstream/main
Remove local and remote branch
Note that a common usage of a fork is to open a pull-request, in particular from a branch on the fork:
git checkout -b patch
... # commits here
Once merged, you can delete the branch:
git checkout main
git branch -D patch
git push --delete origin patch
Update remote branch
When a remote branch is deleted from a repository, it can still show up in the local branch list.
Often .. code-block:: bash
git fetch
should suffice. However, sometimes you’ll have to do
git fetch --prune
Generate patch
In case a new release cannot be made (because you don’t have access to a repository), but you still want to update a conda-forge recipe, you can add ‘patches’ to the recipe.
To this end, clone the repository
git clone https://github.com/someuser/somerepo
Move to the repository
cd somerepo
and determine the number of commits since the last release (e.g. 3). Then have git create the patches, using:
git format-patch -3
This will create a number of *.patch
files (3 in this case). These patches can be added to the recipe. See for example the cling-feedstock.
Partial clone
Recently I came across a few repositories with a very rich history (corresponding to a huge disk-space, requiring also a significant downloading time). If one is not particularly interested in the histories, on can partially (shallow) clone a repository:
git clone --depth=5 ...
conda#
Add library to Conda environment
Conda is a great tool as a package manager and virtual environment together. Many (up-to-date) packages are available through conda-forge. However, ever to often you might want to install from a local source (for example to test the current master branch).
Start by activating the relevant Conda environment (e.g. “myenv”):
conda activate myenv
(see Conda documentation on how to manage environments).
Then, go to the library:
cd /path/to/library
Python
Make sure that you have Python installed, e.g. using
conda install -c conda-forge python
Then, with the Python executable that is loaded (from myenv
)
python -m pip install .
CMake
Make sure that you have CMake installed, e.g. using
conda install -c conda-forge cmake
Then, with the CMake executable that is loaded (from myenv
)
cmake . -DCMAKE_INSTALL_PREFIX:PATH="${CONDA_PREFIX}"
Python#
Create movie with ‘ffmpeg-python’
ffmpeg-python is a great wrapper around ffmpeg to create your movie from Python.
Let us begin by setting up an environment that contains what we need:
conda activate myenv
conda install -c conda-forge ffmpeg-python
conda install -c conda-forge matplotlib
(see Conda documentation on how to manage environments).
Then, we will create an animation as a batch of images:
import matplotlib.pyplot as plt
filenames = []
for i in range(20):
filename = 'image_{0:02d}.png'.format(i)
filenames += [filename]
fig, ax = plt.subplots()
ax.plot([0, 1], [0, i])
ax.set_ylim([0, 20])
plt.savefig(filename)
To convert this to a movie, we will use ffmpeg-python:
import ffmpeg
(
ffmpeg
.input('image_%02d.png', framerate=2)
.output('movie.mp4')
.run()
)
pybind11 examples
pybind11 examples. Some basic examples on how to start using pybind11. Pybind11 is a C++ library that allows to expose a C++ library to Python easily.
ParaView#
ParaView examples
ParaView examples. Some basic examples on how to make data available in ParaView.