Skip to content

Commit 42b9f8d

Browse files
Merge branch 'main' into fix-warnings
2 parents 7432612 + e538d96 commit 42b9f8d

File tree

3 files changed

+41
-81
lines changed

3 files changed

+41
-81
lines changed

.github/workflows/lint-test.yaml

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,26 @@ on:
1010
jobs:
1111
lint-test:
1212
runs-on: ubuntu-latest
13-
env:
14-
# Configure pip to cache dependencies and do a user install
15-
PIP_NO_CACHE_DIR: false
16-
PIP_USER: 1
17-
18-
# Make sure package manager does not use virtualenv
19-
POETRY_VIRTUALENVS_CREATE: false
20-
21-
# Specify explicit paths for python dependencies and the pre-commit
22-
# environment so we know which directories to cache
23-
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base
24-
PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
25-
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
2613

2714
steps:
28-
- name: Add custom PYTHONUSERBASE to PATH
29-
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
30-
3115
- name: Checkout repository
3216
uses: actions/checkout@v2
3317

34-
- name: Setup python
35-
id: python
36-
uses: actions/setup-python@v2
18+
- name: Install Python Dependencies
19+
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1
3720
with:
38-
python-version: '3.9'
21+
dev: true
22+
python_version: '3.9'
3923

4024
# Start the database early to give it a chance to get ready before
4125
# we start running tests.
4226
- name: Run database using docker-compose
4327
run: docker-compose run -d -p 7777:5432 --name pydis_web postgres
4428

45-
# This step caches our Python dependencies. To make sure we
46-
# only restore a cache when the dependencies, the python version,
47-
# the runner operating system, and the dependency location haven't
48-
# changed, we create a cache key that is a composite of those states.
49-
#
50-
# Only when the context is exactly the same, we will restore the cache.
51-
- name: Python Dependency Caching
52-
uses: actions/cache@v2
53-
id: python_cache
54-
with:
55-
path: ${{ env.PYTHONUSERBASE }}
56-
key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
57-
${{ steps.python.outputs.python-version }}-\
58-
${{ hashFiles('./pyproject.toml', './poetry.lock') }}"
59-
60-
# Install our dependencies if we did not restore a dependency cache
61-
- name: Install dependencies using poetry
62-
if: steps.python_cache.outputs.cache-hit != 'true'
63-
run: |
64-
pip install poetry
65-
poetry install
66-
67-
# This step caches our pre-commit environment. To make sure we
68-
# do create a new environment when our pre-commit setup changes,
69-
# we create a cache key based on relevant factors.
70-
- name: Pre-commit Environment Caching
71-
uses: actions/cache@v2
72-
with:
73-
path: ${{ env.PRE_COMMIT_HOME }}
74-
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
75-
${{ steps.python.outputs.python-version }}-\
76-
${{ hashFiles('./.pre-commit-config.yaml') }}"
77-
7829
# We will not run `flake8` here, as we will use a separate flake8
79-
# action. As pre-commit does not support user installs, we set
80-
# PIP_USER=0 to not do a user install.
30+
# action.
8131
- name: Run pre-commit hooks
82-
run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files
32+
run: SKIP=flake8 pre-commit run --all-files
8333

8434
# Run flake8 and have it format the linting errors in the format of
8535
# the GitHub Workflow command to register error annotations. This

Dockerfile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
FROM --platform=linux/amd64 python:3.9-slim-buster
1+
FROM ghcr.io/chrislovering/python-poetry-base:3.9-slim
22

33
# Allow service to handle stops gracefully
44
STOPSIGNAL SIGQUIT
55

6-
# Set pip to have cleaner logs and no saved cache
7-
ENV PIP_NO_CACHE_DIR=false \
8-
POETRY_VIRTUALENVS_CREATE=false
9-
10-
# Install poetry
11-
RUN pip install -U poetry
12-
136
# Copy the project files into working directory
147
WORKDIR /app
158

169
# Install project dependencies
1710
COPY pyproject.toml poetry.lock ./
18-
RUN poetry install --no-dev
11+
RUN poetry install --without dev
1912

2013
# Set Git SHA environment variable
2114
ARG git_sha="development"
@@ -34,14 +27,14 @@ RUN \
3427
SECRET_KEY=dummy_value \
3528
DATABASE_URL=postgres://localhost \
3629
METRICITY_DB_URL=postgres://localhost \
37-
python manage.py collectstatic --noinput --clear
30+
poetry run python manage.py collectstatic --noinput --clear
3831

3932
# Build static files if we are doing a static build
4033
ARG STATIC_BUILD=false
4134
RUN if [ $STATIC_BUILD = "TRUE" ] ; \
42-
then SECRET_KEY=dummy_value python manage.py distill-local build --traceback --force ; \
35+
then SECRET_KEY=dummy_value poetry run python manage.py distill-local build --traceback --force ; \
4336
fi
4437

4538
# Run web server through custom manager
46-
ENTRYPOINT ["python", "manage.py"]
39+
ENTRYPOINT ["poetry", "run", "python", "manage.py"]
4740
CMD ["run"]

pydis_site/apps/api/views.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ class RulesView(APIView):
3737
3838
## Routes
3939
### GET /rules
40-
Returns a JSON array containing the server's rules:
40+
Returns a JSON array containing the server's rules
41+
and keywords relating to each rule.
42+
Example response:
4143
4244
>>> [
43-
... "Eat candy.",
44-
... "Wake up at 4 AM.",
45-
... "Take your medicine."
45+
... ["Eat candy.", ["candy", "sweets"]],
46+
... ["Wake up at 4 AM.", ["wake_up", "early", "early_bird"]],
47+
... ["Take your medicine.", ["medicine", "health"]]
4648
... ]
4749
4850
Since some of the the rules require links, this view
@@ -100,6 +102,12 @@ def _format_link(description: str, link: str, target: str) -> str:
100102

101103
# `format` here is the result format, we have a link format here instead.
102104
def get(self, request, format=None): # noqa: D102,ANN001,ANN201
105+
"""
106+
Returns a list of our community rules coupled with their keywords.
107+
108+
Each item in the returned list is a tuple with the rule as first item
109+
and a list of keywords that match that rules as second item.
110+
"""
103111
link_format = request.query_params.get('link_format', 'md')
104112
if link_format not in ('html', 'md'):
105113
raise ParseError(
@@ -124,35 +132,44 @@ def get(self, request, format=None): # noqa: D102,ANN001,ANN201
124132

125133
return Response([
126134
(
127-
f"Follow the {pydis_coc}."
135+
f"Follow the {pydis_coc}.",
136+
["coc", "conduct", "code"]
128137
),
129138
(
130-
f"Follow the {discord_community_guidelines} and {discord_tos}."
139+
f"Follow the {discord_community_guidelines} and {discord_tos}.",
140+
["discord", "guidelines", "discord_tos"]
131141
),
132142
(
133-
"Respect staff members and listen to their instructions."
143+
"Respect staff members and listen to their instructions.",
144+
["respect", "staff", "instructions"]
134145
),
135146
(
136147
"Use English to the best of your ability. "
137-
"Be polite if someone speaks English imperfectly."
148+
"Be polite if someone speaks English imperfectly.",
149+
["english", "language"]
138150
),
139151
(
140152
"Do not provide or request help on projects that may break laws, "
141-
"breach terms of services, or are malicious or inappropriate."
153+
"breach terms of services, or are malicious or inappropriate.",
154+
["infraction", "tos", "breach", "malicious", "inappropriate"]
142155
),
143156
(
144-
"Do not post unapproved advertising."
157+
"Do not post unapproved advertising.",
158+
["ad", "ads", "advert", "advertising"]
145159
),
146160
(
147161
"Keep discussions relevant to the channel topic. "
148-
"Each channel's description tells you the topic."
162+
"Each channel's description tells you the topic.",
163+
["off-topic", "topic", "relevance"]
149164
),
150165
(
151166
"Do not help with ongoing exams. When helping with homework, "
152-
"help people learn how to do the assignment without doing it for them."
167+
"help people learn how to do the assignment without doing it for them.",
168+
["exam", "exams", "assignment", "assignments", "homework"]
153169
),
154170
(
155-
"Do not offer or ask for paid work of any kind."
171+
"Do not offer or ask for paid work of any kind.",
172+
["paid", "work", "money"]
156173
),
157174
])
158175

0 commit comments

Comments
 (0)