Skip to content

Commit

Permalink
Merge branch 'main' into fix_327
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed May 16, 2021
2 parents b5a7dc4 + 0598774 commit 8c7c3b1
Show file tree
Hide file tree
Showing 418 changed files with 9,378 additions and 6,820 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ source =
pydis_site/apps/api
pydis_site/apps/home
pydis_site/apps/staff
pydis_site/apps/wiki
omit =
*/migrations/*
*/admin.py
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_run:
workflows: ["Lint & Test"]
branches:
- master
- main
types:
- completed

Expand Down Expand Up @@ -38,8 +38,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build the container, including an inline cache manifest to
# allow us to use the registry as a cache source.
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_run:
workflows: ["Build"]
branches:
- master
- main
types:
- completed

Expand All @@ -13,6 +13,7 @@ jobs:
if: github.event.workflow_run.conclusion == 'success'
name: Deploy to Kubernetes Cluster
runs-on: ubuntu-latest
environment: production

steps:
- name: Create SHA Container Tag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Lint & Test
on:
push:
branches:
- master
- main
pull_request:


Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sentry-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Create Sentry release
on:
push:
branches:
- master
- main

jobs:
createSentryRelease:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
uses: actions/checkout@main
- name: Create a Sentry.io release
uses: tclindner/sentry-releases-action@v1.2.0
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ rethinkdb_data/
# Node modules
node_modules/

media/
pip-wheel-metadata/
staticfiles/

Expand Down
1 change: 0 additions & 1 deletion .mdlrc

This file was deleted.

3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

The Python Discord Code of Conduct can be found [on our website](https://pydis.com/coc).
125 changes: 2 additions & 123 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,3 @@
# Contributing to one of Our Projects
# Contributing Guidelines

Our projects are open-source and are automatically deployed whenever commits are pushed to the `master` branch on each repository, so we've created a set of guidelines in order to keep everything clean and in working order.

Note that contributions may be rejected on the basis of a contributor failing to follow these guidelines.

## Rules

1. **No force-pushes** or modifying the Git history in any way.
2. If you have direct access to the repository, **create a branch for your changes** and create a pull request for that branch. If not, create a branch on a fork of the repository and create a pull request from there.
* It's common practice for a repository to reject direct pushes to `master`, so make branching a habit!
* If PRing from your own fork, **ensure that "Allow edits from maintainers" is checked**. This gives permission for maintainers to commit changes directly to your fork, speeding up the review process.
3. **Adhere to the prevailing code style**, which we enforce using [`flake8`](http://flake8.pycqa.org/en/latest/index.html) and [`pre-commit`](https://pre-commit.com/).
* Run `flake8` and `pre-commit` against your code [**before** you push it](https://soundcloud.com/lemonsaurusrex/lint-before-you-push). Your commit will be rejected by the build server if it fails to lint.
* [Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) are a powerful git feature for executing custom scripts when certain important git actions occur. The pre-commit hook is the first hook executed during the commit process and can be used to check the code being committed & abort the commit if issues, such as linting failures, are detected. While git hooks can seem daunting to configure, the `pre-commit` framework abstracts this process away from you and is provided as a dev dependency for this project. Run `pipenv run precommit` when setting up the project and you'll never have to worry about committing code that fails linting.
4. **Make great commits**. A well structured git log is key to a project's maintainability; it efficiently provides insight into when and *why* things were done for future maintainers of the project.
* Commits should be as narrow in scope as possible. Commits that span hundreds of lines across multiple unrelated functions and/or files are very hard for maintainers to follow. After about a week they'll probably be hard for you to follow too.
* Avoid making minor commits for fixing typos or linting errors. Since you've already set up a `pre-commit` hook to run the linting pipeline before a commit, you shouldn't be committing linting issues anyway.
* A more in-depth guide to writing great commit messages can be found in Chris Beam's [*How to Write a Git Commit Message*](https://chris.beams.io/posts/git-commit/)
5. **Avoid frequent pushes to the main repository**. This goes for PRs opened against your fork as well. Our test build pipelines are triggered every time a push to the repository (or PR) is made. Try to batch your commits until you've finished working for that session, or you've reached a point where collaborators need your commits to continue their own work. This also provides you the opportunity to amend commits for minor changes rather than having to commit them on their own because you've already pushed.
* This includes merging master into your branch. Try to leave merging from master for after your PR passes review; a maintainer will bring your PR up to date before merging. Exceptions to this include: resolving merge conflicts, needing something that was pushed to master for your branch, or something was pushed to master that could potentionally affect the functionality of what you're writing.
6. **Don't fight the framework**. Every framework has its flaws, but the frameworks we've picked out have been carefully chosen for their particular merits. If you can avoid it, please resist reimplementing swathes of framework logic - the work has already been done for you!
7. If someone is working on an issue or pull request, **do not open your own pull request for the same task**. Instead, collaborate with the author(s) of the existing pull request. Duplicate PRs opened without communicating with the other author(s) and/or PyDis staff will be closed. Communication is key, and there's no point in two separate implementations of the same thing.
* One option is to fork the other contributor's repository and submit your changes to their branch with your own pull request. We suggest following these guidelines when interacting with their repository as well.
* The author(s) of inactive PRs and claimed issues will be be pinged after a week of inactivity for an update. Continued inactivity may result in the issue being released back to the community and/or PR closure.
8. **Work as a team** and collaborate wherever possible. Keep things friendly and help each other out - these are shared projects and nobody likes to have their feet trodden on.
9. All API changes **must be validated against the bot** before PRing. Please don't leave this for reviewers to discover. Guides for setting up the developer environment can be [found below](#developer-environment).
10. All static content, such as images or audio, **must be licensed for open public use**.
* Static content must be hosted by a service designed to do so. Failing to do so is known as "leeching" and is frowned upon, as it generates extra bandwidth costs to the host without providing benefit. It would be best if appropriately licensed content is added to the repository itself so it can be served by PyDis' infrastructure.

Above all, the needs of our community should come before the wants of an individual. Work together, build solutions to problems and try to do so in a way that people can learn from easily. Abuse of our trust may result in the loss of your Contributor role.

## Changes to this Arrangement

All projects evolve over time, and this contribution guide is no different. This document is open to pull requests or changes by contributors. If you believe you have something valuable to add or change, please don't hesitate to do so in a PR.

## Supplemental Information
### Developer Environment
Instructions for setting up environments for both the site and the bot can be found on the PyDis Wiki:
* [Site](https://pythondiscord.com/pages/contributing/site/)
* [Bot](https://pythondiscord.com/pages/contributing/bot/)

When pulling down changes from GitHub, remember to sync your environment using `pipenv sync --dev` to ensure you're using the most up-to-date versions the project's dependencies.

### Type Hinting
[PEP 484](https://www.python.org/dev/peps/pep-0484/) formally specifies type hints for Python functions, added to the Python Standard Library in version 3.5. Type hints are recognized by most modern code editing tools and provide useful insight into both the input and output types of a function, preventing the user from having to go through the codebase to determine these types.

For example:

```py
import typing as t


def foo(input_1: int, input_2: t.Dict[str, str]) -> bool:
...
```

Tells us that `foo` accepts an `int` and a `dict`, with `str` keys and values, and returns a `bool`.

All function declarations should be type hinted in code contributed to the PyDis organization.

For more information, see *[PEP 483](https://www.python.org/dev/peps/pep-0483/) - The Theory of Type Hints* and Python's documentation for the [`typing`](https://docs.python.org/3/library/typing.html) module.

### AutoDoc Formatting Directives
Many documentation packages provide support for automatic documentation generation from the codebase's docstrings. These tools utilize special formatting directives to enable richer formatting in the generated documentation.

For example:

```py
import typing as t


def foo(bar: int, baz: t.Optional[t.Dict[str, str]] = None) -> bool:
"""
Does some things with some stuff.
:param bar: Some input
:param baz: Optional, some dictionary with string keys and values
:return: Some boolean
"""
...
```

Since PyDis does not utilize automatic documentation generation, use of this syntax should not be used in code contributed to the organization. Should the purpose and type of the input variables not be easily discernable from the variable name and type annotation, a prose explanation can be used. Explicit references to variables, functions, classes, etc. should be wrapped with backticks (`` ` ``).

For example, the above docstring would become:

```py
import typing as t


def foo(bar: int, baz: t.Optional[t.Dict[str, str]] = None) -> bool:
"""
Does some things with some stuff.
This function takes an index, `bar` and checks for its presence in the database `baz`, passed as a dictionary. Returns `False` if `baz` is not passed.
"""
...
```

### Logging Levels
The project currently defines [`logging`](https://docs.python.org/3/library/logging.html) levels as follows, from lowest to highest severity:
* **TRACE:** These events should be used to provide a *verbose* trace of every step of a complex process. This is essentially the `logging` equivalent of sprinkling `print` statements throughout the code.
* **Note:** This is a PyDis-implemented logging level.
* **DEBUG:** These events should add context to what's happening in a development setup to make it easier to follow what's going while working on a project. This is in the same vein as **TRACE** logging but at a much lower level of verbosity.
* **INFO:** These events are normal and don't need direct attention but are worth keeping track of in production, like checking which cogs were loaded during a start-up.
* **WARNING:** These events are out of the ordinary and should be fixed, but have not caused a failure.
* **NOTE:** Events at this logging level and higher should be reserved for events that require the attention of the DevOps team.
* **ERROR:** These events have caused a failure in a specific part of the application and require urgent attention.
* **CRITICAL:** These events have caused the whole application to fail and require immediate intervention.

Ensure that log messages are succinct. Should you want to pass additional useful information that would otherwise make the log message overly verbose the `logging` module accepts an `extra` kwarg, which can be used to pass a dictionary. This is used to populate the `__dict__` of the `LogRecord` created for the logging event with user-defined attributes that can be accessed by a log handler. Additional information and caveats may be found [in Python's `logging` documentation](https://docs.python.org/3/library/logging.html#logging.Logger.debug).

### Work in Progress (WIP) PRs
Github [provides a PR feature](https://github.blog/2019-02-14-introducing-draft-pull-requests/) that allows the PR author to mark it as a WIP. This provides both a visual and functional indicator that the contents of the PR are in a draft state and not yet ready for formal review.

This feature should be utilized in place of the traditional method of prepending `[WIP]` to the PR title.

As stated earlier, **ensure that "Allow edits from maintainers" is checked**. This gives permission for maintainers to commit changes directly to your fork, speeding up the review process.

## Footnotes

This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md).
The Contributing Guidelines for Python Discord projects can be found [on our website](https://pydis.com/contributing.md).
15 changes: 5 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,20 @@ ENV PIP_NO_CACHE_DIR=false \
PIPENV_HIDE_EMOJIS=1 \
PIPENV_NOSPIN=1

# Install git
RUN apt-get -y update \
&& apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user.
RUN useradd --system --shell /bin/false --uid 1500 pysite

# Install pipenv
RUN pip install -U pipenv

# Copy the project files into working directory
WORKDIR /app
COPY . .

# Copy dependency files
COPY Pipfile Pipfile.lock ./

# Install project dependencies
RUN pipenv install --system --deploy

# Copy project code
COPY . .

# Set Git SHA environment variable
ARG git_sha="development"
Expand Down
21 changes: 0 additions & 21 deletions LICENSE-SimpleMDE

This file was deleted.

8 changes: 4 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ django-filter = "~=2.1.0"
django-hosts = "~=4.0"
djangorestframework = "~=3.11.0"
psycopg2-binary = "~=2.8"
django-simple-bulma = "~=1.2"
django-simple-bulma = "~=2.1"
whitenoise = "~=5.0"
requests = "~=2.21"
pygments = "~=2.3.1"
wiki = "~=0.6.0"
pyyaml = "~=5.1"
gunicorn = "~=20.0.4"
django-allauth = "~=0.41"
sentry-sdk = "~=0.19"
markdown = "~=3.3.4"
python-frontmatter = "~=1.0"

[dev-packages]
coverage = "~=5.0"
Expand All @@ -34,6 +33,7 @@ flake8-todo = "~=0.7"
mccabe = "~=0.6.1"
pep8-naming = "~=0.9"
pre-commit = "~=2.1"
pyfakefs = "~=4.4.0"
coveralls = "~=2.1"

[requires]
Expand Down
Loading

0 comments on commit 8c7c3b1

Please sign in to comment.