Skip to content

Commit 187345d

Browse files
committed
wip
1 parent efdfc5c commit 187345d

34 files changed

+294
-118
lines changed

.bandit.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exclude_dirs:
2+
- /tests/
3+
- ./venv/
4+
- ./env/
5+
- ./node_modules/
6+
- .tox
7+
- pydotorg/settings/local.py
8+
skips:
9+
- B101 # B101: assert
10+
- B311 # B311: random

.flake8

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
max-line-length = 120
3+
ignore =
4+
D100,D101,D102,D103,D105,D205,D400,
5+
E305,E266,E231
6+
W504,W606,X100
7+
exclude = ./node_modules/*,*/migrations/*,./venv/*,./env/*,./_personal/*,.tox/*
8+
per-file-ignores =
9+
manage.py:INP001
10+
docs/source/conf.py:INP001
11+
*/test_*.py: E501,W605
12+
custom_storages/__init__.py:F401
13+
sponsors/models/__init__.py:F401

.github/workflows/ci.yml

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
name: CI
22
on: [push, pull_request]
3+
concurrency:
4+
group: ${{ github.head_ref || github.run_id }}
5+
cancel-in-progress: true
6+
7+
permissions:
8+
contents: read
9+
310
jobs:
11+
lint:
12+
name: Lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v3
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.9.16'
20+
cache: 'pip' # caching pip dependencies
21+
- run: python -m pip install pre-commit
22+
shell: bash
23+
- run: python -m pip freeze --local
24+
shell: bash
25+
- uses: actions/cache@v3
26+
with:
27+
path: ~/.cache/pre-commit
28+
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
29+
- run: pre-commit run --show-diff-on-failure --color=always --all-files
30+
shell: bash
431
test:
532
runs-on: ubuntu-latest
633
services:
@@ -16,10 +43,10 @@ jobs:
1643
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1744
steps:
1845
- name: Check out repository
19-
uses: actions/checkout@v2
20-
- uses: actions/setup-python@v2
46+
uses: actions/checkout@v3
47+
- uses: actions/setup-python@v4
2148
with:
22-
python-version: 3.9.16
49+
python-version: "3.9.16"
2350
- name: Cache Python dependencies
2451
uses: actions/cache@v2
2552
env:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Run pre-commit autoupdate every day at midnight
2+
# and create a pull request if any changes
3+
4+
name: Pre-commit auto-update
5+
6+
on:
7+
schedule:
8+
- cron: "15 2 * * *"
9+
workflow_dispatch: # to trigger manually
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
auto-update:
16+
# Disables this workflow from running in a repository that is not part of the indicated organization/user
17+
if: github.repository_owner == 'pythondotorg'
18+
permissions:
19+
contents: write # for peter-evans/create-pull-request to create branch
20+
pull-requests: write # for peter-evans/create-pull-request to create a PR
21+
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-python@v4
26+
with:
27+
python-version: "3.9.16"
28+
29+
- name: Install pre-commit
30+
run: pip install pre-commit
31+
32+
- name: Autoupdate template
33+
run: pre-commit autoupdate
34+
35+
- name: Create Pull Request
36+
uses: peter-evans/create-pull-request@v4
37+
with:
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
branch: update/pre-commit-autoupdate
40+
title: Auto-update pre-commit hooks
41+
commit-message: Auto-update pre-commit hooks
42+
body: Update versions of tools in pre-commit configs to latest version
43+
labels: update

.pre-commit-config.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-autopep8
3+
rev: 'v2.0.0'
4+
hooks:
5+
- id: autopep8
6+
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']
7+
- repo: https://github.com/asottile/pyupgrade
8+
rev: v3.3.1
9+
hooks:
10+
- id: pyupgrade
11+
args: ['--py3-plus', '--py39-plus']
12+
- repo: https://github.com/PyCQA/flake8
13+
rev: 5.0.4
14+
hooks:
15+
- id: flake8
16+
additional_dependencies: [
17+
'flake8-bugbear==22.12.6',
18+
'flake8-no-pep420==2.3.0'
19+
]

boxes/templatetags/__init__.py

Whitespace-only changes.

cms/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_fieldsets(self, request, obj=None):
4444
# Remove created/updated/creator from any existing fieldsets. They'll
4545
# be there if the child class didn't manually declare fieldsets.
4646
fieldsets = super().get_fieldsets(request, obj)
47-
for name, fieldset in fieldsets:
47+
for __, fieldset in fieldsets:
4848
for f in ('created', 'updated', 'creator', 'last_modified_by'):
4949
if f in fieldset['fields']:
5050
fieldset['fields'].remove(f)

dev-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ django-debug-toolbar==3.2.1
1414
coverage
1515
ddt
1616
model-bakery==1.4.0
17+
flake8
18+
pre-commit

downloads/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def validate_unique(self, exclude=None):
338338
qs = ReleaseFile.objects.filter(release=self.release, os=self.os, download_button=True).exclude(pk=self.id)
339339
if qs.count() > 0:
340340
raise ValidationError("Only one Release File per OS can have \"Download button\" enabled")
341-
super(ReleaseFile, self).validate_unique(exclude=exclude)
341+
super().validate_unique(exclude=exclude)
342342

343343
class Meta:
344344
verbose_name = 'Release File'

downloads/tests/test_models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def test_is_version_at_least(self):
8282

8383
release_38 = Release.objects.create(name='Python 3.8.0')
8484
self.assertFalse(release_38.is_version_at_least_3_9)
85-
self.assert_(release_38.is_version_at_least_3_5)
85+
self.assertTrue(release_38.is_version_at_least_3_5)
8686

8787
release_310 = Release.objects.create(name='Python 3.10.0')
88-
self.assert_(release_310.is_version_at_least_3_9)
89-
self.assert_(release_310.is_version_at_least_3_5)
88+
self.assertTrue(release_310.is_version_at_least_3_9)
89+
self.assertTrue(release_310.is_version_at_least_3_5)

jobs/tests/test_views.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def test_job_preview_404(self):
366366
self.assertEqual(response.status_code, 404)
367367

368368
def test_job_create_prepopulate_email(self):
369+
# TODO: Refactor
369370
create_url = reverse('jobs:job_create')
370371
user_data = {
371372
'username': 'phrasebook',
@@ -374,12 +375,12 @@ def test_job_create_prepopulate_email(self):
374375
}
375376

376377
User = get_user_model()
377-
creator = User.objects.create_user(**user_data)
378+
User.objects.create_user(**user_data)
378379

379380
# Logged in, email address is prepopulated.
380381
self.client.login(username=user_data['username'],
381382
password=user_data['password'])
382-
response = self.client.get(create_url)
383+
self.client.get(create_url)
383384

384385
def test_job_types(self):
385386
job_type2 = JobTypeFactory(

nominations/models.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def __str__(self):
3232
def nominations_open(self):
3333
if self.nominations_open_at and self.nominations_close_at:
3434
return (
35-
self.nominations_open_at
36-
< datetime.datetime.now(datetime.timezone.utc)
37-
< self.nominations_close_at
35+
self.nominations_open_at <
36+
datetime.datetime.now(datetime.timezone.utc) <
37+
self.nominations_close_at
3838
)
3939

4040
return False
@@ -128,8 +128,8 @@ def display_name(self):
128128
@property
129129
def display_previous_board_service(self):
130130
if (
131-
self.self_nomination is not None
132-
and self.self_nomination.previous_board_service
131+
self.self_nomination is not None and
132+
self.self_nomination.previous_board_service
133133
):
134134
return self.self_nomination.previous_board_service
135135

@@ -215,16 +215,16 @@ def get_accept_url(self):
215215

216216
def editable(self, user=None):
217217
if (
218-
self.nominee
219-
and user == self.nominee.user
220-
and self.election.nominations_open
218+
self.nominee and
219+
user == self.nominee.user and
220+
self.election.nominations_open
221221
):
222222
return True
223223

224224
if (
225-
user == self.nominator
226-
and not (self.accepted or self.approved)
227-
and self.election.nominations_open
225+
user == self.nominator and
226+
not (self.accepted or self.approved) and
227+
self.election.nominations_open
228228
):
229229
return True
230230

pages/management/commands/import_pages_from_svn.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def copy_image(self, content_path, image):
5151
pass
5252
try:
5353
shutil.copyfile(src, dst)
54-
except Exception as e:
54+
except Exception: # noqa
5555
pass
5656

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

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

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

110110
page_obj, _ = Page.objects.get_or_create(path=path, defaults=defaults)
111111
self.save_images(path, page_obj)
112-
except Exception as e:
112+
except Exception: # noqa
113113
print(f"Unable to create Page object for {match}")
114114
traceback.print_exc()
115115
continue

peps/converters.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
)
1313

1414
PEP_TEMPLATE = 'pages/pep-page.html'
15-
pep_url = lambda num: f'dev/peps/pep-{num}/'
15+
16+
17+
def pep_url(num):
18+
return f'dev/peps/pep-{num}/'
1619

1720

1821
def get_peps_last_updated():

pydotorg/settings/heroku.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
DEBUG = TEMPLATE_DEBUG = False
66

77
DATABASE_CONN_MAX_AGE = 600
8-
DATABASES['default']['CONN_MAX_AGE'] = DATABASE_CONN_MAX_AGE
8+
DATABASES['default']['CONN_MAX_AGE'] = DATABASE_CONN_MAX_AGE # noqa: F405
99

1010
## Django Caching
1111

@@ -16,7 +16,7 @@
1616
}
1717
}
1818

19-
HAYSTACK_SEARCHBOX_SSL_URL = config(
19+
HAYSTACK_SEARCHBOX_SSL_URL = config( # noqa: F405
2020
'SEARCHBOX_SSL_URL'
2121
)
2222

@@ -28,55 +28,55 @@
2828
},
2929
}
3030

31-
SECRET_KEY = config('SECRET_KEY')
31+
SECRET_KEY = config('SECRET_KEY') # noqa: F405
3232

33-
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
33+
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv()) # noqa: F405
3434

3535
MIDDLEWARE = [
3636
'whitenoise.middleware.WhiteNoiseMiddleware',
37-
] + MIDDLEWARE
37+
] + MIDDLEWARE # noqa: F405
3838

3939
MEDIAFILES_LOCATION = 'media'
4040
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
4141
STATICFILES_STORAGE = 'custom_storages.PipelineManifestStorage'
4242

43-
EMAIL_HOST = config('EMAIL_HOST')
44-
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
45-
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
46-
EMAIL_PORT = int(config('EMAIL_PORT'))
43+
EMAIL_HOST = config('EMAIL_HOST') # noqa: F405
44+
EMAIL_HOST_USER = config('EMAIL_HOST_USER') # noqa: F405
45+
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') # noqa: F405
46+
EMAIL_PORT = int(config('EMAIL_PORT')) # noqa: F405
4747
EMAIL_USE_TLS = True
48-
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL')
48+
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL') # noqa: F405
4949

5050
PEP_REPO_PATH = None
51-
PEP_ARTIFACT_URL = config('PEP_ARTIFACT_URL')
51+
PEP_ARTIFACT_URL = config('PEP_ARTIFACT_URL') # noqa: F405
5252

5353
# Fastly API Key
54-
FASTLY_API_KEY = config('FASTLY_API_KEY')
54+
FASTLY_API_KEY = config('FASTLY_API_KEY') # noqa: F405
5555

5656
SECURE_SSL_REDIRECT = True
5757
SECURE_PROXY_SSL_HEADER = ('HTTP_FASTLY_SSL', '1')
5858
SESSION_COOKIE_SECURE = True
5959
CSRF_COOKIE_SECURE = True
6060

61-
INSTALLED_APPS += [
61+
INSTALLED_APPS += [ # noqa: F405
6262
"raven.contrib.django.raven_compat",
6363
]
6464

6565
RAVEN_CONFIG = {
66-
"dsn": config('SENTRY_DSN'),
67-
"release": config('SOURCE_VERSION'),
66+
"dsn": config('SENTRY_DSN'), # noqa: F405
67+
"release": config('SOURCE_VERSION'), # noqa: F405
6868
}
6969

70-
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
71-
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
72-
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
73-
AWS_DEFAULT_ACL = config('AWS_DEFAULT_ACL', default='public-read')
70+
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID') # noqa: F405
71+
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY') # noqa: F405
72+
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME') # noqa: F405
73+
AWS_DEFAULT_ACL = config('AWS_DEFAULT_ACL', default='public-read') # noqa: F405
7474
AWS_AUTO_CREATE_BUCKET = False
7575
AWS_S3_OBJECT_PARAMETERS = {
7676
'CacheControl': 'max-age=86400',
7777
}
7878
AWS_QUERYSTRING_AUTH = False
7979
AWS_S3_FILE_OVERWRITE = False
80-
AWS_S3_REGION_NAME = config('AWS_S3_REGION_NAME', default='us-east-1')
80+
AWS_S3_REGION_NAME = config('AWS_S3_REGION_NAME', default='us-east-1') # noqa: F405
8181
AWS_S3_USE_SSL = True
82-
AWS_S3_ENDPOINT_URL = config('AWS_S3_ENDPOINT_URL', default='https://s3.amazonaws.com')
82+
AWS_S3_ENDPOINT_URL = config('AWS_S3_ENDPOINT_URL', default='https://s3.amazonaws.com') # noqa: F405

0 commit comments

Comments
 (0)