Skip to content

Commit 29d91d2

Browse files
committed
deploy: 5475b47
1 parent daad32d commit 29d91d2

19 files changed

Lines changed: 3239 additions & 64 deletions
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Contributing
2+
3+
A guide to contributing code to any of the Tools for Experiments repositories.
4+
5+
---
6+
7+
## Workflow overview
8+
9+
### 1. Fork the repository
10+
11+
Go to the GitHub page of the repository you want to contribute to and click **Fork** in the top-right corner. This creates a personal copy of the repo under your GitHub account.
12+
13+
### 2. Clone your fork locally
14+
15+
```bash
16+
git clone https://github.com/<your-username>/<repo-name>.git
17+
cd <repo-name>
18+
```
19+
20+
### 3. Create a new branch
21+
22+
Never commit directly to `main`. Create a dedicated branch for your changes:
23+
24+
```bash
25+
git checkout -b my-feature-branch
26+
```
27+
28+
Use a short, descriptive name (e.g. `fix-calibration-bug`, `add-sweep-tool`).
29+
30+
### 4. Make your changes
31+
32+
Edit the code, add new files, or fix bugs. Once you're happy with the changes, stage and commit them:
33+
34+
```bash
35+
git add <files>
36+
git commit -m "Short description of what you changed"
37+
```
38+
39+
### 5. Set up the environment with uv
40+
41+
Each repository uses uv to manage its environment. From the root of the cloned repo, run:
42+
43+
```bash
44+
uv sync
45+
```
46+
47+
This installs all dependencies (including dev tools like `ruff`, `mypy`, and `pytest`) into a local `.venv`. You don't need to activate it — prefix every command with `uv run` and uv will use the right environment automatically.
48+
49+
### 6. Run the checks locally
50+
51+
Before pushing, run the three checks below to catch issues early. **The CI pipeline runs the same checks automatically and will block your pull request from merging if any of them fail.**
52+
53+
Run all commands from the root of the repository (where `pyproject.toml` lives).
54+
55+
#### Linting — ruff
56+
57+
[ruff](https://docs.astral.sh/ruff/) checks code style and common errors:
58+
59+
```bash
60+
uv run ruff check
61+
```
62+
63+
The `.` (current directory) is implied when no path is given, so running `uv run ruff check` from the repo root checks all files in the project. To auto-fix issues where possible:
64+
65+
```bash
66+
uv run ruff check --fix
67+
```
68+
69+
#### Type checking — mypy
70+
71+
[mypy](https://mypy.readthedocs.io/) checks for type errors:
72+
73+
```bash
74+
uv run mypy
75+
```
76+
77+
Again, run this from the repo root — mypy reads the project configuration from `pyproject.toml` and knows which files to check.
78+
79+
Fix any reported type errors before submitting.
80+
81+
#### Tests — pytest
82+
83+
[pytest](https://docs.pytest.org/) runs the test suite:
84+
85+
```bash
86+
uv run pytest
87+
```
88+
89+
All tests must pass. If you added new functionality, add tests for it too.
90+
91+
### 7. Push and open a pull request
92+
93+
```bash
94+
git push origin my-feature-branch
95+
```
96+
97+
Then go to your fork on GitHub and click **Compare & pull request**. Fill in a description of what your changes do and why, then submit.
98+
99+
The CI pipeline will run `ruff`, `mypy`, and `pytest` automatically. You can follow the results in the **Checks** tab of your pull request. All checks must pass before the PR can be merged.
100+
101+
---
102+
103+
## Contributing to the documentation
104+
105+
The docs are written in Markdown using [MyST](https://myst-parser.readthedocs.io/) and built with [Sphinx](https://www.sphinx-doc.org/). Every page is a `.md` file inside the `docs/` directory.
106+
107+
### How the docs are organized
108+
109+
```
110+
docs/
111+
├── conf.py # Sphinx configuration
112+
├── index.md # Top-level table of contents
113+
├── guides/
114+
│ ├── index.md # Section table of contents
115+
│ └── *.md # Individual guide pages
116+
├── contributing/
117+
│ └── *.md
118+
└── examples/
119+
└── *.md
120+
```
121+
122+
Each `index.md` contains a `{toctree}` directive that lists the pages in that section. When you add a new page, register it there.
123+
124+
### Adding a new page
125+
126+
1. Create a new `.md` file in the appropriate section folder.
127+
2. Add its filename (without extension) to the `{toctree}` in that folder's `index.md`:
128+
129+
````markdown
130+
```{toctree}
131+
:maxdepth: 2
132+
133+
existing-page
134+
your-new-page
135+
```
136+
````
137+
138+
### Editing an existing page
139+
140+
Just edit the `.md` file directly — it is plain Markdown with optional MyST directives.
141+
142+
### Building the docs locally
143+
144+
The docs repo has its own `pyproject.toml` at the root of `toolsforexperiments/` that includes Sphinx and its dependencies. First sync the environment:
145+
146+
```bash
147+
uv sync
148+
```
149+
150+
Then build the HTML from the `docs/` directory:
151+
152+
```bash
153+
cd docs
154+
uv run make html
155+
```
156+
157+
The output is written to `docs/build/html/`. Open `docs/build/html/index.html` in your browser to preview the result:
158+
159+
```bash
160+
open docs/build/html/index.html # macOS
161+
xdg-open docs/build/html/index.html # Linux
162+
```
163+
164+
To do a clean rebuild from scratch (useful if pages aren't updating):
165+
166+
```bash
167+
cd docs
168+
uv run make clean html
169+
```
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# Setting Up Your Environment
2+
3+
A guide to getting your development environment set up for working with Tools for Experiments.
4+
5+
---
6+
7+
## Option 1: Using uv
8+
9+
### What is uv?
10+
11+
[uv](https://docs.astral.sh/uv/) is a fast Python package and project manager written in Rust, developed by Astral (the team behind `ruff`). It serves as a drop-in replacement for `pip`, `pip-tools`, `virtualenv`, and more — but orders of magnitude faster.
12+
13+
Key concepts:
14+
- **`pyproject.toml`**: The single source of truth for your project's dependencies and metadata, following the modern Python packaging standard.
15+
- **`uv.lock`**: A lockfile automatically generated by uv that pins exact versions of all dependencies (direct and transitive) for reproducible environments.
16+
- **Editable installs**: uv supports installing local packages in editable mode (`editable = true`), meaning changes to the source code of those packages are immediately reflected without reinstalling.
17+
- **Virtual environments**: uv automatically creates and manages a `.venv` in your project directory.
18+
19+
### Installing uv
20+
21+
```bash
22+
curl -LsSf https://astral.sh/uv/install.sh | sh
23+
```
24+
25+
Or via pip:
26+
27+
```bash
28+
pip install uv
29+
```
30+
31+
### Project structure: `pyproject.toml`
32+
33+
Each measurement or experiment folder should have a `pyproject.toml` that declares its dependencies. For packages that live locally on your machine (like `instrumentserver` or `labcore`), use `[tool.uv.sources]` to point uv to their local paths with editable installs:
34+
35+
```toml
36+
[project]
37+
name = "testing-uv-env" # (1) change to your project name
38+
version = "0.1.0"
39+
description = "Add your description here"
40+
readme = "README.md"
41+
requires-python = ">=3.12"
42+
dependencies = [
43+
"instrumentserver", # (2) list every package you need here
44+
"labcore", # one string per package, comma-separated
45+
]
46+
47+
[tool.uv.sources]
48+
# (3) for each local package listed above, add an entry here pointing to its
49+
# location on your machine. Paths are relative to this pyproject.toml file.
50+
instrumentserver = { path = "../../github/instrumentserver", editable = true }
51+
labcore = { path = "../../github/labcore", editable = true }
52+
```
53+
54+
**What you need to change:**
55+
56+
1. **`name`** — set it to something that identifies your experiment or measurement folder.
57+
58+
2. **`dependencies`** — list all packages your code needs. Regular PyPI packages (e.g. `numpy`, `matplotlib`) just go here as plain strings and uv will fetch them automatically. Local packages also go here — they need a matching entry in `[tool.uv.sources]`.
59+
60+
3. **`[tool.uv.sources]`** — for every local package in `dependencies`, add a line with the relative path from this `pyproject.toml` to that package's root directory (the folder that contains its own `pyproject.toml` or `setup.py`). Keep `editable = true` so that code changes in those repos take effect immediately.
61+
62+
For example, if your experiment folder is at `~/projects/my-experiment/` and `labcore` is cloned at `~/github/labcore/`, the relative path would be `../../github/labcore`.
63+
64+
### Creating and syncing the environment
65+
66+
From the directory containing your `pyproject.toml`, run:
67+
68+
```bash
69+
uv sync
70+
```
71+
72+
This will:
73+
1. Create a `.venv` virtual environment in the current directory (if it doesn't exist).
74+
2. Install all dependencies listed in `pyproject.toml`.
75+
3. Install the local editable packages from the paths defined in `[tool.uv.sources]`.
76+
4. Generate or update `uv.lock`.
77+
78+
### Activating the environment
79+
80+
```bash
81+
source .venv/bin/activate
82+
```
83+
84+
Or run commands directly without activating:
85+
86+
```bash
87+
uv run python my_script.py
88+
uv run jupyter lab
89+
```
90+
91+
### Adding new dependencies
92+
93+
```bash
94+
uv add some-package
95+
```
96+
97+
This updates `pyproject.toml` and `uv.lock` automatically.
98+
99+
---
100+
101+
## Option 2: Using conda / mamba
102+
103+
[conda](https://docs.conda.io/) is a cross-platform package and environment manager. [mamba](https://mamba.readthedocs.io/) is a faster drop-in replacement for conda that uses the same commands and environment files.
104+
105+
### Installing conda or mamba
106+
107+
- **Miniforge** (recommended — ships with mamba by default):
108+
Download from [github.com/conda-forge/miniforge](https://github.com/conda-forge/miniforge/releases) and follow the installer instructions.
109+
110+
- **Miniconda** (conda only):
111+
Download from [docs.conda.io/en/latest/miniconda.html](https://docs.conda.io/en/latest/miniconda.html).
112+
113+
### Creating an environment from the provided file
114+
115+
A base `environment.yml` is provided at the root of this repository with a standard set of dependencies:
116+
117+
```yaml
118+
name: labcore
119+
channels:
120+
- conda-forge
121+
- defaults
122+
dependencies:
123+
- python=3.10
124+
- jupyterlab
125+
- jupyter_bokeh
126+
- qcodes=0.44.1
127+
- bokeh
128+
- pandas
129+
- xarray
130+
- matplotlib
131+
- numpy=1.26.4
132+
- scipy
133+
- scikit-learn
134+
- seaborn
135+
- lmfit
136+
- h5py=3.10.0
137+
- xhistogram
138+
- holoviews
139+
- panel
140+
- param
141+
- hvplot
142+
- versioningit
143+
- qtpy
144+
- pip
145+
- gitpython
146+
- watchdog
147+
- pywavelets
148+
```
149+
150+
To create the environment from it, run from the root of the repository:
151+
152+
```bash
153+
conda env create -f environment.yml
154+
conda activate labcore
155+
```
156+
157+
With mamba (faster):
158+
159+
```bash
160+
mamba env create -f environment.yml
161+
mamba activate labcore
162+
```
163+
164+
### Adding or changing dependencies
165+
166+
If you need extra packages not in `environment.yml`, install them into the active environment:
167+
168+
```bash
169+
conda install -c conda-forge some-package
170+
```
171+
172+
For packages only available on PyPI:
173+
174+
```bash
175+
pip install some-package
176+
```
177+
178+
### Installing local packages in editable mode
179+
180+
For local repositories like `instrumentserver` or `labcore`, install them in editable mode using pip. Replace the paths below with the actual location of each repo on your machine:
181+
182+
```bash
183+
pip install -e /path/to/instrumentserver
184+
pip install -e /path/to/labcore
185+
```
186+
187+
For example, if your repos live in `~/github/`:
188+
189+
```bash
190+
pip install -e ~/github/instrumentserver
191+
pip install -e ~/github/labcore
192+
```
193+
194+
The `-e` flag means editable — any changes you make to the source code of those packages are immediately active without needing to reinstall.
195+
196+
### Exporting and sharing your environment
197+
198+
To export your environment so others can reproduce it:
199+
200+
```bash
201+
conda env export > environment.yml
202+
```
203+
204+
To recreate it from the file:
205+
206+
```bash
207+
conda env create -f environment.yml
208+
```
209+
210+
For a more portable export (cross-platform, without build strings):
211+
212+
```bash
213+
conda env export --no-builds > environment.yml
214+
```

_sources/guides/index.md.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Guides
2+
3+
General guides and resources for working within the Tools for Experiments organization.
4+
5+
```{toctree}
6+
:maxdepth: 2
7+
8+
organization
9+
environment_setup
10+
contributing
11+
```

0 commit comments

Comments
 (0)