Skip to content

Commit 034a527

Browse files
authored
[docs] add a contributing page to the developer documentation (#2884)
1 parent a8aa0b0 commit 034a527

File tree

2 files changed

+151
-1
lines changed

2 files changed

+151
-1
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ const _PAGES = [
8383
"API Reference" => "submodules/Test/reference.md",
8484
],
8585
],
86-
"Developer Docs" => ["developer/checklists.md"],
86+
"Developer Docs" =>
87+
["developer/checklists.md", "developer/contributing.md"],
8788
"Release notes" => "release_notes.md",
8889
]
8990

docs/src/developer/contributing.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# [Contributing](@id contributing_to_mathoptinterface)
2+
3+
This document explains how to contribute code to MathOptInterface.
4+
5+
## Obtain the source code
6+
7+
The easiest way to obtain the source code for MathOptInterface is to run:
8+
```julia
9+
julia> import Pkg
10+
11+
julia> Pkg.dev("MathOptInterface")
12+
```
13+
This will download the MathOptInterface Git repository to `~/.julia/dev/MathOptInterface`.
14+
If you're on Windows, this will be `C:\\Users\\<my_name>\\.julia\\dev\\MathOptInterface`.
15+
16+
Alternatively, you can use `git` to clone the source to a directory of your
17+
choosing:
18+
```
19+
$ cd /some/local/path
20+
$ git clone https://github.com/jump-dev/MathOptInterface.jl.git
21+
```
22+
23+
## Make changes
24+
25+
Code development in MathOptInterface follows typical git development practices.
26+
27+
First, go to [https://github.com/jump-dev/MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl)
28+
and click the "Fork" button in the top-right corner. This will create a copy of
29+
MathOptInterface under your GitHub account.
30+
31+
Then, tell your local git about your new fork:
32+
```
33+
export GITHUB_ACCOUNT="odow" # Replace with your name
34+
cd ~/.julia/dev/MathOptInterface
35+
git remote add ${GITHUB_ACCOUNT} https://github.com/${GITHUB_ACCOUNT}/MathOptInterface.jl.git
36+
```
37+
38+
Before making changes to the source, ensure that you have the latest copy, and
39+
checkout a new branch:
40+
```
41+
git checkout master
42+
git pull
43+
git checkout -b my_new_branch
44+
```
45+
46+
Now you can make changes by editing the local source code. See [Running the tests](@ref)
47+
for how to check if your code passes the tests.
48+
49+
Once you have finished making changes, make a commit and push your branch to
50+
GitHub:
51+
```
52+
git add .
53+
git commit -m "A message describing what you changed"
54+
git push -u $GITHUB_ACCOUNT my_new_branch
55+
```
56+
Finally, go to [https://github.com/jump-dev/MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl)
57+
and follow the instructions that pop up to open a pull request.
58+
59+
## Running the tests
60+
61+
There are lot of tests in MathOptInterface. Running them in their entirety can
62+
take a long time.
63+
64+
The easiest way to run the tests is to run:
65+
```julia
66+
julia> import Pkg
67+
68+
julia> Pkg.test("MathOptInterface")
69+
```
70+
The downside to the approach is that it will run all of the tests, and it will
71+
recompile MathOptInterface from scratch, even if you have made very trivial
72+
changes to the source code.
73+
74+
A faster approach is to use [Revise.jl](https://github.com/timholy/Revise.jl).
75+
76+
First, install Revise in your global package environment:
77+
```
78+
$ julia
79+
80+
julia> import Pkg
81+
82+
julia> Pkg.add("Revise")
83+
```
84+
85+
Then, `cd` to the source code of MathOptInterface, and start Julia with the
86+
project set to `.` (for `~/.julia/dev/MathOptInterface/Project.toml`):
87+
```
88+
$ cd ~/.julia/dev/MathOptInterface
89+
$ julia --project=.
90+
```
91+
92+
To run the tests, load Revise, and then include the relevant test file. For
93+
example:
94+
```julia
95+
julia> using Revise
96+
97+
julia> include("test/Nonlinear/runtests.jl")
98+
99+
julia> # make changes to `src/Nonlinear`
100+
101+
julia> include("test/Nonlinear/runtests.jl")
102+
```
103+
You can also run other tests such as `test/Bridges/Constraint/runtests.jl`, or
104+
any individual file, such as `test/Utilities/distance_to_set.jl`.
105+
106+
There is one complication: `JSONSchema` is a test-time dependency that is not
107+
present in the default project. If you want to run `test/FileFormats/MOF/MOF.jl`,
108+
you will first need to install the package (`Pkg.test("MathOptInterface")` does
109+
this automatically):
110+
```julia
111+
julia> import Pkg; Pkg.add("JSONSchema")
112+
```
113+
If you have installed JSONSchema, you can also run all the tests with
114+
`include("test/runtests.jl")`.
115+
116+
Finally, running the tests locally is best practice, but it is not required.
117+
When you open a pull request, our automated CI will run all of the tests and
118+
highlight any failing tests that need to be fixed.
119+
120+
A comment from `@odow`: when I'm working on a feature, I make local changes,
121+
run the most relevant test file with `include`, and then open a PR. If the
122+
change caused a test to fail in some other part of the codebase, I then
123+
`include` the file with the failing test locally to debug my follow-up changes.
124+
125+
## Building the documentation
126+
127+
Building the documentation follows a similar practice with Revise. First, `cd`
128+
to the source code of MathOptInterface, but this time, start Julia with
129+
`--project=docs`.
130+
```
131+
$ cd ~/.julia/dev/MathOptInterface
132+
133+
$ julia --project=docs
134+
```
135+
136+
Then, ensure that MathOptInterface (in our current directory) has been added as
137+
a development dependency:
138+
```julia
139+
julia> import Pkg; Pkg.dev(".")
140+
[...lines omitted...]
141+
```
142+
Finally, load `Revise` and then build the docs:
143+
```julia
144+
julia> using Revise
145+
146+
julia> include("docs/make.jl")
147+
```
148+
If you make changes to the docs or to the Julia source code (for example, the
149+
docstrings), you can re-run `include` to quickly rebuild the docs.

0 commit comments

Comments
 (0)