[V3] Red's Development Workflow #1636

Closed
opened 2018-05-13 09:50:27 +02:00 by Tobotimus · 6 comments
Tobotimus commented 2018-05-13 09:50:27 +02:00 (Migrated from github.com)

Ahem.
There's been a lot of discussion from us devs lately about Red's development workflow and how we can improve it. This issue aims to give a summary of that discussion.

Introduction

Developing for Red in its current state can involve jumping through a lot of hoops and addressing many caveats in order to produce quality code and contributions. Part of this has to do with how we run tests, and another part is how we set up our development environment.

Development Workflow Outline

Let's picture a developer first starting out contributing to Red. They needs to go through a couple of basic steps, as is the case with many python projects:

  1. Fork and clone the repository
  2. Install dependencies to a local virtual environment
  3. Have some way of running his local development version of Red in said environment
  4. Test their changes to verify they haven't broken everything
  5. Open a pull request, subject to approval of the following conditions:
    5.1. The developers agree with your design and implementation
    5.2. A code review from the developers passes
    5.3. The Travis build succeeds

So what's the matter with this?

Step (1) is all good.

Step (2) could be improved currently. One example for how we might do it right now are as follows:

pip install git+https://github.com/Rapptz/discord.py#egg=discord.py[voice]
pip install -e .[docs,test,voice,mongo]

This didn't actually work with Red-Trivia<1.1, but luckily that will be history very soon thanks to #1635. In addition, upgrading dependencies involves repeating the same commands again with upgrade flags. I don't like big links.

Step (3) is pretty easy, simply run the bot like you normally would.

Step (4) involves installing pytest and running, but it's not just the usage of this which is lacking right now, but the actual coverage and extensiveness of our testing. For changes to docs, they also need to be built, which we don't really have a guide for. Moreover, style isn't enforced in any way.

Step (5) is all good, except that we should really be testing the stuff I described in step (4) on Travis too. This would help the devs a lot with code reviews.

Lastly, I'd like to note that although this is how I would recommend setting up a good environment to develop and test Red, this isn't the way Travis does it. Personally, I think that local testing and Travis should be standardised and unified.

Making adjustments

Installation

Virtual environment tools can be handled by the developer in my opinion. End users will need hand holding when it comes to virtual environments, but it's not too hard for a developer to learn. Tools like pipenv, pyenv, virtualenv all work fine.

We can do less commands for installation by creating a 2nd pip requirements file, I'll call it dev_install.txt, so all we have to do to achieve step (2) is the following:

pip install -r dev_install.txt

Pretty easy right? I think so too. Not only this, but it could be used exactly the same way to simplify the travis install script. This way, we would only need to modify this one file and it would update the development environment on both travis and local installations.

Update: We will be using pipenv as an alternative to this approach. This manages the virtualenv and dependencies for development installation of the project. See #1638 and #1642 for reference.

Testing changes

Currently pytest works, but our code coverage is a pretty sad unfortunately. Moreover, it does nothing but unit testing; what if we want to enforce a style guide? What about building the documentation, how does the developer know how to test all of these things?

We could give them a guide for each of the individual tools used to test these things (pytest, sphinx, flake8, etc.) but I think that's too much writing and too much reading. Moreover, for any new testing methods we add, the developers would have to learn them. Luckily, there's a tool which is made specifically to help with this...

tox is a great tool for integrating all of these tests together, and also running them on different versions of python in isolated virtual environments. The idea is that we configure tox to run particular tests, all the developer has to do is run the command tox in the project directory. The output can be configured to show the developer useful information about where the tests failed.

Once again, Travis can be configured to use this same tool as we would be using locally, with similar benifits.

Installation of tox itself can be done as part of the pip install -r dev_install.txt described above.

The Tools

So, I've talked about tox, which is the important part for your average developer. However we still need to discuss what we're actually testing with tox, since our pytest coverage at the moment is not enough.

From the discussion and from my own testing and research, I've come up with a draft list:

  • Black and/or flake8 for linting and stylechecking
  • sphinx-build (OOTB with sphinx) for building docs and link checking
  • mypy for static type checking

Separate issues can be created for discussing the exact configuration of the tools.

Also, we officially support all python versions from 3.5.1 to 3.6 latest. I think testing with the extremities of this range is sufficient (i.e. 3.5.1 and 3.6 latest).

Ahem. There's been a lot of discussion from us devs lately about Red's development workflow and how we can improve it. This issue aims to give a summary of that discussion. # Introduction Developing for Red in its current state can involve jumping through a lot of hoops and addressing many caveats in order to produce quality code and contributions. Part of this has to do with how we run tests, and another part is how we set up our development environment. # Development Workflow Outline Let's picture a developer first starting out contributing to Red. They needs to go through a couple of basic steps, as is the case with many python projects: 1. Fork and clone the repository 2. Install dependencies to a local virtual environment 3. Have some way of running his local development version of Red in said environment 4. Test their changes to verify they haven't broken everything 5. Open a pull request, subject to approval of the following conditions: 5.1. The developers agree with your design and implementation 5.2. A code review from the developers passes 5.3. The Travis build succeeds ### So what's the matter with this? Step (1) is all good. Step (2) could be improved currently. One example for how we might do it right now are as follows: pip install git+https://github.com/Rapptz/discord.py#egg=discord.py[voice] pip install -e .[docs,test,voice,mongo] This didn't actually work with Red-Trivia<1.1, but luckily that will be history very soon thanks to #1635. In addition, upgrading dependencies involves repeating the same commands again with upgrade flags. I don't like big links. Step (3) is pretty easy, simply run the bot like you normally would. Step (4) involves installing pytest and running, but it's not just the usage of this which is lacking right now, but the actual coverage and extensiveness of our testing. For changes to docs, they also need to be built, which we don't really have a guide for. Moreover, style isn't enforced in any way. Step (5) is all good, except that we should really be testing the stuff I described in step (4) on Travis too. This would help the devs a lot with code reviews. Lastly, I'd like to note that although this is how I would recommend setting up a good environment to develop and test Red, this isn't the way Travis does it. Personally, I think that local testing and Travis should be standardised and unified. # Making adjustments #### Installation ~~Virtual environment tools can be handled by the developer in my opinion. End users will need hand holding when it comes to virtual environments, but it's not too hard for a developer to learn. Tools like pipenv, pyenv, virtualenv all work fine.~~ ~~We can do less commands for installation by creating a 2nd pip requirements file, I'll call it `dev_install.txt`, so all we have to do to achieve step (2) is the following:~~ pip install -r dev_install.txt ~~Pretty easy right? I think so too. Not only this, but it could be used exactly the same way to simplify the travis install script. This way, we would only need to modify this one file and it would update the development environment on both travis *and* local installations.~~ *Update:* We will be using [pipenv](https://github.com/pypa/pipenv) as an alternative to this approach. This manages the virtualenv *and* dependencies for development installation of the project. See #1638 and #1642 for reference. #### Testing changes Currently pytest works, but our code coverage is a pretty sad unfortunately. Moreover, it does nothing but unit testing; what if we want to enforce a style guide? What about building the documentation, how does the developer know how to test all of these things? We could give them a guide for each of the individual tools used to test these things (pytest, sphinx, flake8, etc.) but I think that's too much writing and too much reading. Moreover, for any *new* testing methods we add, the developers would have to learn them. Luckily, there's a tool which is made specifically to help with this... **[tox](https://github.com/tox-dev/tox)** is a great tool for integrating all of these tests together, and also running them on different versions of python in isolated virtual environments. The idea is that we configure tox to run particular tests, all the developer has to do is run the command `tox` in the project directory. The output can be configured to show the developer useful information about where the tests failed. Once again, Travis can be configured to use this same tool as we would be using locally, with similar benifits. Installation of tox itself can be done as part of the `pip install -r dev_install.txt` described above. ## The Tools So, I've talked about tox, which is the important part for your average developer. However we still need to discuss what we're actually testing with tox, since our pytest coverage at the moment is not enough. From the discussion and from my own testing and research, I've come up with a draft list: - [Black](https://github.com/ambv/black) and/or [flake8](https://github.com/PyCQA/flake8) for linting and stylechecking - sphinx-build (OOTB with sphinx) for building docs and link checking - [mypy](https://github.com/python/mypy) for static type checking Separate issues can be created for discussing the exact configuration of the tools. Also, we officially support all python versions from 3.5.1 to 3.6 latest. I think testing with the extremities of this range is sufficient (i.e. 3.5.1 and 3.6 latest).
Tobotimus commented 2018-05-13 13:12:48 +02:00 (Migrated from github.com)

I've just added mypy for static type checking to the draft list of tools we'll run with tox. This one might take a bit longer to set up, since much of the existing code needs type hints added or fixed.

That being said though, linting could take longer since there exist hundreds of violations in this project for the style guide we will likely propose.

I've just added mypy for static type checking to the draft list of tools we'll run with tox. This one might take a bit longer to set up, since much of the existing code needs type hints added or fixed. That being said though, linting could take longer since there exist hundreds of violations in this project for the style guide we will likely propose.
Tobotimus commented 2018-05-13 16:24:20 +02:00 (Migrated from github.com)

Also, we officially support all python versions from 3.5.1 to 3.6 latest. I think testing with the extremities of this range is sufficient (i.e. 3.5.1 and 3.6 latest).

Turns out that all this time, a dependency of aiohttp breaks on 3.5.1. In my opinion it is fairly unnecessary to support 3.5.1 since all major operating systems and linux distributions have 3.5.2+ available, and even if not, pyenv can be used as a workaround on linux.

> Also, we officially support all python versions from 3.5.1 to 3.6 latest. I think testing with the extremities of this range is sufficient (i.e. 3.5.1 and 3.6 latest). Turns out that all this time, a dependency of aiohttp breaks on 3.5.1. In my opinion it is fairly unnecessary to support 3.5.1 since all major operating systems and linux distributions have 3.5.2+ available, and even if not, pyenv can be used as a workaround on linux.
Tobotimus commented 2018-05-14 04:13:12 +02:00 (Migrated from github.com)

@tekulvw Has brought forward using the pipenv tool as an alternative to the aforementioned dev_install.txt. See #1638 for reference, and #1642 for the alternative implementation.

@tekulvw Has brought forward using the [pipenv](https://github.com/pypa/pipenv) tool as an alternative to the aforementioned `dev_install.txt`. See #1638 for reference, and #1642 for the alternative implementation.
Tobotimus commented 2018-05-19 07:15:56 +02:00 (Migrated from github.com)

I'm satisfied with the state of this for now. Moving to final review to give a chance for anyone else who might have other ideas or qualms with the new setup.

I'm satisfied with the state of this for now. Moving to final review to give a chance for anyone else who might have other ideas or qualms with the new setup.
pgaetani commented 2018-05-21 09:26:28 +02:00 (Migrated from github.com)

Could some official docs on how to setup this environment be written up? I could probably ask you for the detailed steps you took and write them myself, if you need?

Could some official docs on how to setup this environment be written up? I could probably ask you for the detailed steps you took and write them myself, if you need?
Tobotimus commented 2018-05-21 12:41:55 +02:00 (Migrated from github.com)

@UltimatePancake I'm glad you asked. The documentation you're after is pending a merge over on #1659 😃

@UltimatePancake I'm glad you asked. The documentation you're after is pending a merge over on #1659 :smiley:
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#1636
No description provided.