|
| 1 | +How can I contribute to TextAttack? |
| 2 | +============================================ |
| 3 | + |
| 4 | +*This documentation page is adapted from [TextAttack Github CONTRIBUTING.md](https://github.com/QData/TextAttack/blob/master/CONTRIBUTING.md). for detailed information on contributing* |
| 5 | + |
| 6 | + |
| 7 | +We welcome contributions from all members of the community– and there are lots |
| 8 | +of ways to help without editing the code! Answering questions, helping others, |
| 9 | +reaching out and improving the documentations are immensely valuable to the |
| 10 | +community. |
| 11 | + |
| 12 | +It also helps us if you spread the word: reference the library from blog posts |
| 13 | +on the awesome projects it made possible, shout out on Twitter every time it has |
| 14 | +helped you, or simply star the repo to say "thank you". |
| 15 | + |
| 16 | +## Slack Channel |
| 17 | + |
| 18 | +For help and realtime updates related to TextAttack, please [join the TextAttack Slack](https://join.slack.com/t/textattack/shared_invite/zt-ez3ts03b-Nr55tDiqgAvCkRbbz8zz9g)! |
| 19 | + |
| 20 | +## Ways to contribute |
| 21 | + |
| 22 | +There are lots of ways you can contribute to TextAttack: |
| 23 | +* Submitting issues on Github to report bugs or make feature requests |
| 24 | +* Fixing outstanding issues with the existing code |
| 25 | +* Implementing new features |
| 26 | +* Adding support for new models and datasets |
| 27 | +* Contributing to the examples or to the documentation |
| 28 | + |
| 29 | +*All are equally valuable to the community.* |
| 30 | + |
| 31 | +## Submitting a new issue or feature request |
| 32 | + |
| 33 | +Do your best to follow these guidelines when submitting an issue or a feature |
| 34 | +request. It will make it easier for us to come back to you quickly and with good |
| 35 | +feedback. |
| 36 | + |
| 37 | +### Found a bug? |
| 38 | + |
| 39 | +TextAttack can remain robust and reliable thanks to users who notify us of |
| 40 | +the problems they encounter. So thank you for [reporting an issue](https://github.com/QData/TextAttack/issues). |
| 41 | + |
| 42 | +We also have a suite of tests intended to detect bugs before they enter the |
| 43 | +codebase. That said, they still happen (Turing completeness and all) so it's up |
| 44 | +to you to report the bugs you find! We would really appreciate it if you could |
| 45 | +make sure the bug was not already reported (use the search bar on Github under |
| 46 | +Issues). |
| 47 | + |
| 48 | +To help us fix your issue quickly, please follow these steps: |
| 49 | + |
| 50 | +* Include your **OS type and version**, the versions of **Python**, **PyTorch** and |
| 51 | + **Tensorflow** when applicable; |
| 52 | +* A short, self-contained, code snippet that allows us to reproduce the bug in |
| 53 | + less than 30s; |
| 54 | +* Provide the *full* traceback if an exception is raised. |
| 55 | + |
| 56 | +### Do you want to add your model? |
| 57 | + |
| 58 | +Awesome! Please provide the following information: |
| 59 | + |
| 60 | +* Short description of the model and link to the paper; |
| 61 | +* Link to the implementation if it is open-source; |
| 62 | +* Link to the model weights if they are available. |
| 63 | + |
| 64 | +If you are willing to contribute the model yourself, let us know so we can best |
| 65 | +guide you. We can host your model on our S3 server, but if you trained your |
| 66 | +model using `transformers`, it's better if you host your model on their |
| 67 | +[model hub](https://huggingface.co/models). |
| 68 | + |
| 69 | +### Do you want a new feature: a component, a recipe, or something else? |
| 70 | + |
| 71 | +A world-class feature request addresses the following points: |
| 72 | + |
| 73 | +1. Motivation first: |
| 74 | + * Is it related to a problem/frustration with the library? If so, please explain |
| 75 | + why. Providing a code snippet that demonstrates the problem is best. |
| 76 | + * Is it related to something you would need for a project? We'd love to hear |
| 77 | + about it! |
| 78 | + * Is it something you worked on and think could benefit the community? |
| 79 | + Awesome! Tell us what problem it solved for you. |
| 80 | +2. Write a *full paragraph* describing the feature; |
| 81 | +3. Provide a **code snippet** that demonstrates its future use; |
| 82 | +4. In case this is related to a paper, please attach a link; |
| 83 | +5. Attach any additional information (drawings, screenshots, etc.) you think may help. |
| 84 | + |
| 85 | + |
| 86 | +## Start contributing! (Pull Requests) |
| 87 | + |
| 88 | +Before writing code, we strongly advise you to search through the exising PRs or |
| 89 | +issues to make sure that nobody is already working on the same thing. If you are |
| 90 | +unsure, it is always a good idea to open an issue to get some feedback. |
| 91 | + |
| 92 | +You will need basic `git` proficiency to be able to contribute to |
| 93 | +`textattack`. `git` is not the easiest tool to use but it has the greatest |
| 94 | +manual. Type `git --help` in a shell and enjoy. If you prefer books, [Pro |
| 95 | +Git](https://git-scm.com/book/en/v2) is a very good reference. |
| 96 | + |
| 97 | +Follow these steps to start contributing: |
| 98 | + |
| 99 | +1. Fork the [repository](https://github.com/QData/TextAttack) by |
| 100 | + clicking on the 'Fork' button on the repository's page. This creates a copy of the code |
| 101 | + under your GitHub user account. |
| 102 | + |
| 103 | +2. Clone your fork to your local disk, and add the base repository as a remote: |
| 104 | + |
| 105 | + ```bash |
| 106 | + $ git clone git@github.com:<your Github handle>/TextAttack.git |
| 107 | + $ cd TextAttack |
| 108 | + $ git remote add upstream https://github.com/QData/TextAttack |
| 109 | + ``` |
| 110 | + |
| 111 | +3. Create a new branch to hold your development changes: |
| 112 | + |
| 113 | + ```bash |
| 114 | + $ git checkout -b a-descriptive-name-for-my-changes |
| 115 | + ``` |
| 116 | + |
| 117 | + **do not** work on the `master` branch. |
| 118 | + |
| 119 | +4. Set up a development environment by running the following commands in a virtual environment: |
| 120 | + |
| 121 | + |
| 122 | + ```bash |
| 123 | + $ cd TextAttack |
| 124 | + $ pip install -e . ".[dev]" |
| 125 | + $ pip install black isort pytest pytest-xdist |
| 126 | + ``` |
| 127 | + |
| 128 | + This will install `textattack` in editable mode and install `black` and |
| 129 | + `isort`, packages we use for code formatting. |
| 130 | + |
| 131 | + (If TextAttack was already installed in the virtual environment, remove |
| 132 | + it with `pip uninstall textattack` before reinstalling it in editable |
| 133 | + mode with the `-e` flag.) |
| 134 | + |
| 135 | +5. Develop the features on your branch. |
| 136 | + |
| 137 | + As you work on the features, you should make sure that the test suite |
| 138 | + passes: |
| 139 | + |
| 140 | + ```bash |
| 141 | + $ make test |
| 142 | + ``` |
| 143 | + |
| 144 | + (or just simply `pytest`.) |
| 145 | + |
| 146 | + > **Tip:** if you're fixing just one or two tests, you can run only the last tests that failed using `pytest --lf`. |
| 147 | +
|
| 148 | + `textattack` relies on `black` and `isort` to format its source code |
| 149 | + consistently. After you make changes, format them with: |
| 150 | + |
| 151 | + ```bash |
| 152 | + $ make format |
| 153 | + ``` |
| 154 | + |
| 155 | + You can run quality checks to make sure your code is formatted properly |
| 156 | + using this command: |
| 157 | + |
| 158 | + ```bash |
| 159 | + $ make lint |
| 160 | + ``` |
| 161 | + |
| 162 | + Once you're happy with your changes, add changed files using `git add` and |
| 163 | + make a commit with `git commit` to record your changes locally: |
| 164 | + |
| 165 | + ```bash |
| 166 | + $ git add modified_file.py |
| 167 | + $ git commit |
| 168 | + ``` |
| 169 | + |
| 170 | + Please write [good commit messages](https://chris.beams.io/posts/git-commit/). |
| 171 | + |
| 172 | + It is a good idea to sync your copy of the code with the original |
| 173 | + repository regularly. This way you can quickly account for changes: |
| 174 | + |
| 175 | + ```bash |
| 176 | + $ git fetch upstream |
| 177 | + $ git rebase upstream/master |
| 178 | + ``` |
| 179 | + |
| 180 | + Push the changes to your account using: |
| 181 | + |
| 182 | + ```bash |
| 183 | + $ git push -u origin a-descriptive-name-for-my-changes |
| 184 | + ``` |
| 185 | + |
| 186 | +6. Add documentation. |
| 187 | + |
| 188 | + Our docs are in the `docs/` folder. Thanks to `sphinx-automodule`, adding |
| 189 | + documentation for a new code file should just be two lines. Our docs will |
| 190 | + automatically generate from the comments you added to your code. If you're |
| 191 | + adding an attack recipe, add a reference in `attack_recipes.rst`. |
| 192 | + If you're adding a transformation, add a reference in `transformation.rst`, etc. |
| 193 | + |
| 194 | + You can build the docs and view the updates using `make docs`. If you're |
| 195 | + adding a tutorial or something where you want to update the docs multiple |
| 196 | + times, you can run `make docs-auto`. This will run a server using |
| 197 | + `sphinx-autobuild` that should automatically reload whenever you change |
| 198 | + a file. |
| 199 | + |
| 200 | +7. Once you are satisfied (**and the checklist below is happy too**), go to the |
| 201 | + webpage of your fork on GitHub. Click on 'Pull request' to send your changes |
| 202 | + to the project maintainers for review. |
| 203 | + |
| 204 | +8. It's ok if maintainers ask you for changes. It happens to core contributors |
| 205 | + too! So everyone can see the changes in the Pull request, work in your local |
| 206 | + branch and push the changes to your fork. They will automatically appear in |
| 207 | + the pull request. |
| 208 | + |
| 209 | + |
| 210 | +### Checklist |
| 211 | + |
| 212 | +1. The title of your pull request should be a summary of its contribution. |
| 213 | +2. If your pull request adresses an issue, please mention the issue number in |
| 214 | + the pull request description to make sure they are linked (and people |
| 215 | + consulting the issue know you are working on it); |
| 216 | +3. To indicate a work in progress please mark it as a draft on Github. |
| 217 | +4. Make sure existing tests pass. |
| 218 | +5. Add relevant tests. No quality testing = no merge. |
| 219 | +6. All public methods must have informative docstrings that work nicely with sphinx. |
| 220 | + |
| 221 | +### Tests |
| 222 | + |
| 223 | +You can run TextAttack tests with `pytest`. Just type `make test`. |
| 224 | + |
| 225 | + |
| 226 | +#### This guide was heavily inspired by the awesome [transformers guide to contributing](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) |
0 commit comments