Skip to content

Commit

Permalink
Fix several issues
Browse files Browse the repository at this point in the history
* Update Python version to 3.8.5 - fix issue django-stars#32
* Update PostgreSQL version to 12.4 & Redis version to 6.0.6 - fix issue django-stars#34
* Adjust isort CLI parameters to work with a new version - fix issue django-stars#30
* Update CircleCI config (update pip, database password) - fix issue django-stars#29
* Temporary pin Django & Celery versions
  • Loading branch information
alexryabtsev committed Aug 27, 2020
1 parent ebaac3e commit b6b53c3
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
working_directory: ~/project
docker:
- image: circleci/python:3.8.2
- image: circleci/python:3.8.5
environment:
AWESOME_SECRET_KEY: test-secret-key
AWESOME_EMAIL_BACKEND: django.core.mail.backends.dummy.EmailBackend
Expand All @@ -14,11 +14,11 @@ jobs:
AWESOME_DATABASE_URL: postgresql://postgres:awesome_password@localhost/awesome_test_db
AWESOME_CELERY_BROKER: redis://localhost:6379/1
AWESOME_CELERY_TASK_ALWAYS_EAGER: on
- image: postgres:12.2
- image: postgres:12.4
environment:
POSTGRES_DB: awesome_test_db
POSTGRES_PASSWORD: awesome_password
- image: redis:5.0.9
- image: redis:6.0.6
steps:
- checkout
- restore_cache:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Create python virtual environment. We recommend to use [pyenv](https://github.com/pyenv/pyenv) & [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv):

```bash
pyenv install 3.8.2
pyenv virtualenv 3.8.2 my_project
pyenv install 3.8.5
pyenv virtualenv 3.8.5 my_project
pyenv activate my_project
```

Expand Down
6 changes: 3 additions & 3 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"project_name": "awesome",
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
"domain_name": "example.com",
"python_version": "3.8.2",
"python_version": "3.8.5",
"database_password": "awesome_password_1",
"postgresql_version": "12.2",
"redis_version": "5.0.9"
"postgresql_version": "12.4",
"redis_version": "6.0.6"
}
4 changes: 1 addition & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class GenerateRequirementsInFileHook(AbstractHook):

def __init__(self):
self._project_requirements_with_versions_need_to_be_pinned = (
"Celery",
"Django",
"django-environ",
"django-filter",
"djangorestframework",
Expand All @@ -30,7 +28,7 @@ def __init__(self):
"redis",
"sentry-sdk",
)
self._project_requirements_with_versions_do_not_need_to_be_pinned = ("pytz", )
self._project_requirements_with_versions_do_not_need_to_be_pinned = ("Celery==4.4.6", "Django==3.0.9", "pytz")
self._dev_requirements_with_versions_need_to_be_pinned = (
"Pygments",
"Werkzeug",
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_project(ctx):
)
with ctx.cd(project_path):
ctx.run(f"python3 -m venv {virtual_env_path}", pty=True, replace_env=True)
ctx.run(f"{virtual_env_path}/bin/pip install fabric invoke pip-tools", pty=True, replace_env=True)
ctx.run(f"{virtual_env_path}/bin/pip install -U pip fabric invoke pip-tools", pty=True, replace_env=True)
ctx.run(f"""source {virtual_env_path}/bin/activate && \
{virtual_env_path}/bin/fab pip.compile && \
{virtual_env_path}/bin/fab pip.sync && \
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generate_requirements_in_file_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def test_get_project_packages(mocker):
packages = hook._get_project_packages()

assert packages == [
"Celery==<mocked>",
"Django==<mocked>",
"Celery==4.4.6",
"Django==3.0.9",
"django-environ==<mocked>",
"django-filter==<mocked>",
"djangorestframework==<mocked>",
Expand Down
4 changes: 3 additions & 1 deletion {{ cookiecutter.project_slug }}/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ jobs:
{{ cookiecutter.project_slug | upper() }}_SECRET_KEY: stub
{{ cookiecutter.project_slug | upper() }}_USE_SENTRY: off
{{ cookiecutter.project_slug | upper() }}_DEBUG: off
{{ cookiecutter.project_slug | upper() }}_DATABASE_URL: postgresql://postgres@localhost/{{ cookiecutter.project_slug }}_test_db
{{ cookiecutter.project_slug | upper() }}_DATABASE_URL: postgresql://postgres:test_db_password@localhost/{{ cookiecutter.project_slug }}_test_db
{{ cookiecutter.project_slug | upper() }}_CELERY_BROKER: redis://localhost:6379/1
{{ cookiecutter.project_slug | upper() }}_CELERY_TASK_ALWAYS_EAGER: on
- image: postgres:{{ cookiecutter.postgresql_version }}
environment:
POSTGRES_DB: {{ cookiecutter.project_slug }}_test_db
POSTGRES_PASSWORD: test_db_password
- image: redis:{{ cookiecutter.redis_version }}
steps:
- checkout
Expand All @@ -27,6 +28,7 @@ jobs:
command: |
python3 -m venv .env
. .env/bin/activate
pip install -U pip
pip install -r api/requirements-dev.txt
- save_cache:
key: {% raw %}python-deps-v1-{{ checksum "api/requirements-dev.txt" }}{% endraw %}
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
args: [.]
pass_filenames: false
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
rev: v5.4.2
hooks:
- id: isort
- repo: https://github.com/gvanderest/pylama-pre-commit
Expand Down
1 change: 1 addition & 0 deletions {{ cookiecutter.project_slug }}/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

{{ cookiecutter.project_slug | upper() }}_DATABASE_URL=psql://postgres:{{ cookiecutter.database_password }}@127.0.0.1:5432/{{ cookiecutter.project_slug }}_db
{{ cookiecutter.project_slug | upper() }}_CELERY_BROKER=redis://127.0.0.1:6379/1
{{ cookiecutter.project_slug | upper() }}_REDIS_URL=redis://127.0.0.1:6379/2

{{ cookiecutter.project_slug | upper() }}_DEV_INSTALLED_APPS=debug_toolbar
{{ cookiecutter.project_slug | upper() }}_DEV_MIDDLEWARE=debug_toolbar.middleware.DebugToolbarMiddleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ChangePasswordSerializer(serializers.Serializer):
new_password = serializers.CharField(max_length=128, write_only=True, style={"input_type": "password"})

def __init__(self, *args, **kwargs):
super(ChangePasswordSerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.request = self.context.get("request")
self.user = getattr(self.request, "user", None)
self.password_service = PasswordService()
Expand Down Expand Up @@ -50,7 +50,7 @@ class ConfirmResetPasswordSerializer(serializers.Serializer):
signature = serializers.CharField(max_length=71, write_only=True)

def __init__(self, *args, **kwargs):
super(ConfirmResetPasswordSerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.password_service = PasswordService()

def validate_password(self, password):
Expand Down Expand Up @@ -80,7 +80,7 @@ class ResetPasswordSerializer(serializers.Serializer):
email = serializers.EmailField(max_length=128, write_only=True)

def __init__(self, *args, **kwargs):
super(ResetPasswordSerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.password_service = PasswordService()

def save(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Meta:
fields = ("email", "first_name", "last_name", "password")

def __init__(self, *args, **kwargs):
super(RegistrationSerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.password_service = PasswordService()

def validate_email(self, email):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChangePasswordAPIView(CreateAPIView):

@swagger_auto_schema(responses={status.HTTP_204_NO_CONTENT: openapi.Response("")})
def post(self, request, *args, **kwargs): # pragma: no cover
super(ChangePasswordAPIView, self).post(request, *args, **kwargs)
super().post(request, *args, **kwargs)
return Response(status=status.HTTP_204_NO_CONTENT)


Expand All @@ -30,7 +30,7 @@ class ResetPasswordAPIView(CreateAPIView):

@swagger_auto_schema(responses={status.HTTP_204_NO_CONTENT: openapi.Response("")})
def post(self, request, *args, **kwargs): # pragma: no cover
super(ResetPasswordAPIView, self).post(request, *args, **kwargs)
super().post(request, *args, **kwargs)
return Response(status=status.HTTP_204_NO_CONTENT)


Expand All @@ -40,5 +40,5 @@ class ConfirmResetPasswordAPIView(CreateAPIView):

@swagger_auto_schema(responses={status.HTTP_204_NO_CONTENT: openapi.Response("")})
def post(self, request, *args, **kwargs): # pragma: no cover
super(ConfirmResetPasswordAPIView, self).post(request, *args, **kwargs)
super().post(request, *args, **kwargs)
return Response(status=status.HTTP_204_NO_CONTENT)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class SQLFormatter(logging.Formatter):
def format(self, record):
sql = sqlparse.format(record.sql.strip(), reindent=True)
record.statement = pygments.highlight(sql, SqlLexer(), TerminalTrueColorFormatter(style="monokai"))
return super(SQLFormatter, self).format(record)
return super().format(record)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..environment import env


REDIS_URL = env.str("{{ cookiecutter.project_slug | upper() }}_REDIS_URL", default="redis://127.0.0.1:6379/2")
REDIS_URL = env.str("{{ cookiecutter.project_slug | upper() }}_REDIS_URL", default="redis://redis:6379/2")
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

# enable serve static by django for local develop
if settings.DEBUG: # pragma: no cover
from django.conf.urls.static import static
from django.conf.urls.static import static # pylint: disable=ungrouped-imports

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Expand All @@ -75,7 +75,7 @@

# enable Sentry check (by raising 500 on demand)
if not settings.DEBUG:
from django.views.generic.base import View
from django.views.generic.base import View # pylint: disable=ungrouped-imports

class ServerErrorTestView(View):
def dispatch(self, request, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions {{ cookiecutter.project_slug }}/fabric_scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def test_black_apply(ctx):
@task()
def test_isort_check(ctx):
with ctx.cd(project_path()):
ctx.run("isort --check --skip .env", pty=True, replace_env=False)
ctx.run("isort --check --skip .env .", pty=True, replace_env=False)


@task()
def test_isort_apply(ctx):
with ctx.cd(project_path()):
ctx.run("isort --apply --skip .env", pty=True, replace_env=False)
ctx.run("isort --skip .env .", pty=True, replace_env=False)


@task()
Expand Down

0 comments on commit b6b53c3

Please sign in to comment.