Note: consider watchingSciPy Development Workflowbefore or after
reading to see an example of fixing a bug and submitting a pull request.
This guide assumes that you have created your own fork (copy) of the SciPy
repository, cloned the repository on your own machine, and built SciPy from this
source code. If you haven’t, check the Building from source pages appropriate to your
system. Before getting started here, there are three other things you need to do
just once before you start modifying SciPy.
In a terminal, introduce yourself to Git:
gitconfig--globaluser.emailyou@yourdomain.comgit
config
--
global
user
.
name
"Your Name"
This information credits you for your work, but note that it will become
publicly available if you “push” your work to GitHub. See
Setting your commit email address in Git for more information.
Navigate to the root directory of your local SciPy repository and enter:
This associates the name upstream with the official SciPy repository
located at scipy/scipy.git.
Note that when you cloned your fork of the SciPy repository, Git already
associated the name origin with your fork. The reason you need both of
these “remotes” is that you will typically start with the latest version
of SciPy from the official repository upstream, make changes, “push”
your changes to your fork of the repository origin, and then submit
a “pull request” asking SciPy to “pull” your changes from your fork into
the official repository.
Initialize git submodules:
gitsubmoduleupdate--init
This fetches and updates any submodules that SciPy needs (such as Boost).
Basic workflow
In short:
Start a new feature branch for each set of edits that you do.
See below.
ensure that the main branch of your local repository is checked out,
apply all the latest changes from the upstream/main (main SciPy
repository main branch) to your local main branch, and
create and check out a new branch (-b) based on your local main
branch.
In any case, it’s important that your feature branch include the latest
changes from the upstream main to help avoid
merge conflicts
when it’s time to submit a pull request.
It’s also a good idea to build this branch and run tests before continuing.
Assuming you’ve followed one of the Building from source pages to set up
your development environment, you’ll need to activate your development
environment and then run tests (note that the spintest command will
perform a build automatically if needed):
condaactivatescipy-devspintest-v
Make some changes. When you feel that you’ve made a complete, working set
of related changes, move on to the next steps.
Optional: Check which files have changed with gitstatus (see git
status). You’ll see a listing like this one:
# On branch my-new-feature# Changed but not updated:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: README## Untracked files:# (use "git add <file>..." to include in what will be committed)## INSTALLnochangesaddedtocommit(use"git add"and/or"git commit -a")
Optional: Compare the changes with the previous version using with gitdiff (git diff). This brings up a simple text browser interface that
highlights the difference between your files and the previous version.
Add any relevant modified or new files using gitaddmodified_file
(see git add). This puts the files into a staging area, which is a queue
of files that will be added to your next commit. Only add files that have
related, complete changes. Leave files with unfinished changes for later
commits.
To commit the staged files into the local copy of your repo, do gitcommit. At this point, a text editor will open up to allow you to write a
commit message. Read the commit message
section to be sure that you are writing a
properly formatted and sufficiently detailed commit message. After saving
your message and closing the editor, your commit will be saved. For trivial
commits, a short commit message can be passed in through the command line
using the -m flag. For example, gitcommit-am"ENH:Somemessage".
In some cases, you will see this form of the commit command: gitcommit-a. The extra -a flag automatically commits all modified files and
removes all deleted files. This can save you some typing of numerous gitadd commands; however, it can add unwanted changes to a commit if you’re
not careful. For more information, see why the -a flag? - and the
helpful use-case description in the .
It may be the case that while you were working on your edits, new commits have
been added to upstream that affect your work. In this case, follow the
Rebasing on main instructions to apply those changes to your branch.
Writing the commit message
Commit messages should be clear and follow a few basic rules.
Example:
MAINT/TST: fft: remove xp backend skips, test `fftfreq` `device`
The first line of the commit message starts with a capitalized acronym
(or multiple, options listed below) indicating what type of commit this is.
Then a blank line, then more text if needed.
References to code names should be enclosed in backticks.
If changes are limited to certain submodules or functions, they should be
included after the acronym(s) - backticks are not needed here.
Example:
BUG:sparse.linalg.gmres: add early exit when `x0` already solves problem
Lines shouldn't be longer than 72 characters. If the commit is related to an issue,
indicate that with "See gh-3456", "Closes gh-3456", or similar,
in the extended description.
However, if you are pushing many commits to a PR, you should avoid including
this in every commit message as it will clutter the linked issue.
Describing the motivation for a change, the nature of a bug for bug fixes or
some details on what an enhancement does are also good to include in a commit
message. Messages should be understandable without looking at the code
changes. A commit message like MAINT:fixedanotherone is an example of
what not to do; the reader has to go look for context elsewhere.
Standard acronyms to start the commit message with are:
Asking for your changes to be merged with the main repo
When you feel your work is finished, you can create a pull request (PR). Github
has a nice help page that outlines the process for filing pull requests.
If your changes involve modifications to the API or addition/modification of a
function, you should initiate a code review. This involves sending an email to
the SciPy forum with a link to your PR along with a description of
and a motivation for your changes.
Checklist before submitting a PR
Did you check that the code can be distributed under a BSD license? See
License Considerations.
Have you checked SciPy’s AI policy? See AI Policy.
Is the docstring of the new functionality tagged with
..versionadded::X.Y.Z (where X.Y.Z is the version number of the
next release? See the updating, workers, and constraints
documentation of differential_evolution, for example.
In case of larger additions, is there a tutorial or more extensive
module-level description? Tutorial files are in doc/source/tutorial.
If new files are added, are they integrated correctly via meson.build?
See Compiled code for more information.