@@ -89,7 +89,7 @@ is required for building the C API documentation.
8989On Debian/Ubuntu we can install these with:
9090
9191``` bash
92- $ sudo apt install build-essential doxygen
92+ sudo apt install build-essential doxygen
9393```
9494
9595All Python development is managed using [ uv] ( https://docs.astral.sh/uv/ ) .
@@ -108,7 +108,7 @@ in ``python/pyproject.toml`` and managed with [uv](https://docs.astral.sh/uv/).
108108Install all development dependencies by running, from the ` python/ ` directory:
109109
110110``` bash
111- $ uv sync
111+ uv sync
112112```
113113
114114The lock file lives at ` python/uv.lock ` and must be kept up to date. Run
@@ -127,12 +127,12 @@ To get a local git development environment, please follow these steps:
127127- Make a fork of the tskit repo on [ GitHub] ( http://github.com/tskit-dev/tskit )
128128- Clone your fork into a local directory:
129129 ``` bash
130- $ git clone git@github.com:YOUR_GITHUB_USERNAME/tskit.git
130+ git clone git@github.com:YOUR_GITHUB_USERNAME/tskit.git
131131 ```
132132- Install the {ref}` sec_development_workflow_prek ` pre-commit hook
133133 (again from the `` python/ `` subdirectory):
134134 ``` bash
135- $ uv run prek install
135+ uv run prek install
136136 ```
137137
138138See the {ref}` sec_development_workflow_git ` section for detailed information
@@ -168,14 +168,14 @@ skip to {ref}`sec_development_workflow_anothers_commit`.
168168 [ upstream remote] (
169169 https://help.github.com/articles/configuring-a-remote-for-a-fork/ ):
170170 ``` bash
171- $ git remote add upstream https://github.com/tskit-dev/tskit.git
171+ git remote add upstream https://github.com/tskit-dev/tskit.git
172172 ```
173173
1741743 . Create a "topic branch" to work on. One reliable way to do it
175175 is to follow this recipe:
176176 ``` bash
177- $ git fetch upstream
178- $ git checkout -b topic_branch_name upstream/main
177+ git fetch upstream
178+ git checkout -b topic_branch_name upstream/main
179179 ```
180180
1811814 . Write your code following the outline in {ref}` sec_development_best_practices ` .
@@ -235,7 +235,7 @@ Then, continuing from above:
2352353 . Fetch the pull request, and store it as a local branch.
236236 For instance, to name the local branch ` my_pr_copy ` :
237237 ``` bash
238- $ git fetch upstream pull/854/head:my_pr_copy
238+ git fetch upstream pull/854/head:my_pr_copy
239239 ```
240240 You should probably call the branch something more descriptive,
241241 though. (Also note that you might need to put ` origin ` instead
@@ -244,7 +244,7 @@ Then, continuing from above:
244244
2452454 . Check out the pull request's local branch:
246246 ``` bash
247- $ git checkout my_pr_copy
247+ git checkout my_pr_copy
248248 ```
249249
250250Now, your repository will be in exactly the same state as
@@ -267,7 +267,7 @@ or running `uv run pytest` from this subdirectory.)
267267After you're done, you should do:
268268
269269``` bash
270- $ git checkout main
270+ git checkout main
271271```
272272
273273to get your repository back to the "main" branch of development.
@@ -289,7 +289,7 @@ and other common problems.
289289To run checks manually without committing, from the ` python/ ` subdirectory:
290290
291291``` bash
292- $ uv run prek --all-files
292+ uv run prek --all-files
293293```
294294
295295If local results differ from CI, run ` uv run prek cache clean ` to clear the cache.
@@ -526,20 +526,20 @@ The tests are defined in the `tests` directory, and run using
526526If you want to run the tests in a particular module (say, ` test_tables.py ` ), use:
527527
528528``` bash
529- $ uv run pytest tests/test_tables.py
529+ uv run pytest tests/test_tables.py
530530```
531531
532532To run all the tests in a particular class in this module (say, ` TestNodeTable ` )
533533use:
534534
535535``` bash
536- $ uv run pytest tests/test_tables.py::TestNodeTable
536+ uv run pytest tests/test_tables.py::TestNodeTable
537537```
538538
539539To run a specific test case in this class (say, ` test_copy ` ) use:
540540
541541``` bash
542- $ uv run pytest tests/test_tables.py::TestNodeTable::test_copy
542+ uv run pytest tests/test_tables.py::TestNodeTable::test_copy
543543```
544544
545545In general, you can copy-paste the string describing a failed test from the
@@ -550,7 +550,7 @@ You can also run tests with a keyword expression search. For example this will
550550run all tests that have ` TestNodeTable ` but not ` copy ` in their name:
551551
552552``` bash
553- $ uv run pytest -k " TestNodeTable and not copy"
553+ uv run pytest -k " TestNodeTable and not copy"
554554```
555555
556556When developing your own tests, it is much quicker to run the specific tests
@@ -560,41 +560,41 @@ suite each time.
560560To run all of the tests, we can use:
561561
562562``` bash
563- $ uv run pytest
563+ uv run pytest
564564```
565565
566566By default the tests are run on 4 cores, if you have more you can specify:
567567
568568``` bash
569- $ uv run pytest -n8
569+ uv run pytest -n8
570570```
571571
572572A few of the tests take most of the time, we can skip the slow tests to get the test run
573573under 20 seconds on an modern workstation:
574574
575575``` bash
576- $ uv run pytest --skip-slow
576+ uv run pytest --skip-slow
577577```
578578
579579If you have an agent running the tests in a sandboxed environment, you may need to
580580skip tests thsat require network access or FIFOs:
581581
582582``` bash
583- $ uv run pytest --skip-network
583+ uv run pytest --skip-network
584584```
585585
586586If you have a lot of failing tests it can be useful to have a shorter summary
587587of the failing lines:
588588
589589``` bash
590- $ uv run pytest --tb=line
590+ uv run pytest --tb=line
591591```
592592
593593If you need to see the output of tests (e.g. ` print ` statements) then you need to use
594594these flags to run a single thread and capture output:
595595
596596``` bash
597- $ uv run pytest -n0 -vs
597+ uv run pytest -n0 -vs
598598```
599599
600600All new code must have high test coverage, which will be checked as part of the
@@ -644,7 +644,7 @@ However, if you really need to be on the bleeding edge, you can use
644644the following command to install:
645645
646646``` bash
647- $ python3 -m pip install git+https://github.com/tskit-dev/tskit.git#subdirectory=python
647+ python3 -m pip install git+https://github.com/tskit-dev/tskit.git#subdirectory=python
648648```
649649
650650(Because the Python package is not defined in the project root directory, using pip to
@@ -689,13 +689,13 @@ to automatically format code.
689689On Debian/Ubuntu, install the system dependencies with:
690690
691691``` bash
692- $ sudo apt install libcunit1-dev ninja-build
692+ sudo apt install libcunit1-dev ninja-build
693693```
694694
695695Install meson using uv:
696696
697697``` bash
698- $ uv tool install meson
698+ uv tool install meson
699699```
700700
701701An exact version of clang-format is required because formatting rules
@@ -718,7 +718,7 @@ with a custom configuration. This is checked as part of the
718718{ref}` prek checks <sec_development_workflow_prek> ` . To manually format all files run:
719719
720720``` bash
721- $ uv run prek --all-files
721+ uv run prek --all-files
722722```
723723
724724If you are doing this in the `` c `` directory, use
@@ -730,7 +730,7 @@ prek searching for configuration within subdirectories. To avoid this, tell
730730prek where to find its config explicitly:
731731
732732``` bash
733- $ uv run prek --all-files -c prek.toml
733+ uv run prek --all-files -c prek.toml
734734```
735735
736736
@@ -743,8 +743,8 @@ is defined in `meson.build`. To set up the initial build
743743directory, run
744744
745745``` bash
746- $ cd c
747- $ meson setup build
746+ cd c
747+ meson setup build
748748```
749749
750750To setup a debug build add ` --buildtype=debug ` to the above command. This will set the ` TSK_TRACE_ERRORS `
@@ -753,15 +753,15 @@ flag, which will print error messages to `stderr` when errors occur which is use
753753To compile the code run
754754
755755``` bash
756- $ ninja -C build
756+ ninja -C build
757757```
758758
759759All the tests and other artefacts are in the build directory. Individual test
760760suites can be run, via (e.g.) ` ./build/test_trees ` . To run all of the tests,
761761run
762762
763763``` bash
764- $ ninja -C build test
764+ ninja -C build test
765765```
766766
767767For vim users, the [ mesonic] ( https://www.vim.org/scripts/script.php?script_id=5378 ) plugin
@@ -792,14 +792,14 @@ To just run a specific test on its own, provide
792792this test name as a command line argument, e.g.:
793793
794794``` bash
795- $ ./build/test_tables test_node_table
795+ ./build/test_tables test_node_table
796796```
797797
798798After making sure tests pass, you should next run the tests through valgrind,
799799to check for memory leaks, for instance:
800800
801801``` bash
802- $ valgrind ./build/test_tables test_node_table
802+ valgrind ./build/test_tables test_node_table
803803```
804804
805805While 100% test coverage is not feasible for C code, we aim to cover all code
@@ -814,31 +814,31 @@ To generate and view coverage reports for the C tests locally:
814814
815815Compile with coverage enabled:
816816 ``` bash
817- $ cd c
818- $ meson build -D b_coverage=true
819- $ ninja -C build
817+ cd c
818+ meson build -D b_coverage=true
819+ ninja -C build
820820 ```
821821
822822Run the tests:
823823 ``` bash
824- $ ninja -C build test
824+ ninja -C build test
825825 ```
826826
827827Generate coverage data:
828828 ``` bash
829- $ cd build
830- $ find ../tskit/* .c -type f -printf " %f\n" | xargs -i gcov -pb libtskit.a.p/tskit_{}.gcno ../tskit/{}
829+ cd build
830+ find ../tskit/* .c -type f -printf " %f\n" | xargs -i gcov -pb libtskit.a.p/tskit_{}.gcno ../tskit/{}
831831 ```
832832
833833The generated ` .gcov ` files can then be viewed directly with ` cat filename.c.gcov ` .
834834Lines prefixed with ` ##### ` were never executed, lines with numbers show execution counts, and lines with ` - ` are non-executable code.
835835
836836` lcov ` can be used to create browsable HTML coverage reports:
837837 ``` bash
838- $ sudo apt-get install lcov # if needed
839- $ lcov --capture --directory build-gcc --output-file coverage.info
840- $ genhtml coverage.info --output-directory coverage_html
841- $ firefox coverage_html/index.html
838+ sudo apt-get install lcov # if needed
839+ lcov --capture --directory build-gcc --output-file coverage.info
840+ genhtml coverage.info --output-directory coverage_html
841+ firefox coverage_html/index.html
842842 ```
843843
844844### Coding conventions
@@ -972,28 +972,28 @@ module and how it is built from source. The module is built automatically by
972972The simplest way to do this is to run ` make ` in the ` python ` directory:
973973
974974``` bash
975- $ make
975+ make
976976```
977977
978978If ` make ` is not available, you can run the same command manually:
979979
980980``` bash
981- $ uv run python setup.py build_ext --inplace
981+ uv run python setup.py build_ext --inplace
982982```
983983
984984It is sometimes useful to specify compiler flags when building the low
985985level module. For example, to make a debug build you can use:
986986
987987``` bash
988- $ CFLAGS=' -Wall -O0 -g' make
988+ CFLAGS=' -Wall -O0 -g' make
989989```
990990
991991If you need to track down a segfault etc, running some code through gdb can
992992be very useful. For example, to run a particular test case, we can do:
993993
994994
995995``` bash
996- $ gdb python
996+ gdb python
997997(gdb) run -m pytest tests/test_python_c.py
998998
999999
0 commit comments