|Denna sida är för närvarande ett utkast. This page is a draft based on phab:T154471, and is still subject to change.
Ändringar kan ske utan förvarning och innehållet reflekterar ej nödvändigtvis framtida beslut eller ståndpunkter. När innehållet har spikats bör denna mallen tas bort.
|Denna sida i ett nötskal: The purpose of this page is to establish a few basic guidelines around the development work done by Wikimedia Sverige employees in their official capacity.
It is acknowledged that there will be multiple situations when the guidelines are not appropriate, and common sense should always take precedence.
Denna sida är på engelska av transparensskäl samt då den använda terminologin oftast är på engelska. Undersidor kan ibland vara på svenska.
The default language for new projects should, whenever appropriate, be Python 3. When compatible the MIT license should be used.
What to include
Log files should not be included in the repositories. When relevant, these may instead be uploaded as attachments to Phabricator tasks.
Input data may be included in the repository depending on scope. E.g. a .json file containing a mapping of parish names to Wikidata may be appropriate whereas all of the metadata for a batch upload may not be. If needed, such files can instead be stored on Nextcloud.
Processed data which can be recreated by re-running the code should never be part of a repository. Output that is expensive to recreate, doesn't take too much space and may be useful in the future can be stored on Nextcloud.
Documentation ensures the code is understandable by other members of the team, an external audience, as well as by the coder themselves a year later.
All new public functions and classes are expected to be documented. It is recommended to also document function parameters. A style for parameter documentation has not yet been selected. Python documentation is expected to follow
Code-style and linting
Linting ensures code consistency and reduces the need for nitpicking during code-review. Basic linting is expected to have been done by the person responsible for a PR. Even better is to have linting be part of the CI process. For python, the code style is expected to follow PEP8. Helpful tools are
Gerrit, Github and Phabricator
For MediaWiki development gerrit should always be used. For other projects, Github may often be more appropriate. For one-use-only repositories (such as code for a specific batch upload) Github is recommended. Repositories in Github can either be under the user account or the Wikimedia-Sverige account.
In order to comply with our Phabricator guidelines, issue tracking for any new repositories must be done in Phabricator. To connect the two, Github commit messages should include a link to the Phabricator task, and the commit/Pull request should be linked to from the task. If the patch is up for review the #patch-for-review tag should also be added to the task. To make the issue handling system discoverable, a link to the relevant Phabricator board/project should be added to the README file. It may also be advisable to disable issues in that repository (Settings → Options → Features).
For existing repositories already containing Github issues: new issues should instead be filed as Phabricator tasks. Existing issues should get an equivalent Phabricator task when work commences on them (or if they are included in planning). When created, it should be clear from the task, which the old issue was and from the issue, which task that is now dealing with it.
For repositories which are temporary forks of another Github repository or where there is extensive collaboration outside of Wikimedia, issue tracking may continue in Github.
Code-review and task branching
The implementation of code-review varies between our different projects, but the following are general recommendations.
To make code-review possible, and to keep the commit history cleaner, tasks should be developed in separate branches. These are then merged into the master branch via a gerrit review or a Github pull request (both hereafter PR). The scope of a branch often corresponds to a single Phabricator task (e.g. new functionality, changed functionality, a bug). When merged into master, it is most often appropriate to squash each PR into a single commit.
Whenever possible, PRs should be independent of each other. This way they can be developed in parallel and the review/merge of one is less likely to impact the other.
Code-review happens either on the PR level or, in special cases, before deployment. Unless otherwise decided the review is done by the project manager/senior developer.
Making code-review happen
Due to limited resources, having every PR reviewed is not always realistic. The following should be taken in consideration when determining whether code-review is necessary:
- The size of the project. The time and effort put into code-review should be proportional to those put into the whole project.
- The scope of the project. Projects with a more general scope, built with re-usability in mind, should be prioritized for code-review, even if they are currently being maintained/used by one developer/specific application.
- The people involved. Projects actively maintained by several developers should be prioritized for code-review.
Testing makes it easier to update existing code, to deal with edge cases and to deploy with confidence. It can also help when writing the product code, as it makes you think more about what it does and how.
Unit testing should be implemented in new code. It is not necessary to introduce in older code that's assumed to be working. While not necessary, it may be a good idea to use test driven development.
Integration testing is not required at this point. This can partially be mitigated using documentation in e.g. Phabricator describing the expected output/behaviour given some real-life input examples.
Tests should ideally be run as part of the CI process.