Developer documentation
If you haven't, please read the Contributing guidelines first.
If you want to make contributions to this package that involves code, then this guide is for you.
First time clone
If you have writing rights, you don't have to fork. Instead, simply clone and skip ahead. Whenever upstream is mentioned, use origin instead.
If this is the first time you work with this repository, follow the instructions below to clone the repository.
Fork this repo
Clone your repo (this will create a
git remotecalledorigin)Add this repo as a remote:
git remote add upstream https://github.com/dcelisgarza/PortfolioOptimisers.jlThis will ensure that you have two remotes in your git: origin and upstream. You will create branches and push to origin, and you will fetch and update your local main branch from upstream.
Linting and formatting
Install a plugin on your editor to use EditorConfig. This will ensure that your editor is configured with important formatting settings.
We use https://pre-commit.com to run the linters and formatters. In particular, the Julia code is formatted using JuliaFormatter.jl, so please install it globally first:
julia> # Press ]pkg> activatepkg> add JuliaFormatterTo install pre-commit, we recommend using pipx as follows:
# Install pipx following the link
pipx install pre-commitWith pre-commit installed, activate it as a pre-commit hook:
pre-commit installTo run the linting and formatting manually, enter the command below:
pre-commit run -aNow, you can only commit if all the pre-commit tests pass.
Testing
As with most Julia packages, you can just open Julia in the repository folder, activate the environment, and run test:
julia> # press ]pkg> activate .pkg> testWorking on a new issue
We try to keep a linear history in this repo, so it is important to keep your branches up-to-date.
Fetch from the remote and fast-forward your local main
git fetch upstream git switch main git merge --ff-only upstream/mainBranch from
mainto address the issue (see below for naming)git switch -c 42-add-answer-universePush the new local branch to your personal remote repository
git push -u origin 42-add-answer-universeCreate a pull request to merge your remote branch into the org main.
Branch naming
- If there is an associated issue, add the issue number.
- If there is no associated issue, and the changes are small, add a prefix such as "typo", "hotfix", "small-refactor", according to the type of update.
- If the changes are not small and there is no associated issue, then create the issue first, so we can properly discuss the changes.
- Use dash separated imperative wording related to the issue (e.g.,
14-add-tests,15-fix-model,16-remove-obsolete-files).
Commit message
- Use imperative or present tense, for instance: Add feature or Fix bug.
- Have informative titles.
- When necessary, add a body with details.
- If there are breaking changes, add the information to the commit message.
Before creating a pull request
Try to create "atomic git commits" (recommended reading: The Utopic Git History).
Make sure the tests pass.
Make sure the pre-commit tests pass.
Fetch any
mainupdates from upstream and rebase your branch, if necessary:bash git fetch upstream git rebase upstream/main BRANCH_NAMEThen you can open a pull request and work with the reviewer to address any issues.
How a change reaches main
Each issue states its route in a **Lands on:** line, and every pull request merges by squash. The decision is ADR 0240. The first true row gives the value:
| True when | **Lands on:** | Branch |
|---|---|---|
| A decision, a measurement or a research ticket | no code | none |
Not a sweep sub-issue, not an issue that a sweep ticket or the review of dev-sweep found, and the review of an open pull request or the work on it found the issue, or that pull request is wrong or incomplete without the work, makes the defect, makes it worse or makes it reachable, or adds or changes what the work edits | same branch #<pr> | the head branch of the pull request |
| The work needs code that only an open pull request has, and it is a review of its own | stacked on #<pr> | dev-<feature>, a layer above that pull request |
| As the row above, but the work can wait for the merge | sweep after #<pr>, dev after #<pr>, own branch after #<pr> | as below, when the merge is there |
A ticket of a map whose tickets make sense on main only together | map #<map> | dev-<feature>, one pull request for the map |
An issue that a sweep ticket, the review of dev-sweep or the review of a merged pull request found | own branch | dev-<feature>, with its own pull request |
A sweep sub-issue of #404, and dev-sweep or main has the file | sweep | dev-sweep, which the maintainer merges as a batch |
An ergonomics change, a small performance fix, an unusual composition bug or a docs fix, and dev or main has the code | dev | dev, which the maintainer merges as a batch |
| Anything else that lands, such as a standalone feature or an important correctness fix | own branch | dev-<feature>, with its own pull request |
The maintainer can name another route for an issue. For a pull request whose head is dev, a row that names the pull request gives dev, and for one whose head is dev-sweep, it gives sweep. code_health/lands_on.sh checks the line, and the workflow Route gives each issue a label for its route.
A pull request is standalone when its base is main. It is a layer when its base is the branch of another pull request. GitHub then shows the diff of the layer alone, applies the rules of main to it, and merges the layers from the bottom up. A stack has three layers at most. The land-work skill under .claude/skills/ gives the steps.
A review of each pull request is recorded by code_health/review_stamp.sh, as a GitHub review and as the commit status Review. A push keeps the status when the diff did not change. A pull request does not merge while an issue that says same branch for it is open.
The other rules of a change are these:
- Name a branch for its feature, with the prefix
dev-, for exampledev-concentration-limit. A branch that holds research alone can take the prefixresearch-. It gets no push checks, and it does not merge intomain. - A push to a branch of this repository runs the full CI, and the pull request shows those checks. A merge into
mainwaits for them (ADR 0220). - A branch of a fork gets no push checks in this repository, so its pull request cannot merge. The maintainer pushes the branch of a fork to a
dev-branch here, and the pull request from that branch merges. - The base of a pull request need not be current. Rebase only when GitHub shows a conflict with
main. - Name the issue in the commit message, as
Fix #<issue>: …. A pull request of its own also writesCloses #<issue>in its body, so that the pull request links the issue. - Close the issue when the push that holds the last part of its fix reaches the remote branch, with
gh issue close <issue> --comment "Fixed in <sha> on <branch>.". Do not wait for the merge intomain. A commit of a part of the work namesPart of #<issue>: …, and the issue stays open.
When a code-health gate turns red
Two checks hold the numbers that issue #250 asks to fall: Complexity and JET. Both are a ratchet. A file passes when its number has not risen above the number code_health/ records for it, so neither check ever asks you to improve a number you did not cause. A file far above every threshold is green while its number holds steady.
The Complexity check carries a third ratchet beside the two complexity ones, and it reads differently. The size ratchet counts the code lines in a file, where a docstring line, a comment line and a blank line are not code. A file's ceiling there is the greater of 500 and the number the baseline records for it, so a file under 500 code lines is free to grow and a file over 500 may fall and may not rise. See docs/adr/0101-the-size-gate-counts-code-lines-and-binds-over-a-threshold.md.
When one turns red, the run names every offending file, the metric, the baseline number and the new one. The design picks the route, not the number. Take one of three routes.
Do not change a signature, a type bound or the home of a function only to pass a ratchet. The gate then goes green, and the design gets worse. An argument removed for a read of a scoped value hides a dependency, and a direct test of the function must then set the scope (#2060). See When the correct form raises a number.
Lower the number, when the lower form is also the better design. For a complexity number the file's number is the maximum over its definitions, so only the worst definition moves it. For the size ratchet, move code to the file of its subject, or delete it. A docstring costs nothing there.
Dismiss the report, for
JETalone. A Dismissal says that a class of report is not a real defect. It cites a Rationale by name, and the two halves have different owners: citing an approved Rationale is bookkeeping that any contributor may do, and adding a new Rationale is a claim that some code is correct. See Dismissing a JET report.Record the rise, when the higher number comes from the correct form. When the correct form raises a number states what the correct form is and the threshold that still binds. A number may rise, but only through a diff that a person approved. Run the refresh with the flag that names the act:
julia --project=code_health code_health/complexity.jl refresh --accept-riseYou do not need to measure it yourself. The run that trips uploads the file that clears it. Download the run's Refresh Artifact from its page, put the file at its committed path under
code_health/, and commit it. That needs no Julia at all.
What a contributor without write access cannot finish alone
Route 2, and only when the Rationale is new. A new [rationale.…] block needs the maintainer, and CI flags a pull request that adds one. Cite an existing Rationale and nothing blocks you; write a new one and say so in the pull request, so a maintainer can rule on it.
Routes 1 and 3 are open to everybody. A fork pull request runs both checks and can download both artifacts, because the artifact attaches to the run in this repository and this repository is public. One thing a fork contributor cannot do is re-run a check, so a transient failure needs a new push from you or a re-run by a maintainer.
Two red cases the artifact does not clear on its own
- A renamed file under
JET. The Report Fingerprint holds the file, so a rename breaks every Dismissal on it. The refresh carries the row to the new path and prints the Dismissal lines that now name a dead path; you editcode_health/rulings.tomlyourself. - A tracked
.jlfile that is neither measured nor a named Unmeasured Path. Add an[[unmeasured_path]]entry with a reason, or move the file undersrc/orext/.
In both, the artifact is correct and worth committing. It is not the whole fix.
The maintenance loop that drives these numbers down, rather than merely holding them, is Code health: the maintenance loop.
Writing documentation
Please document new features. The documentation must include:
- Links to related functions and types.
- Exhaustive descriptions of the arguments, keyword arguments, type information, and data validation.
- Exhaustive usage examples as REPL-style
jldoctestblocks, they should maximize code coverage.
The Capability Catalogue
The capability catalogue is the user-facing inventory of everything the package can do, grouped by the job each thing does. It is generated: docs/capability_catalogue.jl curates only the grouping, and every description is the first sentence of the corresponding docstring, so a description cannot drift from the type it describes.
A new type or a new export takes its place in the catalogue in the same change. test/test_26_docs.jl fails if a name on the Choice Surface is missing, and the docs build refuses to render an incomplete page. The section Capability Catalogue (required for every new public-facing addition) of .github/instructions/julia-source-code.instructions.md owns the rule: which names are on the surface, the group a name takes, and the NOT_A_FEATURE and NOT_A_CHOICE lists.
Because descriptions come from docstrings, a type's first sentence has to stand alone in a bullet list. See the summary-sentence rules in .github/instructions/julia-docstrings.instructions.md.
Building and viewing the documentation locally
Following the latest suggestions, we recommend using LiveServer to build the documentation. Here is how you do it:
Run
julia --project=docsto open Julia in the environment of the docs.If this is the first time building the docs
- Press
]to enterpkgmode - Run
pkg> instantiate. The[sources]entry ofdocs/Project.tomlalready points the docs at the development version of the package, so do not runpkg> dev ., which rewrites that entry. - Press backspace to leave
pkgmode
- Press
Run
julia> using LiveServerRun
julia> servedocs()
A preview of the documentation of a pull request
The documentation of each pull request from a branch of this repository deploys as a preview. A pull request from a fork builds the documentation but deploys no preview. The preview is at https://dcelisgarza.github.io/PortfolioOptimisers.jl/previews/PR<number>/. Each preview is a full build, and GitHub Pages refuses a site above 10 GiB, so the Doc preview cleanup workflow deletes a preview when its pull request closes. Each week it also deletes a preview whose pull request is not open. After each documentation run of a pull request, it keeps only the previews of the eight open pull requests updated last (PAGES_KEEP_PREVIEWS). The next push to a pull request deploys its preview again.
The same workflow keeps the documentation of the five newest minor series online, and of each series only its newest patch. It deletes the other versions. A link into a deleted version, such as /v0.34.3/, stops resolving. The version selector lists only the newest patch of each series.
Making a new release
A release can come from any commit of main whose push checks are green. Never register a commit whose checks are red.
Each pull request into main that changes a file under src/ or ext/ is one release, and the merge queue of issue #2340 holds its place and its version. A release that breaks an interface takes the next minor version, for example 0.35.0 after 0.34.24. Each other release takes the next patch, for example 0.34.25. A bug fix is not a break, and § A design is chosen by the standing test of .github/instructions/julia-source-code.instructions.md states its version and when it takes a page of the migration guide.
A pull request that changes no file under src/ or ext/, such as a change to CI, to a skill or to a page of the docs alone, takes no version and is no release. It has no fold, no release notes and no turn push.
A release takes these steps:
- The review of the pull request checks that it has a page of
docs/src/next_release/for each break and for each bug fix that § A design is chosen by the standing test of.github/instructions/julia-source-code.instructions.mdgives a page, and no page for another bug fix. Then the review folds the pages into the migration guide withjulia docs/fold_next_release.jl <from> <to>, for example with0.34.21 0.34.22, and refreshes the prose baseline withjulia --project=code_health code_health/prose.jl refresh. A release with no page has no fold. - The review also writes the release notes in the description of the pull request, in one fenced block that starts with
Release notes:. The notes have the form of the registration comment on issue #50, and § Review of theland-workskill gives the form. - When the pull request before it has merged, its turn push merges
mainand setsversioninProject.toml. When the queue moved after the review, the turn push also corrects the heading of the folded section. After the merge ofmain, it runsjulia --project=code_health code_health/docstrings.jl scanon the files undersrc/andext/that the pull request changes. It pastes each row that rose intocode_health/docstrings_baseline.toml, and it runstest/test_90_docstring_census.jl. § The prose follows ASD-STE100, The Gate, of.github/instructions/julia-docstrings.instructions.mdowns this exception to the ratchet. Wait for the checks to pass. - Squash-merge the pull request.
- On issue #50, write a comment with
@JuliaRegistrator registeron its first line, then an empty line and the block of release notes of the pull request. The comment registers the head ofmain, so write it before the next merge. Write it only when the registry pull request of the version before it has merged in General, because AutoMerge refuses a version that skips a version.
The check Version of each pull request into main runs .github/version_check.sh. It holds two rules against main. First, a pull request that changes the code under src/ or ext/ holds a version above the one of main. A change of a .md file there, or of docstring prose alone, is no code: code_health/gate_reach.jl gives it the class prose, and it takes no version (#2459). A change of a jldoctest line or of a string literal is a release. Second, when the description holds a line Release notes:, the first vX.Y.Z after it is the version of the head. The check does not ask for the release notes: the review writes them. A merge of main through the web page brings back the version line of main, and this check then turns red.
Write the mention of the registration bot only in that comment on #50. The bot answers a mention in a pull request with a comment that does nothing.
After that, you only need to wait and verify:
- Wait for the bot to comment (should take < 1m) with a link to a PR to the registry
- Follow the link and wait for a comment on the auto-merge
- The comment should said all is well and auto-merge should occur shortly
- After the merge happens, TagBot will trigger and create a new GitHub tag. Check on https://github.com/dcelisgarza/PortfolioOptimisers.jl/releases
- After the release is create, a "docs" GitHub action will start for the tag.
- After it passes, a deploy action will run.
- After that runs, the stable docs should be updated. Check them and look for the version number.