You should only need to do this step once
First fork the slsim repository. A fork is your own remote copy of the repository on GitHub. To create a fork:
- Go to the LSST-strong-lensing GitHub Repository
- Click the Fork button (in the top-right-hand corner)
- Choose where to create the fork, typically your personal GitHub account
Next clone your fork. Cloning creates a local copy of the repository on your computer to work with. To clone your fork:
git clone https://github.com/<your-account>/slsim.git
Finally add the slsim-project
repository as a remote. This will allow you to fetch changes made to the codebase. To add the slsim-project
remote:
cd slsim git remote add slsim-project https://github.com/LSST-strong-lensing/slsim.git
To run your own version of slsim and making sure that your own development changes are reflected (as well as switching branches), install the slsim package in development mode with
cd slsim pip install -r requirements.txt --user python setup.py develop --user
Note
Development mode installation uses the file path to the repository you work on. If you do the regular installation, a copy of all the python files will be made in the path of the python version and the path to call the routines will be to these files.
Warning
Make sure you uninstalled all SLSim versions first before installing the version in development mode. Otherwise, due to path hierarchy, there is still a good chance your copied files will be imported instead of the files in your development repository.
Create a branch off the slsim-project
main branch. Working on unique branches for each new feature simplifies the development, review and merge processes by maintining logical separation. To create a feature branch:
git fetch slsim-project git checkout -b <your-branch-name> slsim-project/main
Write the new code you would like to contribute and commit it to the feature branch on your local repository. Ideally commit small units of work often with clear and descriptive commit messages describing the changes you made. To commit changes to a file:
git add file_containing_your_contribution git commit -m 'Your clear and descriptive commit message'
Push the contributions in your feature branch to your remote fork on GitHub:
git push origin <your-branch-name>
Note: The first time you push a feature branch you will probably need to use --set-upstream origin to link to your remote fork:
git push --set-upstream origin <your-branch-name>
When you feel that work on your new feature is complete, you should create a Pull Request. This will propose your work to be merged into the main slsim repository.
- Go to slsim Pull Requests
- Click the green New pull request button
- Click compare across forks
- Confirm that the base fork is
LSST-strong-lensing/slsim
and the base branch ismain
- Confirm the head fork is
<your-account>/slsim
and the compare branch is<your-branch-name>
- Give your pull request a title and fill out the the template for the description
- Click the green Create pull request button
A series of automated checks will be run on your pull request, some of which will be required to pass before it can be merged into the main codebase:
Tests
(Required) runs the unit tests in four predefined environments; latest supported versions, oldest supported versions, macOS latest supported and Windows latest supported. Click "Details" to view the output including any failures.Code Style
(Required) runs flake8 to check that your code conforms to the PEP 8 style guidelines. Click "Details" to view any errors.codecov
reports the test coverage for your pull request; you should aim for codecov/patch — 100.00%. Click "Details" to view coverage data.docs
(Required) builds the docstrings on readthedocs. Click "Details" to view the documentation or the failed build log.
As you work on your feature, new commits might be made to the slsim-project
main branch. You will need to update your branch with these new commits before your pull request can be accepted. You can achieve this in a few different ways:
If your pull request has no conflicts, click Update branch
If your pull request has conflicts, click Resolve conflicts, manually resolve the conflicts and click Mark as resolved
merge the
slsim-project
main branch from the command line:git fetch slsim-project git merge slsim-project/mainrebase your feature branch onto the
slsim-project
main branch from the command line:git fetch slsim-project git rebase slsim-project/main
Warning: It is bad practice to rebase commits that have already been pushed to a remote such as your fork. Rebasing creates new copies of your commits that can cause the local and remote branches to diverge. git push --force
will overwrite the remote branch with your newly rebased local branch. This is strongly discouraged, particularly when working on a shared branch where you could erase a collaborators commits.
- For more information about resolving conflicts see the GitHub guides:
More information regarding the usage of GitHub can be found in the GitHub Guides.
Before your pull request can be merged into the codebase, it will be reviewed by one of the slsim developers and required to pass a number of automated checks. Below are a minimum set of guidelines for developers to follow:
- slsim is compatible with Python>=3.7 (see setup.cfg). slsim does not support backwards compatibility with Python 2.x; six, __future__ and 2to3 should not be used.
- All contributions should follow the PEP8 Style Guide for Python Code. We recommend using flake8 to check your code for PEP8 compliance.
- Importing slsim should only depend on having NumPy, SciPy and Astropy installed.
- Code will be grouped into submodules based on broad science areas.
- For more information see the Astropy Coding Guidelines.
Pull requests will require existing unit tests to pass before they can be merged. Additionally, new unit tests should be written for all new public methods and functions. Unit tests for each submodule are contained in subdirectories called tests
and you can run them locally using pytest
. For more information see the Astropy Testing Guidelines.
If your unit tests check the statistical distribution of a random sample, the test outcome itself is a random variable, and the test will fail from time to time. Please mark such tests with the @pytest.mark.flaky
decorator, so that they will be automatically tried again on failure. To prevent non-random test failures from being run multiple times, please isolate random statistical tests and deterministic tests in their own test cases.
All public classes, methods and functions require docstrings. You can build documentation locally by installing sphinx-astropy and calling make html
in the docs
subdirectory. Docstrings should include the following sections:
- Description
- Parameters
- Notes
- References
For more information see the Astropy guide to Writing Documentation.