|
2 | 2 |
|
3 | 3 | Contributions to scPortrait are welcome! This section provides some guidelines and tips to follow when contributing. |
4 | 4 |
|
5 | | -## Installing dev dependencies |
| 5 | +## Creating a development Environment and installing dev dependencies |
6 | 6 |
|
7 | | -In addition to the packages needed to _use_ this package, you need additional python packages to _run tests_ and _build the documentation_. It's easy to install them using `pip`: |
| 7 | +It's recommended to do development work in an isolated environment. |
| 8 | +There are number of ways to do this, including virtual environments, conda environments, and virtual machines. |
| 9 | + |
| 10 | +We use conda environments. To setup a conda environment please do the following: |
8 | 11 |
|
9 | | -```bash |
| 12 | +```console |
| 13 | +conda create -n "{dev_environment_name}" python=3.12 |
| 14 | +conda activate {dev_environment_name} |
| 15 | +``` |
| 16 | + |
| 17 | +In addition to the packages needed to _use_ this package, you need additional python packages to _run tests_ and _build the documentation_. It's easy to install them using `pip` by adding the `dev` tag: |
| 18 | + |
| 19 | +### Interactive Installation |
| 20 | +```console |
10 | 21 | git clone https://github.com/MannLabs/scPortrait |
11 | 22 | cd scPortrait |
12 | 23 | pip install -e '.[dev]' |
13 | 24 | ``` |
14 | 25 |
|
15 | | -## Code-style |
| 26 | +### Installation from PyPi |
| 27 | +```console |
| 28 | +pip install scportrait[dev] |
| 29 | +``` |
16 | 30 |
|
17 | | -This project uses [pre-commit][] to enforce consistent code-styles. On every commit, pre-commit checks will either automatically fix issues with the code, or raise an error message. |
| 31 | +## Committing Code Changes |
18 | 32 |
|
19 | | -To enable pre-commit locally, simply run |
| 33 | +We assume some familiarity with `git`. For more detailed information, we recommend the following introductions: |
20 | 34 |
|
21 | | -```console |
22 | | -pre-commit install |
23 | | -``` |
| 35 | +- [Atlassian's git tutorial][] — beginner-friendly introduction to the git command line |
| 36 | +- [Setting up git for GitHub][] — configuring git to work with your GitHub account |
24 | 37 |
|
25 | | -in the root of the repository. Pre-commit will automatically download all dependencies when it is run for the first time. |
| 38 | +In short, contributing changes to scPortrait follows this workflow: |
26 | 39 |
|
27 | | -Alternatively, you can rely on the [pre-commit.ci][] service enabled on GitHub. If you didn't run `pre-commit` before pushing changes to GitHub it will automatically commit fixes to your pull request, or show an error message. |
| 40 | +1. **Fork and clone the repository** |
| 41 | + See: [Forking and cloning](#forking-and-cloning) |
28 | 42 |
|
29 | | -If pre-commit.ci added a commit on a branch you still have been working on locally, simply use |
| 43 | +2. **Set up pre-commit hooks** |
| 44 | + Ensures consistent formatting and linting across contributions. |
| 45 | + See: [Setting up `pre-commit`](#setting-up-pre-commit) |
30 | 46 |
|
31 | | -```console |
32 | | -git pull --rebase |
33 | | -``` |
34 | | -to integrate the changes into yours. |
| 47 | +3. **Create a new branch for your changes** |
| 48 | + Development should occur on a separate branch. |
| 49 | + See: [Creating a branch for your feature](#creating-a-branch-for-your-feature) |
35 | 50 |
|
36 | | -While the [pre-commit.ci][] is useful, we strongly encourage installing and running pre-commit locally first to understand its usage. |
| 51 | +4. **Commit your changes with clear commit messages** |
| 52 | + See: [Commit Message Guidelines](#commit-message-guidelines) |
37 | 53 |
|
38 | | -## Writing documentation |
| 54 | +5. **Open a pull request** |
| 55 | + Submit your branch to the `main` branch of the main repository. |
| 56 | + See: [Open a pull request](#open-a-pull-request) |
39 | 57 |
|
40 | | -Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: |
| 58 | +We encourage small, focused pull requests, as these are easier to review and discuss. |
41 | 59 |
|
42 | | -- Google-style docstrings, where the __init__ method should be documented in its own docstring, not at the class level. |
43 | | -- there should be no specification of type in the docstrings (this should be done in the function call with mypy style type hints instead) |
44 | | -- add type hints for use with mypy |
45 | | -- example code |
46 | | -- automatic building with Sphinx |
| 60 | +### Forking and cloning |
47 | 61 |
|
48 | | -Refer to [sphinx google style docstrings][] for detailed information on writing documentation. |
| 62 | +To get the code, and be able to push changes back to the main project, you'll need to (1) fork the repository on github and (2) clone the repository to your local machine. |
49 | 63 |
|
50 | | -## Writing Tests |
| 64 | +This is very straight forward if you're using [GitHub's CLI][]: |
51 | 65 |
|
52 | | -If you are adding a new function to scPortrait please also include a unit test. |
| 66 | +```console |
| 67 | +$ gh repo fork mannlabs/scPortrait --clone --remote |
| 68 | +``` |
53 | 69 |
|
54 | | -## Running Tests |
| 70 | +This will fork the repo to your github account, create a clone of the repo on your current machine, add our repository as a remote, and set the `main` development branch to track our repository. |
55 | 71 |
|
56 | | -We use [pytest][] to test scProtrait. To run the tests, simply run `pytest .` in your local clone of the scPortrait repo. |
| 72 | +To do this manually, first make a fork of the repository by clicking the "fork" button on our main github package. Then, on your machine, run: |
57 | 73 |
|
58 | | -A lot of warnings can be thrown while running the test files. It’s often easier to read the test results with them hidden via the `--disable-pytest-warnings` argument. |
| 74 | +```console |
| 75 | +$ # Clone your fork of the repository (substitute in your username) |
| 76 | +$ git clone https://github.com/{your-username}/scPortrait.git |
| 77 | +$ # Enter the cloned repository |
| 78 | +$ cd scPortrait |
| 79 | +$ # Add our repository as a remote |
| 80 | +$ git remote add upstream https://github.com/mannlabs/scPortrait.git |
| 81 | +$ # git branch --set-upstream-to "upstream/main" |
| 82 | +``` |
59 | 83 |
|
60 | | -## Building the Documentation |
| 84 | +### setting up `pre-commit` |
61 | 85 |
|
62 | | -The docs for scPortrait are updated and built automatically whenever code is merged or commited to the main branch. To test documentation locally you need to do the following: |
| 86 | +We use [pre-commit][] to run some styling checks in an automated way. |
| 87 | +We also test against these checks, so make sure you follow them! |
63 | 88 |
|
64 | | -1. navigate into the `docs` folder in your local scPortrait clone |
65 | | -2. ensure you have a functional development environment where the additional dev dependencies (these incldue those required to build the documentation) are installed |
66 | | -3. execute: |
| 89 | +You can install pre-commit with: |
67 | 90 |
|
68 | 91 | ```console |
69 | | -make clean |
70 | | -make html |
| 92 | +$ pip install pre-commit |
71 | 93 | ``` |
72 | | -4. open the file `scportriat/docs/_build/html/index.html` in your favorite browser |
73 | 94 |
|
74 | | -## Tutorials with jupyter notebooks |
| 95 | +You can then install it to run while developing here with: |
75 | 96 |
|
76 | | -Indepth tutorials using jupyter notebooks are hosted in a dedicated repository: [scPortrait Notebooks](https://github.com/MannLabs/scPortrait-notebooks). |
| 97 | +```console |
| 98 | +$ pre-commit install |
| 99 | +``` |
77 | 100 |
|
78 | | -Please update and/or add new tutorials there. |
| 101 | +From the root of the repo. |
| 102 | + |
| 103 | +If you choose not to run the hooks on each commit, you can run them manually with `pre-commit run --files={your files}`. |
79 | 104 |
|
80 | | -## Commiting Code Changes |
| 105 | +### Creating a branch for your feature |
81 | 106 |
|
82 | | -We assume some familiarity with `git`. For more detailed information we recommend checking out these tutorials: |
| 107 | +All development should occur in branches dedicated to the particular work being done. |
| 108 | +Additionally, unless you are a maintainer, all changes should be directed at the `main` branch. |
| 109 | +You can create a branch with: |
83 | 110 |
|
84 | | -[Atlassian's git tutorial][]: Beginner friendly introductions to the git command line interface |
85 | | -[Setting up git for GitHub][]: Configuring git to work with your GitHub user account |
| 111 | +```console |
| 112 | +$ git checkout main # Starting from the main branch |
| 113 | +$ git pull # Syncing with the repo |
| 114 | +$ git switch -c {your-branch-name} # Making and changing to the new branch |
| 115 | +``` |
86 | 116 |
|
87 | 117 | ### Commit Message Guidelines |
88 | 118 |
|
89 | 119 | To keep the commit history clear and easy to navigate, we use short, descriptive commit messages with a conventional prefix indicating the type of change: |
90 | 120 |
|
91 | 121 | `[TAG] Short, clear description in imperative form` |
92 | 122 |
|
| 123 | +Following this style is encouraged for all contributions, but do not worry if you forget — maintainers may adjust commit messages during PR squash-merge. |
| 124 | + |
93 | 125 | #### Format |
94 | 126 | - **Use the imperative mood** (“Fix bug”, “Add feature”), not past tense. |
95 | 127 | - **Keep it brief** (ideally under 60 characters). |
@@ -118,101 +150,120 @@ To keep the commit history clear and easy to navigate, we use short, descriptive |
118 | 150 | | Update docs | `[DOCS] Expand documentation for project setup` | |
119 | 151 | | Ensure dtypes are consistent over all image tiles during stitching | `[FIX] Ensure dtype consistency across stitched tiles` | |
120 | 152 |
|
121 | | -#### Why This Helps |
| 153 | +### Open a pull request |
122 | 154 |
|
123 | | -- Makes pull request histories easy to scan |
124 | | -- Helps auto-generate release notes with meaningful summaries |
125 | | -- Avoids noise and ambiguity |
126 | | -- Works well with automated tools (e.g., GitHub Release Notes) |
| 155 | +When you're ready to have your code reviewed, push your changes up to your fork: |
127 | 156 |
|
128 | | -Following this style is encouraged for all contributions, but do not worry if you forget — maintainers may adjust commit messages during PR squash-merge. |
| 157 | +```console |
| 158 | +$ # The first time you push the branch, you'll need to tell git where |
| 159 | +$ git push --set-upstream origin {your-branch-name} |
| 160 | +$ # After that, just use |
| 161 | +$ git push |
| 162 | +``` |
129 | 163 |
|
130 | | -### Forking and cloning |
| 164 | +And open a pull request by going to the main repo and clicking *New pull request*. |
| 165 | +GitHub is also pretty good about prompting you to open PRs for recently pushed branches. |
131 | 166 |
|
132 | | -To get the code, and be able to push changes back to the main project, you'll need to (1) fork the repository on github and (2) clone the repository to your local machine. |
| 167 | +We'll try and get back to you soon! |
133 | 168 |
|
134 | | -This is very straight forward if you're using [GitHub's CLI][]: |
135 | 169 |
|
136 | | -```console |
137 | | -$ gh repo fork mannlabs/scPortrait --clone --remote |
138 | | -``` |
| 170 | +## Code-style |
139 | 171 |
|
140 | | -This will fork the repo to your github account, create a clone of the repo on your current machine, add our repository as a remote, and set the `main` development branch to track our repository. |
| 172 | +This project uses [pre-commit][] to enforce consistent code-styles. On every commit, pre-commit checks will either automatically fix issues with the code, or raise an error message. |
141 | 173 |
|
142 | | -To do this manually, first make a fork of the repository by clicking the "fork" button on our main github package. Then, on your machine, run: |
| 174 | +To enable pre-commit locally, simply run |
143 | 175 |
|
144 | 176 | ```console |
145 | | -$ # Clone your fork of the repository (substitute in your username) |
146 | | -$ git clone https://github.com/{your-username}/scPortrait.git |
147 | | -$ # Enter the cloned repository |
148 | | -$ cd scPortrait |
149 | | -$ # Add our repository as a remote |
150 | | -$ git remote add upstream https://github.com/mannlabs/scPortrait.git |
151 | | -$ # git branch --set-upstream-to "upstream/main" |
| 177 | +pre-commit install |
152 | 178 | ``` |
153 | 179 |
|
154 | | -### setting up `pre-commit` |
| 180 | +in the root of the repository. Pre-commit will automatically download all dependencies when it is run for the first time. |
155 | 181 |
|
156 | | -We use [pre-commit][] to run some styling checks in an automated way. |
157 | | -We also test against these checks, so make sure you follow them! |
| 182 | +Alternatively, you can rely on the [pre-commit.ci][] service enabled on GitHub. If you didn't run `pre-commit` before pushing changes to GitHub it will automatically commit fixes to your pull request, or show an error message. |
158 | 183 |
|
159 | | -You can install pre-commit with: |
| 184 | +If pre-commit.ci added a commit on a branch you still have been working on locally, simply use |
160 | 185 |
|
161 | 186 | ```console |
162 | | -$ pip install pre-commit |
| 187 | +git pull --rebase |
163 | 188 | ``` |
| 189 | +to integrate the changes into yours. |
164 | 190 |
|
165 | | -You can then install it to run while developing here with: |
| 191 | +While the [pre-commit.ci][] is useful, we strongly encourage installing and running pre-commit locally first to understand its usage. |
166 | 192 |
|
167 | | -```console |
168 | | -$ pre-commit install |
169 | | -``` |
| 193 | +## Writing documentation |
170 | 194 |
|
171 | | -From the root of the repo. |
| 195 | +Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: |
172 | 196 |
|
173 | | -If you choose not to run the hooks on each commit, you can run them manually with `pre-commit run --files={your files}`. |
| 197 | +- Google-style docstrings, where the __init__ method should be documented in its own docstring, not at the class level. |
| 198 | +- there should be no specification of type in the docstrings (this should be done in the function call with mypy style type hints instead) |
| 199 | +- add type hints for use with mypy |
| 200 | +- example code |
| 201 | +- automatic building with Sphinx |
174 | 202 |
|
175 | | -### Creating a branch for your feature |
| 203 | +Refer to [sphinx google style docstrings][] for detailed information on writing documentation. |
176 | 204 |
|
177 | | -All development should occur in branches dedicated to the particular work being done. |
178 | | -Additionally, unless you are a maintainer, all changes should be directed at the `main` branch. |
179 | | -You can create a branch with: |
| 205 | +## Building the Documentation |
| 206 | + |
| 207 | +The docs for scPortrait are updated and built automatically whenever code is merged or commited to the main branch. To test documentation locally you need to do the following: |
| 208 | + |
| 209 | +1. navigate into the `docs` folder in your local scPortrait clone |
| 210 | +2. ensure you have a functional development environment where the additional dev dependencies (these incldue those required to build the documentation) are installed |
| 211 | +3. execute: |
180 | 212 |
|
181 | 213 | ```console |
182 | | -$ git checkout main # Starting from the main branch |
183 | | -$ git pull # Syncing with the repo |
184 | | -$ git switch -c {your-branch-name} # Making and changing to the new branch |
| 214 | +make clean |
| 215 | +make html |
185 | 216 | ``` |
| 217 | +4. open the file `scportriat/docs/_build/html/index.html` in your favorite browser |
186 | 218 |
|
187 | | -### Open a pull request |
| 219 | +## Writing Tests |
188 | 220 |
|
189 | | -When you're ready to have your code reviewed, push your changes up to your fork: |
| 221 | +If you introduce a new function or modify existing functionality, be sure to include corresponding **unit tests**. Tests help ensure correctness, stability, and maintainability across the codebase. |
| 222 | + |
| 223 | +## Running Tests |
| 224 | + |
| 225 | +scPortrait uses [pytest][] for testing and maintains two categories of test suites: |
| 226 | +1. Unit Tests |
| 227 | +2. End-to-End (E2E) Tests |
| 228 | + |
| 229 | +Unit Tests are run whenever a commit is made in a PR. Before opening a pull request, ensure **unit tests pass locally**. |
| 230 | + |
| 231 | +The E2E tests are computationally more expensive and run the entire scPortrait processing pipeline and as such are much slower. These tests are only run on commits made in the main branch e.g. upon merging a PR. Before merging into `main`, please ensure **E2E tests pass**. |
| 232 | + |
| 233 | +A lot of warnings can be thrown while running the test files. It’s often easier to read the test results with them hidden via the `--disable-pytest-warnings` argument. |
190 | 234 |
|
| 235 | +### Unit Tests |
| 236 | + |
| 237 | +Unit tests validate individual functions or modules in isolation (e.g., file readers, plotting utilities, segmentation helpers). These tests are designed to be fast and run frequently during development. |
| 238 | + |
| 239 | +Run only unit tests: |
191 | 240 | ```console |
192 | | -$ # The first time you push the branch, you'll need to tell git where |
193 | | -$ git push --set-upstream origin {your-branch-name} |
194 | | -$ # After that, just use |
195 | | -$ git push |
| 241 | +pytest tests/unit_tests --disable-warnings |
196 | 242 | ``` |
197 | 243 |
|
198 | | -And open a pull request by going to the main repo and clicking *New pull request*. |
199 | | -GitHub is also pretty good about prompting you to open PRs for recently pushed branches. |
200 | | - |
201 | | -We'll try and get back to you soon! |
| 244 | +### End-to-End (E2E) Tests |
202 | 245 |
|
203 | | -## Creating a development Environment |
| 246 | +E2E tests run larger workflow scenarios to ensure that multiple components of the pipeline work correctly together (e.g., segmentation → extraction → featurization → selection). |
| 247 | +These tests are **much slower** and may require larger example data. |
204 | 248 |
|
205 | | -It's recommended to do development work in an isolated environment. |
206 | | -There are number of ways to do this, including virtual environments, conda environments, and virtual machines. |
| 249 | +Run only E2E tests: |
| 250 | +```console |
| 251 | +pytest tests/e2e_tests --disable-warnings |
| 252 | +``` |
207 | 253 |
|
208 | | -We use conda environments. To setup a conda environment please do the following: |
| 254 | +### Running All Tests |
209 | 255 |
|
| 256 | +To run both unit and E2E tests together: |
210 | 257 | ```console |
211 | | -conda create -n "{dev_environment_name}" python=3.12 |
212 | | -conda activate {dev_environment_name} |
213 | | -pip install scportrait[dev] |
| 258 | +pytest . |
214 | 259 | ``` |
215 | 260 |
|
| 261 | +## Tutorials with jupyter notebooks |
| 262 | + |
| 263 | +Indepth tutorials using jupyter notebooks are hosted in a dedicated repository: [scPortrait Notebooks](https://github.com/MannLabs/scPortrait-notebooks). |
| 264 | + |
| 265 | +Please update and/or add new tutorials there. |
| 266 | + |
216 | 267 | ## Creating a New Release |
217 | 268 |
|
218 | 269 | Before creating a release, ensure that **all tests pass** for the code currently on `main` (unit tests and end-to-end tests). If any tests fail, fix the issues before proceeding. |
|
0 commit comments