-
Notifications
You must be signed in to change notification settings - Fork 3
Contributing
If you're a member of the Minecraft Commands organization, you can clone repos and manage branches directly without having to manage your own fork. This is generally considered to be the more straightforward approach to contributing.
-
Clone: Choose the
commanderbot-pyrepo and clone it withgit clonedirectly, without forking it. -
Branch:
-
The default/base branch
mainis protected and, unless you're a maintainer, you will not be able to push to it. Instead, you should create and commit to a separate branch for each new extension, bug fix, or any other self-contained set of changes. This simplifies the process of alternating between different tasks and keeps your work separate from everyone else. -
Think of a good, succinct branch name. We'll use
my-branch-nameas an example here. You can create and checkout a new branch at the same time withgit checkout -b my-branch-name.
-
-
Make changes:
-
During development you should try to separate your commits with meaningful commit messages. If you can't summarize your commit in 50-70 characters, you might want to try splitting it up into smaller, incremental pieces. This encourages a meaningful commit history, helps your future self remember what you did, and reduces the impact of merge conflicts.
-
You should update the changelog to reflect any user, API, or otherwise significant changes in your branch. This will be required as part of your pull request, but it is recommended to do this regularly for your own reference. All projects using a changelog adhere to the Keep a Changelog format. You can refer to the existing changelogs to familiarize yourself with the format.
-
-
Merge: At some point you may need to merge
maininto your branch by runninggit merge mainin your own branch. If someone else has committed changes to files that you have also changed in your branch, it is possible you will need to resolve merge conflicts. Themainbranch is generally updated with each release and high-traffic files like changelogs often conflict. -
Push: Push your changes with
git push. If this is the first time you're pushing changes to this branch, git should prompt you to explicitly create the remote branch withgit push -u origin my-branch-name. -
Pull request: When you're ready to contribute your changes, you can submit a pull request against the
mainbranch to be included in the next release.
If you're not a member of the Minecraft Commands organization, or you prefer to manage your own repository, you can use a fork to contribute. You will want to configure an upstream remote so that you can sync your fork with the upstream repository. The rest of the process is largely unchanged.
All projects use:
- Python 3.10+
- discord.py 2.0+
- Poetry for package management
- Semantic Versioning for project versioning
- Keep a Changelog for changelog formatting
- Knowledge of the typing module, async programming, and the Discord API are recommended
Install Poetry and familiarize yourself with the commands. Poetry makes it easier to manage dependencies and keep them synchronized with everyone else.
Fork and clone the commanderbot-py repo:
git clone git@github.com:MinecraftCommands/commanderbot-py.gitYou can use Poetry to create and manage a virtual environment (venv) for you, or you can do so manually.
If you wish to do so manually, the recommended approach is to create a Python virtual environment in the root of the repo:
python -m venv venv/commanderbot-pyYou can use any path for the venv, but it is recommended to use venv/commanderbot-py because:
- everything under
venvis already git-ignored; and - the sub-folder
commanderbot-pylabels the venv to help distinguish it from others.
Activate the venv you just created (such as by opening a new integrated terminal) and install dependencies:
poetry installOnce the packages are installed, you can verify the results:
poetry showCreate .vscode/settings.json and set python.pythonPath to the venv you just created. The path differs based on the name you chose, and whether you're on Windows or Linux. Here's what it might look like on Linux for the commanderbot-py repo:
{
"python.pythonPath": "venv/commanderbot-py/bin/python"
}It is important to configure certain project-level settings such as which code formatter to use. All Python projects use the black formatter. You can do this either in the folder settings at .vscode/settings.json or your workspace settings, by adding these options:
{
"python.formatting.provider": "black"
}Note that black itself is configured separately in pyproject.toml as part of version control.
Here are some additional recommend settings to help streamline the development process:
{
"editor.rulers": [88],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"files.exclude": {
".pytest_cache/**": true,
"**/__pycache__": true,
"venv/**": true,
"*.egg-info/**": true
}
}Placing these options in your workspace settings will apply them to all folders in the current workspace, which is useful if you have multiple repos present.
You can access your workspace settings by opening the command palette with ctrl + shift + p and searching for Preferences: Open Workspace Settings (JSON). Make sure to place settings under the settings field, separate from folders.
See the CommanderBot readme for how to configure and run an instance of the bot.
Note that the two files bot.json and bot.token as well as the entire data folder are already git-ignored, however you may choose to maintain your bot's state elsewhere.
Create .vscode/launch.json to define launch/debug configuration for the bot. Here's a starting template that sets the working directory to the git-ignored bot folder, and reads configuration from bot.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "CommanderBot",
"type": "python",
"request": "launch",
"module": "commanderbot",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/bot",
"args": ["bot.json", "--log", "INFO"]
}
]
}You will also need to provide a bot token to log-in with. One option is to create a .env file under the same git-ignored bot folder, and use it to set the BOT_TOKEN environment variable:
BOT_TOKEN=put_your_bot_token_here