Skip to content

Commit

Permalink
Merge pull request #55 from mantiumai/AlexN/pre-commit-hooks
Browse files Browse the repository at this point in the history
run pre-commit hooks in CI
  • Loading branch information
alex-nork authored Jul 11, 2023
2 parents 38ff442 + 060eb0b commit aa4d457
Show file tree
Hide file tree
Showing 41 changed files with 232 additions and 26,517 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
cd chirps; python manage.py test
- name: Run Linting
run: |
isort --check-only --diff .
pre-commit run -a
pylint --load-plugins pylint_django --django-settings-module="chirps.settings" $(find . -name "*.py" | xargs)
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ cython_debug/
.vscode/launch.json

chirps/erl_crash.dump
*.dump
*.dump
68 changes: 34 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,42 @@ repos:
- --exclude="(\.gitlab)"

# pydocstyle checks docstring styles after blue is done reformatting
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# types: [python]
# exclude: 'test_.+\.py'
# args:
# - --config=.pydocstyle
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
types: [python]
exclude: '^.*/migrations/.*$|test_.+\.py'
args:
- --config=.pydocstyle

# After blue is done reformatting everything, double check it with flake8
# - repo: https://github.com/pycqa/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
# types: [python]
# args:
# - --max-line-length=120
# - --extend-ignore=E203
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
types: [python]
args:
- --max-line-length=120
- --extend-ignore=E203

# mypy validates the python typing as per PEP 484
# See https://jaredkhan.com/blog/mypy-pre-commit for the source of this
# - repo: local
# # We do not use pre-commit/mirrors-mypy,
# # as it comes with opinionated defaults
# # (like --ignore-missing-imports)
# # and is difficult to configure to run
# # with the dependencies correctly installed.
# hooks:
# - id: mypy
# name: mypy
# entry: "./scripts/run-mypy"
# # A script hook uses the active virtual environment, so it must be up-to-date with `poetry install --sync`
# language: script
# types_or: [python, toml]
# # use require_serial so that script
# # is only called once per commit
# require_serial: true
# # Print the number of files as a sanity-check
# verbose: true
# - repo: local
# # We do not use pre-commit/mirrors-mypy,
# # as it comes with opinionated defaults
# # (like --ignore-missing-imports)
# # and is difficult to configure to run
# # with the dependencies correctly installed.
# hooks:
# - id: mypy
# name: mypy
# entry: "./scripts/run-mypy"
# # A script hook uses the active virtual environment, so it must be up-to-date with `poetry install --sync`
# language: script
# types_or: [python, toml]
# # use require_serial so that script
# # is only called once per commit
# require_serial: true
# # Print the number of files as a sanity-check
# verbose: true
1 change: 1 addition & 0 deletions chirps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProfileInline(admin.StackedInline):

class UserAdmin(BaseUserAdmin):
"""Define a new User admin."""

inlines = [ProfileInline]


Expand Down
2 changes: 1 addition & 1 deletion chirps/account/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Configures the account app."""""
"""Configures the account app."""
from django.apps import AppConfig


Expand Down
3 changes: 3 additions & 0 deletions chirps/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ def clean_openai_key(self):

class Meta:
"""Meta class for ProfileForm."""

model = Profile
fields = ['openai_key']

widgets = {'openai_key': forms.PasswordInput(attrs={'class': 'form-control'})}


class LoginForm(forms.Form):
"""Form for logging in."""

username = forms.CharField(max_length=256)
password = forms.CharField(max_length=256, widget=forms.PasswordInput)


class SignupForm(forms.Form):
"""Form for signing up."""

Expand Down
11 changes: 4 additions & 7 deletions chirps/account/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ def test_new_account_signup(self):
email = '[email protected]'

# Create a new account
response = self.client.post(reverse('signup'), {
'username': username,
'email': email,
'password1': password,
'password2': password
})
response = self.client.post(
reverse('signup'), {'username': username, 'email': email, 'password1': password, 'password2': password}
)
self.assertRedirects(response, '/', 302)

# Logout (since the account creation )
Expand All @@ -47,6 +44,6 @@ def test_new_account_signup(self):
{
'username': username,
'password': password,
}
},
)
self.assertRedirects(response, '/', status_code=302)
2 changes: 1 addition & 1 deletion chirps/account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
'password_reset/',
auth_views.PasswordResetView.as_view(template_name='account/password_reset.html'),
name='password_reset',
)
),
]
13 changes: 6 additions & 7 deletions chirps/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def profile(request):

return render(request, 'account/profile.html', {'form': form})


def signup(request):
"""Render the signup page and handle posts."""
if request.method == 'POST':
Expand All @@ -48,9 +49,7 @@ def signup(request):
if has_error is False:
# Create the user:
user = User.objects.create_user(
form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password1']
form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']
)
user.save()

Expand All @@ -68,19 +67,19 @@ def signup(request):

return render(request, 'account/signup.html', {'form': form})


def login_view(request):
"""Render the login page."""

# If there are no users, redirect to the installation page
if User.objects.count() == 0:
return redirect(reverse('install'))

if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = authenticate(request=request,
username=form.cleaned_data['username'],
password=form.cleaned_data['password'])
user = authenticate(
request=request, username=form.cleaned_data['username'], password=form.cleaned_data['password']
)
if user:
login(request, user)
return redirect('/')
Expand Down
5 changes: 2 additions & 3 deletions chirps/base_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

class InstallForm(forms.Form):
"""Form to render the new installation page."""

superuser_username = forms.CharField(label='Superuser Username', max_length=100)
superuser_email = forms.EmailField(label='Superuser Email', max_length=100)
superuser_password = forms.CharField(label='Superuser Password', max_length=100, widget=forms.PasswordInput)
superuser_password_confirm = forms.CharField(
label='Superuser Password (Confirm)',
max_length=100,
widget=forms.PasswordInput
label='Superuser Password (Confirm)', max_length=100, widget=forms.PasswordInput
)
3 changes: 2 additions & 1 deletion chirps/base_app/management/commands/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

class Command(BaseCommand):
"""Manage a local celery installation with this command."""

help = 'Interact with the local celery broker'

def add_arguments(self, parser):

"""Add arguments to celery command"""
parser.add_argument('--start', action='store_true', help='Start celery server')
parser.add_argument('--stop', action='store_true', help='Stop celery server')
parser.add_argument('--restart', action='store_true', help='Restart celery server')
Expand Down
2 changes: 2 additions & 0 deletions chirps/base_app/management/commands/initialize_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

class Command(BaseCommand):
"""Initialize the app by running multiple management commands."""

help = 'Initialize the app by running multiple management commands'

def handle(self, *args, **options):
"""Handle the command"""
# Run the 'redis --start' command
self.stdout.write(self.style.WARNING('Starting Redis...'))
call_command('redis', '--start')
Expand Down
5 changes: 3 additions & 2 deletions chirps/base_app/management/commands/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

class Command(BaseCommand):
"""Management command for interacting with rabbitmq."""

help = 'Interact with the local rabbitmq development server'

def add_arguments(self, parser):

"""Add arguments to rabbitmq command"""
parser.add_argument('--start', action='store_true', help='Start rabbitmq server')
parser.add_argument('--stop', action='store_true', help='Stop rabbitmq server')
parser.add_argument('--status', action='store_true', help='Check rabbitmq server status')

def handle(self, *args, **options):

"""Handle rabbitmq command"""
if options['start']:
os.system('rabbitmq-server start -detached')
elif options['stop']:
Expand Down
5 changes: 3 additions & 2 deletions chirps/base_app/management/commands/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

class Command(BaseCommand):
"""Management command for interacting with redis."""

help = 'Interact with the local redis development server'

def add_arguments(self, parser):

"""Add arguments to redis command"""
parser.add_argument('--start', action='store_true', help='Start redis server')
parser.add_argument('--stop', action='store_true', help='Stop redis server')
parser.add_argument('--status', action='store_true', help='Check redis server status')

def handle(self, *args, **options):

"""Handle redis command"""
if options['start']:
os.system('redis-server --daemonize yes')
elif options['stop']:
Expand Down
2 changes: 2 additions & 0 deletions chirps/base_app/management/commands/start_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

class Command(BaseCommand):
"""Initialize the app by running multiple management commands."""

help = 'Initialize the app by running multiple management commands'

def handle(self, *args, **options):
"""Start the services required to run the application, then start the server with `runserver`"""
# Run the 'redis --start' command
self.stdout.write(self.style.WARNING('Starting Redis...'))
call_command('redis', '--start')
Expand Down
2 changes: 1 addition & 1 deletion chirps/base_app/static/css/bootstrap.min.css

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions chirps/base_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@

from . import views

urlpatterns = [
path('', views.index, name='index'),
path('install', views.install, name='install')
]
urlpatterns = [path('', views.index, name='index'), path('install', views.install, name='install')]
4 changes: 2 additions & 2 deletions chirps/base_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def index(request):
"""Render the index page."""
return render(request, 'dashboard/index.html', {})


def install(request):
"""Render the install page."""

# If there are uses already, redirect to the dashboard
if User.objects.count() > 0:
return redirect(reverse('index'))
Expand All @@ -42,7 +42,7 @@ def install(request):
user = User.objects.create_superuser(
form.cleaned_data['superuser_username'],
form.cleaned_data['superuser_email'],
form.cleaned_data['superuser_password']
form.cleaned_data['superuser_password'],
)

# Create the user profile
Expand Down
28 changes: 14 additions & 14 deletions chirps/chirps/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,28 @@

# FERNET SETTINGS
if os.getenv('FERNET_KEY') is None:
raise Exception('FERNET_KEY environment variable is not set') # pylint: disable=broad-exception-raised
raise Exception('FERNET_KEY environment variable is not set') # pylint: disable=broad-exception-raised

FERNET_KEY = os.getenv('FERNET_KEY')

# LOGGING Configuration Options
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
'root': {
'handlers': ['console'],
'level': 'WARNING',
},
"loggers": {
"django": {
"handlers": ["console"],
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
"propagate": False,
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': False,
},
},
}
1 change: 1 addition & 0 deletions chirps/chirps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
Expand Down
Loading

0 comments on commit aa4d457

Please sign in to comment.