Skip to content

Commit

Permalink
Merge pull request #2 from pymasterspl/feature/gh-actions
Browse files Browse the repository at this point in the history
attempt ghactions
  • Loading branch information
jacoor authored May 4, 2024
2 parents 0fefbd1 + eee8339 commit 6a1c4fd
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 18 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run linting

on:
pull_request:
types: [opened, ready_for_review, synchronize, reopened]

jobs:
pep8:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.11"]
if: github.event.pull_request.draft == false
steps:
- name: Cancel Previous Runs
if: "!endsWith(github.ref, '/master') && !endsWith(github.ref, '/dev')"
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
78 changes: 78 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Run tests

on:
pull_request:
types: [opened, ready_for_review, synchronize, reopened]

jobs:
pytests:
runs-on: ubuntu-22.04
if: github.event.pull_request.draft == false
steps:
- name: Cancel Previous Runs
if: "!endsWith(github.ref, '/master') && !endsWith(github.ref, '/dev')"
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/[email protected]

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.11"
architecture: "x64"

- name: Cache Poetry
id: cache-poetry
uses: actions/cache@v3
with:
path: ~/.poetry
key: ${{ matrix.os }}-poetry

# Only runs when key from caching step changes
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
# Poetry still needs to be re-prepended to the PATH on each run, since
# PATH does not persist between runs.
- name: Add Poetry to $PATH
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Get Poetry version
run: poetry --version

- name: Check pyproject.toml validity
run: |
poetry check --no-interaction
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v3
with:
path: ${{github.workspace}}/.venv
key: ${{ matrix.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ matrix.os }}-

- name: Install deps
if: steps.cache-deps.cache-hit != 'true'
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
- name: Create .env file
run: |
echo "SECRET_KEY=default_secret_key" > .env
echo "DEBUG=False" >> .env
echo "ALLOWED_HOSTS=[]" >> .env
- name: Check Migrations
run: |
poetry run python manage.py makemigrations --check --dry-run
- name: Run pytest
run: |
poetry run pytest -vv
110 changes: 101 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,101 @@
# reddit
Reddit clone for educational purposes.

## Roadmap
- Users management
- registration
- login via email
- password recovery
- discuss next steps and design models
# Reddit
Reddit clone for educational purposes. Developed by PyMasters

## Rules of engagement
Good reading on working with code changes and pull request is https://google.github.io/eng-practices/. It contains both views - change author and reviewer.

### Rules

1. Do not commit directly to `master` or `dev`. Both branches are protected.
2. Check your code with `ruff check` prior to creating pull requests. The code is checked against PEP8 using `ruff`. Violations will not allow merging.
- fix can be applied by ruff automatically for some issues, check `ruff check --fix`.
3. Use pull request to add your work. Make pull request to `dev` branch.
- After creating pull request use "reviewers" option on far right of the screen to request review from "pymasters/reddit" team, or you can request review from certain team member directly by mentioning their name.
![alt text](readme-image.png)
- One of the team members (or multiple) will perform code review and approve the pull request or request changes.
- If changes are requested, all comments have to be in constructive and friendly manner, as shown in https://google.github.io/eng-practices/review/reviewer/comments.html
- It's a good thing to comment on the good parts of code with "Nice work" or something similar.
4. As this is a learning project, pair programming is most welcome. Jump on Zoom or google meet and work together: https://www.youtube.com/watch?v=wu6BOT-eMgc&t=105s&ab_channel=devmentor.pl
5. Code quality and automated tests will be run and required to pass before pull request can be merged.
6. At least one approval by other team member is required before pull request can be merged.
7. After pull request is approved and code quality + tests are passed, pull request is merged by the author.
8. It is author responsibility to watch over pull request, bump if there is no code review done, fix issues and merge pull request.

#### How to Set up

Clone repository to specific folder (ex. reddit):
```
git clone https://github.com/pymasterspl/reddit.git
```
You need to have installed Poetry package. If you don't have, please install using this command:
```
pip install poetry
```
Navigate to reddit folder by command:
```
cd reddit
```
Set poetry global option, to use project folder as place to hold Virtual environment (recommended):
```
poetry config virtualenvs.in-project true
```
Install virtual environment, using current dependencies:
```
poetry install
```
Copy file env-template to .env file using command:
```
# linux/mac
cp env-template .env
# windows
copy env-template .env
```
Start poetry virtual environment
```
poetry shell
```

Update local .env file as needed

Create admin account to access admin site:

```
# linux/mac
# to apply db changes
./manage.py migrate
./manage.py createsuperuser
# windows
# to apply db changes
python manage.py migrate
python manage.py createsuperuser
```


Run project:
```
# linux/mac
# to apply db changes
./manage.py migrate
# to start project
./manage.py runserver
# windows
# to apply db changes
python manage.py migrate
# to start project
python manage.py runserver
```

Load data from fixtures:
```
python manage.py loaddata {fixture_name}.json
```

Open web browser and navigate to localhost address: http://127.0.0.1:8000/

### In case of problems with starting the project:
1. Check the env-template file and update the local .env file if necessary
2. Run `poetry install`

16 changes: 16 additions & 0 deletions env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Enviroment .env file template,,
# In django project install: pip install python-decouple
# ## Decouple import in settings.py from decouple import config

# Your Django app secret key without '' or " ", in Django settings.py should be as follow:
# SECRET_KEY = config('SECRET_KEY')
SECRET_KEY=secret-key

# Debug state, in Django settings.py should be as follow:
# DEBUG = config('DEBUG')
DEBUG=True

# Allowed Hosts in Django settings.py should be as follow:
# ALLOWED_HOSTS = json.loads(config('ALLOWED_HOSTS'))
ALLOWED_HOSTS='["127.0.0.1", "192.168.99.100", "localhost"]'

13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
Django = "^5.0.4"
python-decouple = "^3.8"

[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
Expand All @@ -17,3 +18,31 @@ ruff = "^0.3.7"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
exclude = ["scripts/", "manage.py", "urls.py", "asgi.py", "wsgi.py", "migrations/"]
line-length = 120

indent-width = 4
target-version = "py311"

[tool.ruff.lint]
select = ["ALL"]
ignore = ["D104", "D100", "D103", "D211", "D213", "D101"]

[tool.ruff.format]
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.ruff.lint.per-file-ignores]
"**/tests/**/*.py" = [
# at least this three should be fine in tests:
"S101", # asserts allowed in tests...
"ARG", # Unused function args -> fixtures nevertheless are functionally relevant...
"FBT", # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize()
]
Binary file added readme-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions reddit/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Django settings for reddit project.
"""Django settings for reddit project.
Generated by 'django-admin startproject' using Django 5.0.4.
Expand All @@ -10,8 +9,11 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

import json
from pathlib import Path

from decouple import config

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -20,12 +22,18 @@
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-e4pma3)-c!52=l7+#68cj_qg(nx)o*s1q439+mwan6%+&srldd"

SECRET_KEY = config("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
DEBUG = config("DEBUG")


# SECURITY WARNING: don't run with debug turned on in production!


ALLOWED_HOSTS = json.loads(config("ALLOWED_HOSTS"))


# Application definition
Expand Down Expand Up @@ -77,7 +85,7 @@
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
},
}


Expand Down
Empty file added reddit/tests/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions reddit/tests/test_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_blank() -> None:
assert True, "just for verification of the config. Remove later on."

6 changes: 4 additions & 2 deletions reddit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"""
from django.contrib import admin
from django.urls import path

import os
x = 'alamasssssssssskotaal amasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskotaalamasssssssssskota'
print('test')
urlpatterns = [
path("admin/", admin.site.urls),
path('admin/', admin.site.urls),
]
6 changes: 6 additions & 0 deletions roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Roadmap
- Users management
- registration
- login via email - follow: https://akademiait.com.pl/zrozumiec-django-uzytkownicy-jak-stworzyc-wlasny-model-uzytkownika-z-logowaniem-po-adresie-email/
- password recovery
- discuss next steps and design models

0 comments on commit 6a1c4fd

Please sign in to comment.