Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luzfcb committed Dec 19, 2022
1 parent efdfc5c commit 187345d
Show file tree
Hide file tree
Showing 34 changed files with 294 additions and 118 deletions.
10 changes: 10 additions & 0 deletions .bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exclude_dirs:
- /tests/
- ./venv/
- ./env/
- ./node_modules/
- .tox
- pydotorg/settings/local.py
skips:
- B101 # B101: assert
- B311 # B311: random
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
max-line-length = 120
ignore =
D100,D101,D102,D103,D105,D205,D400,
E305,E266,E231
W504,W606,X100
exclude = ./node_modules/*,*/migrations/*,./venv/*,./env/*,./_personal/*,.tox/*
per-file-ignores =
manage.py:INP001
docs/source/conf.py:INP001
*/test_*.py: E501,W605
custom_storages/__init__.py:F401
sponsors/models/__init__.py:F401
33 changes: 30 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
name: CI
on: [push, pull_request]
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9.16'
cache: 'pip' # caching pip dependencies
- run: python -m pip install pre-commit
shell: bash
- run: python -m pip freeze --local
shell: bash
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- run: pre-commit run --show-diff-on-failure --color=always --all-files
shell: bash
test:
runs-on: ubuntu-latest
services:
Expand All @@ -16,10 +43,10 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Check out repository
uses: actions/checkout@v2
- uses: actions/setup-python@v2
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9.16
python-version: "3.9.16"
- name: Cache Python dependencies
uses: actions/cache@v2
env:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Run pre-commit autoupdate every day at midnight
# and create a pull request if any changes

name: Pre-commit auto-update

on:
schedule:
- cron: "15 2 * * *"
workflow_dispatch: # to trigger manually

permissions:
contents: read

jobs:
auto-update:
# Disables this workflow from running in a repository that is not part of the indicated organization/user
if: github.repository_owner == 'pythondotorg'
permissions:
contents: write # for peter-evans/create-pull-request to create branch
pull-requests: write # for peter-evans/create-pull-request to create a PR

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9.16"

- name: Install pre-commit
run: pip install pre-commit

- name: Autoupdate template
run: pre-commit autoupdate

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
title: Auto-update pre-commit hooks
commit-message: Auto-update pre-commit hooks
body: Update versions of tools in pre-commit configs to latest version
labels: update
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v2.0.0'
hooks:
- id: autopep8
args: ['--in-place', '--select', 'E101,E112,E113,E115,E116,E117,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E133,E201,E202,E203,E211,E221,E222,E223,E224,E225,E226,E227,E228,E231,E231,E241,E242,E251,E252,E261,E262,E265,E271,E272,E273,E274,E275,E301,E302,E303,E304,E305,E306,W391']
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ['--py3-plus', '--py39-plus']
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear==22.12.6',
'flake8-no-pep420==2.3.0'
]
Empty file added boxes/templatetags/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion cms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_fieldsets(self, request, obj=None):
# Remove created/updated/creator from any existing fieldsets. They'll
# be there if the child class didn't manually declare fieldsets.
fieldsets = super().get_fieldsets(request, obj)
for name, fieldset in fieldsets:
for __, fieldset in fieldsets:
for f in ('created', 'updated', 'creator', 'last_modified_by'):
if f in fieldset['fields']:
fieldset['fields'].remove(f)
Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ django-debug-toolbar==3.2.1
coverage
ddt
model-bakery==1.4.0
flake8
pre-commit
2 changes: 1 addition & 1 deletion downloads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def validate_unique(self, exclude=None):
qs = ReleaseFile.objects.filter(release=self.release, os=self.os, download_button=True).exclude(pk=self.id)
if qs.count() > 0:
raise ValidationError("Only one Release File per OS can have \"Download button\" enabled")
super(ReleaseFile, self).validate_unique(exclude=exclude)
super().validate_unique(exclude=exclude)

class Meta:
verbose_name = 'Release File'
Expand Down
6 changes: 3 additions & 3 deletions downloads/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_is_version_at_least(self):

release_38 = Release.objects.create(name='Python 3.8.0')
self.assertFalse(release_38.is_version_at_least_3_9)
self.assert_(release_38.is_version_at_least_3_5)
self.assertTrue(release_38.is_version_at_least_3_5)

release_310 = Release.objects.create(name='Python 3.10.0')
self.assert_(release_310.is_version_at_least_3_9)
self.assert_(release_310.is_version_at_least_3_5)
self.assertTrue(release_310.is_version_at_least_3_9)
self.assertTrue(release_310.is_version_at_least_3_5)
5 changes: 3 additions & 2 deletions jobs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def test_job_preview_404(self):
self.assertEqual(response.status_code, 404)

def test_job_create_prepopulate_email(self):
# TODO: Refactor
create_url = reverse('jobs:job_create')
user_data = {
'username': 'phrasebook',
Expand All @@ -374,12 +375,12 @@ def test_job_create_prepopulate_email(self):
}

User = get_user_model()
creator = User.objects.create_user(**user_data)
User.objects.create_user(**user_data)

# Logged in, email address is prepopulated.
self.client.login(username=user_data['username'],
password=user_data['password'])
response = self.client.get(create_url)
self.client.get(create_url)

def test_job_types(self):
job_type2 = JobTypeFactory(
Expand Down
22 changes: 11 additions & 11 deletions nominations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def __str__(self):
def nominations_open(self):
if self.nominations_open_at and self.nominations_close_at:
return (
self.nominations_open_at
< datetime.datetime.now(datetime.timezone.utc)
< self.nominations_close_at
self.nominations_open_at <
datetime.datetime.now(datetime.timezone.utc) <
self.nominations_close_at
)

return False
Expand Down Expand Up @@ -128,8 +128,8 @@ def display_name(self):
@property
def display_previous_board_service(self):
if (
self.self_nomination is not None
and self.self_nomination.previous_board_service
self.self_nomination is not None and
self.self_nomination.previous_board_service
):
return self.self_nomination.previous_board_service

Expand Down Expand Up @@ -215,16 +215,16 @@ def get_accept_url(self):

def editable(self, user=None):
if (
self.nominee
and user == self.nominee.user
and self.election.nominations_open
self.nominee and
user == self.nominee.user and
self.election.nominations_open
):
return True

if (
user == self.nominator
and not (self.accepted or self.approved)
and self.election.nominations_open
user == self.nominator and
not (self.accepted or self.approved) and
self.election.nominations_open
):
return True

Expand Down
8 changes: 4 additions & 4 deletions pages/management/commands/import_pages_from_svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def copy_image(self, content_path, image):
pass
try:
shutil.copyfile(src, dst)
except Exception as e:
except Exception: # noqa
pass

def save_images(self, content_path, page):
Expand Down Expand Up @@ -79,7 +79,7 @@ def handle(self, *args, **kwargs):
raise ImproperlyConfigured("PYTHON_ORG_CONTENT_SVN_PATH not defined in settings")

matches = []
for root, dirnames, filenames in os.walk(self.SVN_REPO_PATH):
for root, __dirnames, filenames in os.walk(self.SVN_REPO_PATH):
for filename in filenames:
if re.match(r'(content\.(ht|rst)|body\.html)$', filename):
matches.append(os.path.join(root, filename))
Expand All @@ -93,7 +93,7 @@ def handle(self, *args, **kwargs):

try:
data = parse_page(os.path.dirname(match))
except Exception as e:
except Exception: # noqa
print(f"Unable to parse {match}")
traceback.print_exc()
continue
Expand All @@ -109,7 +109,7 @@ def handle(self, *args, **kwargs):

page_obj, _ = Page.objects.get_or_create(path=path, defaults=defaults)
self.save_images(path, page_obj)
except Exception as e:
except Exception: # noqa
print(f"Unable to create Page object for {match}")
traceback.print_exc()
continue
5 changes: 4 additions & 1 deletion peps/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)

PEP_TEMPLATE = 'pages/pep-page.html'
pep_url = lambda num: f'dev/peps/pep-{num}/'


def pep_url(num):
return f'dev/peps/pep-{num}/'


def get_peps_last_updated():
Expand Down
42 changes: 21 additions & 21 deletions pydotorg/settings/heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DEBUG = TEMPLATE_DEBUG = False

DATABASE_CONN_MAX_AGE = 600
DATABASES['default']['CONN_MAX_AGE'] = DATABASE_CONN_MAX_AGE
DATABASES['default']['CONN_MAX_AGE'] = DATABASE_CONN_MAX_AGE # noqa: F405

## Django Caching

Expand All @@ -16,7 +16,7 @@
}
}

HAYSTACK_SEARCHBOX_SSL_URL = config(
HAYSTACK_SEARCHBOX_SSL_URL = config( # noqa: F405
'SEARCHBOX_SSL_URL'
)

Expand All @@ -28,55 +28,55 @@
},
}

SECRET_KEY = config('SECRET_KEY')
SECRET_KEY = config('SECRET_KEY') # noqa: F405

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv()) # noqa: F405

MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
] + MIDDLEWARE
] + MIDDLEWARE # noqa: F405

MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
STATICFILES_STORAGE = 'custom_storages.PipelineManifestStorage'

EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_PORT = int(config('EMAIL_PORT'))
EMAIL_HOST = config('EMAIL_HOST') # noqa: F405
EMAIL_HOST_USER = config('EMAIL_HOST_USER') # noqa: F405
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') # noqa: F405
EMAIL_PORT = int(config('EMAIL_PORT')) # noqa: F405
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL')
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL') # noqa: F405

PEP_REPO_PATH = None
PEP_ARTIFACT_URL = config('PEP_ARTIFACT_URL')
PEP_ARTIFACT_URL = config('PEP_ARTIFACT_URL') # noqa: F405

# Fastly API Key
FASTLY_API_KEY = config('FASTLY_API_KEY')
FASTLY_API_KEY = config('FASTLY_API_KEY') # noqa: F405

SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_FASTLY_SSL', '1')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

INSTALLED_APPS += [
INSTALLED_APPS += [ # noqa: F405
"raven.contrib.django.raven_compat",
]

RAVEN_CONFIG = {
"dsn": config('SENTRY_DSN'),
"release": config('SOURCE_VERSION'),
"dsn": config('SENTRY_DSN'), # noqa: F405
"release": config('SOURCE_VERSION'), # noqa: F405
}

AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
AWS_DEFAULT_ACL = config('AWS_DEFAULT_ACL', default='public-read')
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID') # noqa: F405
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY') # noqa: F405
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME') # noqa: F405
AWS_DEFAULT_ACL = config('AWS_DEFAULT_ACL', default='public-read') # noqa: F405
AWS_AUTO_CREATE_BUCKET = False
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = False
AWS_S3_REGION_NAME = config('AWS_S3_REGION_NAME', default='us-east-1')
AWS_S3_REGION_NAME = config('AWS_S3_REGION_NAME', default='us-east-1') # noqa: F405
AWS_S3_USE_SSL = True
AWS_S3_ENDPOINT_URL = config('AWS_S3_ENDPOINT_URL', default='https://s3.amazonaws.com')
AWS_S3_ENDPOINT_URL = config('AWS_S3_ENDPOINT_URL', default='https://s3.amazonaws.com') # noqa: F405
Loading

0 comments on commit 187345d

Please sign in to comment.