@@ -98,14 +98,14 @@ the development workflows of all tskit-dev packages are organised around
9898using uv, and therefore we strongly recommend using it. Uv is straightforward
9999to install, and not invasive (existing Python installations can be completely
100100isolated if you don't use features like `` uv tool `` etc which update your
101- $HOME/.local/bin). Uv manages an isolated local environment per project
101+ `` $HOME/.local/bin `` ). Uv manages an isolated local environment per project
102102and allows us to deterministically pin package versions and easily switch
103103between Python versions, so that CI environments can be replicated exactly
104104locally.
105105
106106The packages needed for development are specified as dependency groups
107107in `` python/pyproject.toml `` and managed with [ uv] ( https://docs.astral.sh/uv/ ) .
108- Install all development dependencies using :
108+ Install all development dependencies by running, from the ` python/ ` directory :
109109
110110``` bash
111111$ uv sync
@@ -129,7 +129,8 @@ To get a local git development environment, please follow these steps:
129129 ``` bash
130130 $ git clone git@github.com:YOUR_GITHUB_USERNAME/tskit.git
131131 ```
132- - Install the {ref}` sec_development_workflow_prek ` pre-commit hook:
132+ - Install the {ref}` sec_development_workflow_prek ` pre-commit hook
133+ (again from the `` python/ `` subdirectory):
133134 ``` bash
134135 $ uv run prek install
135136 ```
@@ -201,7 +202,7 @@ skip to {ref}`sec_development_workflow_anothers_commit`.
201202 to document any breaking changes separately in a "breaking changes" section.
202203
2032048 . Push your changes to your topic branch and either open the PR or, if you
204- opened a draft PR above change it to a non-draft PR by clicking "Ready to
205+ already opened a draft PR change it to a non-draft PR by clicking "Ready to
205206 Review".
206207
2072089 . The tskit community will review the code, asking you to make changes where appropriate.
@@ -258,10 +259,10 @@ subdirectory.
258259
259260To test out changes to the * code* , you can change to the ` python/ ` subdirectory,
260261and run ` make ` to compile the C code.
261- If you then execute ` python ` from this subdirectory (and only this one!),
262+ If you then execute python commands from this subdirectory (and only this one!),
262263it will use the modified version of the package.
263- (For instance, you might want to
264- open an interactive ` python ` shell from the ` python/ ` subdirectory,
264+ (For instance, you might want to open an interactive python shell by running
265+ ` uv run python` in the ` python/ ` subdirectory,
265266or running ` uv run pytest ` from this subdirectory.)
266267
267268After you're done, you should do:
@@ -272,7 +273,8 @@ $ git checkout main
272273
273274to get your repository back to the "main" branch of development.
274275If the pull request is changed and you want to do the same thing again,
275- then first * delete* your local copy (by doing ` git branch -d my_pr_copy ` )
276+ then to avoid conflicts with any changes you might have made,
277+ first * delete* your local copy (by doing ` git branch -d my_pr_copy ` )
276278and repeat the steps again.
277279
278280
@@ -285,13 +287,7 @@ On each commit a [prek](https://prek.j178.dev) hook will run checks for
285287code style (see the {ref}` sec_development_python_style ` section for details)
286288and other common problems.
287289
288- To install the hook:
289-
290- ``` bash
291- $ uv run prek install
292- ```
293-
294- To run checks manually without committing:
290+ To run checks manually without committing, from the ` python/ ` subdirectory:
295291
296292``` bash
297293$ uv run prek --all-files
@@ -467,6 +463,9 @@ See :ref:`sec_development_documentation_cross_referencing` for details.
467463The :meth:`.TreeSequence.trees` method returns an iterator.
468464````
469465
466+ Some errors may occur because of out-of-date cached results,
467+ which can be cleared by running ` make clean ` .
468+
470469(sec_development_python)=
471470
472471
@@ -544,6 +543,10 @@ To run a specific test case in this class (say, `test_copy`) use:
544543$ uv run pytest tests/test_tables.py::TestNodeTable::test_copy
545544```
546545
546+ In general, you can copy-paste the string describing a failed test from the
547+ output of pytest to re-run just that test (including specific parametrized
548+ arguments present as ` [args] ` ).
549+
547550You can also run tests with a keyword expression search. For example this will
548551run all tests that have ` TestNodeTable ` but not ` copy ` in their name:
549552
@@ -793,6 +796,13 @@ this test name as a command line argument, e.g.:
793796$ ./build/test_tables test_node_table
794797```
795798
799+ After making sure tests pass, you should next run the tests through valgrind,
800+ to check for memory leaks, for instance:
801+
802+ ``` bash
803+ $ valgrind ./build/test_tables test_node_table
804+ ```
805+
796806While 100% test coverage is not feasible for C code, we aim to cover all code
797807that can be reached. (Some classes of error such as malloc failures
798808and IO errors are difficult to simulate in C.) Code coverage statistics are
@@ -1029,7 +1039,7 @@ Continuous integration is handled by [GitHub Actions](https://help.github.com/en
10291039tskit uses shared workflows defined in the
10301040[ tskit-dev/.github] ( https://github.com/tskit-dev/.github ) repository:
10311041
1032- - ** lint** — runs prek against all files
1042+ - ** lint** — runs ruff and clang (using prek) against all files
10331043- ** python-tests** — runs the pytest suite with coverage on Linux, macOS and Windows
10341044- ** python-c-tests** — builds the C extension with coverage and runs low-level tests
10351045- ** c-tests** — runs C unit tests under gcc, clang, and valgrind
@@ -1050,6 +1060,9 @@ tskit codebase.
10501060Note that this guide covers the most complex case of adding a new function to both
10511061the C and Python APIs.
10521062
1063+ 0 . Draft a docstring for your function, that describes exactly what the function
1064+ takes as arguments and what it returns under what conditions. Update this
1065+ docstring as you go along and make modifications.
105310661 . Write your function in Python: in ` python/tests/ ` find the test module that
10541067 pertains to the functionality you wish to add. For instance, the kc_distance
10551068 metric was added to
@@ -1085,7 +1098,7 @@ the C and Python APIs.
10851098 the example of other tests, you might need to only add a single line of code
10861099 here. In this case, the tests are well factored so that we can easily compare
10871100 the results from both the Python and C versions.
1088- 9 . Write a docstring for your function in the Python API: for instance, the kc_distance
1101+ 9 . Finalize your docstring and insert it into the Python API: for instance, the kc_distance
10891102 docstring is in
10901103 [ tskit/python/tskit/trees.py] ( https://github.com/tskit-dev/tskit/blob/main/python/tskit/trees.py ) .
10911104 Ensure that your docstring renders correctly by building the documentation
0 commit comments