Skip to content

Commit 921d353

Browse files
vinaypuppaltapaswenipathak
authored andcommitted
Configure flake8 and yapf with pre-commit (#215)
* add pre-commit * configure flake8 and yapf * configure travis to run all pre-commit hooks on changed files * run yapf on whole codebase and fix issues * add info on how to install pre-commit hooks
1 parent 1bd35db commit 921d353

13 files changed

+128
-80
lines changed

.flake8

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
ignore =
3+
# A continuation line is under-indented for a visual indentation.
4+
E128
5+
6+
max-line-length=80

.pre-commit-config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exclude: '^$'
2+
fail_fast: true
3+
repos:
4+
- repo: https://github.com/pre-commit/mirrors-yapf
5+
sha: v0.20.0
6+
hooks:
7+
- id: yapf
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
sha: v1.1.1
10+
hooks:
11+
- id: check-yaml
12+
- id: check-added-large-files
13+
- id: flake8

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ before_script:
2020
- cd oshc/
2121
- python manage.py migrate --noinput
2222
- python manage.py collectstatic --noinput
23+
- git diff-tree --no-commit-id --name-only -r $REVISION | xargs pre-commit run --files
2324

2425
script:
25-
- flake8 . --ignore=E128
2626
- coverage run --source='main' manage.py test --verbosity 2
2727

2828
after_success:

README.md

+36-23
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,61 @@ We are trying to create a medium where people who want to start with contributin
99
[Website](http://opensourcehelpcommunity.herokuapp.com/) [WIP]
1010

1111
## Deployement details
12+
1213
After every commit
1314

1415
1. The `predev` branch on GitHub is automatically deployed to [opensourcehelpcommunity-predev.herokuapp.com](http://opensourcehelpcommunity-predev.herokuapp.com/).
15-
2. The `develop` branch on github is automatically deployed to [opensourcehelpcommunity-dev.herokuapp.com](http://opensourcehelpcommunity-dev.herokuapp.com/).
16-
3. The `master` branch is automatically deployed [to opensourcehelpcommunity.herokuapp.com](http://opensourcehelpcommunity.herokuapp.com/) .
16+
1. The `develop` branch on github is automatically deployed to [opensourcehelpcommunity-dev.herokuapp.com](http://opensourcehelpcommunity-dev.herokuapp.com/).
17+
1. The `master` branch is automatically deployed [to opensourcehelpcommunity.herokuapp.com](http://opensourcehelpcommunity.herokuapp.com/) .
1718

1819
This is using [Django(1.11)](https://www.djangoproject.com/) and [Bootstrap](http://getbootstrap.com/)
1920

2021
## How to Contribute
21-
This is an Open Source project and we would be happy to see contributors who report bugs and file feature requests submitting pull requests as well. This project adheres to the Collaborative [code of conduct](https://github.com/OpenSourceHelpCommunity/OpenSourceHelpCommunity.github.io/blob/develop/CODE_OF_CONDUCT.md). By participating, you expect to maintain the code of conduct. Before creating `New issue` and `Pull request`, please refer to the [template](docs).
22+
23+
This is an Open Source project and we would be happy to see contributors who report bugs and file feature requests submitting pull requests as well. This project adheres to the Collaborative [code of conduct](https://github.com/OpenSourceHelpCommunity/OpenSourceHelpCommunity.github.io/blob/develop/CODE_OF_CONDUCT.md). By participating, you expect to maintain the code of conduct. Before creating `New issue` and `Pull request`, please refer to the [template](docs).
2224

2325
All the development is done on `predev` branch and once we're ready for testing the deployment in real environment with databases we merge the `predev` branch with the `develop` branch. When we're ready for new release we merge `develop` with `master` to deploy it on our main website. **Please submit your pull request based on `predev` branch.**
2426

2527
## Installations
28+
2629
Run
27-
```
30+
31+
```bash
2832
pip install -r requirements.txt
2933
```
30-
to install everything required to run this project on heroku as well as on your local.
3134

35+
to install everything required to run this project on heroku as well as on your local.
3236

3337
## To run this in your local
3438

3539
1. Clone this repository using
36-
```
37-
git clone [email protected]:OpenSourceHelpCommunity/OpenSourceHelpCommunity.github.io.git
38-
```
39-
40-
2. Go inside main Django app [Instructional video on installing Django](https://youtu.be/qgGIqRFvFFk)
41-
```
42-
cd oshc
43-
```
44-
45-
3. Collectstatic files using
46-
```
47-
python manage.py collectstatic
48-
```
49-
50-
4. Run the app
51-
```
52-
python manage.py runserver
53-
```
40+
41+
```bash
42+
git clone [email protected]:OpenSourceHelpCommunity/OpenSourceHelpCommunity.github.io.git
43+
```
44+
45+
1. Go inside main Django app [Instructional video on installing Django](https://youtu.be/qgGIqRFvFFk)
46+
47+
```bash
48+
cd oshc
49+
```
50+
51+
1. Install [pre-commit](pre-commit.com) into your git hooks. [pre-commit](pre-commit.com) will now run on every commit. Every time you clone a project that is using [pre-commit](pre-commit.com) running [pre-commit](pre-commit.com) install should always be the first thing you do after installing requirements.
52+
53+
```bash
54+
pre-commit install
55+
```
56+
57+
1. Collectstatic files using
58+
59+
```bash
60+
python manage.py collectstatic
61+
```
62+
63+
1. Run the app
64+
```bash
65+
python manage.py runserver
66+
```
5467

5568
To run the web app in Debug mode set the DEBUG environment variable.
5669
In Linux, run the `export DEBUG=True` command in the terminal.

oshc/authentication/urls.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
urlpatterns = [
55
url(r'^accounts/', include('allauth.urls')),
66
url(r'^accounts/login/profile/', views.profile, name="profile"),
7-
url(r'^ajax/validate_username/$', views.validate_username,
7+
url(r'^ajax/validate_username/$',
8+
views.validate_username,
89
name='validate_username'),
910
]

oshc/main/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def approve_contest(self, request, queryset):
2626
else:
2727
message_bit = "{} contests were".format(contest_approved)
2828
self.message_user(request, "{} approved.".format(message_bit))
29+
2930
approve_contest.short_description = "Approve"
3031

3132

oshc/main/migrations/0001_initial.py

+30-22
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,50 @@ class Migration(migrations.Migration):
99

1010
initial = True
1111

12-
dependencies = [
13-
]
12+
dependencies = []
1413

1514
operations = [
1615
migrations.CreateModel(
1716
name='chatSession',
1817
fields=[
19-
('id', models.AutoField(auto_created=True,
20-
primary_key=True,
21-
serialize=False, verbose_name='ID')),
22-
('title', models.CharField(help_text='Session title',
23-
max_length=128)),
24-
('profile_name', models.CharField(
25-
help_text="The person's name", max_length=128)),
26-
('profile_url', models.URLField(
27-
help_text="The Url of the person's website")),
28-
('description', models.TextField(
29-
help_text='Session details', max_length=512)),
18+
('id',
19+
models.AutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name='ID')),
24+
('title',
25+
models.CharField(help_text='Session title', max_length=128)),
26+
('profile_name',
27+
models.CharField(
28+
help_text="The person's name", max_length=128)),
29+
('profile_url',
30+
models.URLField(help_text="The Url of the person's website")),
31+
('description',
32+
models.TextField(help_text='Session details',
33+
max_length=512)),
3034
('start_date', models.DateTimeField()),
3135
('end_date', models.DateTimeField()),
32-
('register_url', models.URLField(
33-
help_text='URL for the event registration')),
36+
('register_url',
37+
models.URLField(help_text='URL for the event registration')),
3438
],
3539
),
3640
migrations.CreateModel(
3741
name='Contest',
3842
fields=[
39-
('id', models.AutoField(auto_created=True,
40-
primary_key=True,
41-
serialize=False, verbose_name='ID')),
42-
('name', models.CharField(help_text='Contest name',
43-
max_length=128)),
43+
('id',
44+
models.AutoField(
45+
auto_created=True,
46+
primary_key=True,
47+
serialize=False,
48+
verbose_name='ID')),
49+
('name',
50+
models.CharField(help_text='Contest name', max_length=128)),
4451
('link',
4552
models.URLField(help_text="URL of the contest's website")),
46-
('description', models.TextField(
47-
help_text='Contest details', max_length=512, null=True)),
53+
('description',
54+
models.TextField(
55+
help_text='Contest details', max_length=512, null=True)),
4856
('start_date', models.DateField(null=True)),
4957
('end_date', models.DateField(null=True)),
5058
('approved', models.BooleanField(default=False)),

oshc/main/migrations/0002_journey.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ class Migration(migrations.Migration):
1515
migrations.CreateModel(
1616
name='Journey',
1717
fields=[
18-
('id', models.AutoField(auto_created=True,
19-
primary_key=True, serialize=False, verbose_name='ID')),
20-
('title', models.CharField(help_text='Journey title',
21-
max_length=128)),
22-
('description', models.TextField(help_text='Session details',
23-
max_length=512)),
18+
('id',
19+
models.AutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name='ID')),
24+
('title',
25+
models.CharField(help_text='Journey title', max_length=128)),
26+
('description',
27+
models.TextField(help_text='Session details',
28+
max_length=512)),
2429
('start_date', models.DateTimeField()),
2530
],
2631
),

oshc/main/models.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class chatSession(models.Model):
88
title = models.CharField(max_length=128, help_text="Session title")
9-
profile_name = models.CharField(max_length=128,
10-
help_text="The person's name")
9+
profile_name = models.CharField(
10+
max_length=128, help_text="The person's name")
1111
profile_url = models.URLField(help_text="The Url of the person's website")
1212
description = models.TextField(max_length=512, help_text="Session details")
1313
start_date = models.DateTimeField()
@@ -21,8 +21,8 @@ def __str__(self):
2121
class Contest(models.Model):
2222
name = models.CharField(max_length=128, help_text="Contest name")
2323
link = models.URLField(help_text="URL of the contest's website")
24-
description = models.TextField(max_length=512,
25-
help_text="Contest details", null=True)
24+
description = models.TextField(
25+
max_length=512, help_text="Contest details", null=True)
2626
start_date = models.DateField(null=True)
2727
end_date = models.DateField(null=True)
2828
approved = models.BooleanField(default=False)

oshc/main/tests.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66

77

88
class HomeViewTests(TestCase):
9-
109
def test_get_request(self):
1110
response = self.client.get(reverse("home"))
1211
self.assertEqual(response.status_code, 200)
1312

1413

1514
class RequestSessionViewTests(SimpleTestCase):
16-
1715
def test_get_request(self):
1816
response = self.client.get(reverse('request_session'))
1917
self.assertEqual(response.status_code, 200)

oshc/main/views.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def request_session(request):
1616

1717
def contests(request):
1818
contest_list = Contest.objects.all()
19-
return render(request, 'contests.html',
20-
context={'contest_list': contest_list})
19+
return render(
20+
request, 'contests.html', context={
21+
'contest_list': contest_list
22+
})
2123

2224

2325
def contest_new(request):
@@ -42,5 +44,4 @@ def submit_contest(request):
4244

4345
def journey(request):
4446
journey_list = Journey.objects.order_by('start_date')
45-
return render(request, 'journey.html',
46-
context={'Journey': journey_list})
47+
return render(request, 'journey.html', context={'Journey': journey_list})

oshc/oshc/settings.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
ALLOWED_HOSTS = ['*']
2727

2828
# Tuple of people who get error notifications
29-
ADMINS = [
30-
('Tapasweni Pathak', '[email protected]'),
31-
('Nikhita Raghunath', '[email protected]'),
32-
('Ibrahim Jarif', '[email protected]'),
33-
('Amar Prakash Pandey', '[email protected]')
34-
]
29+
ADMINS = [('Tapasweni Pathak', '[email protected]'),
30+
('Nikhita Raghunath', '[email protected]'),
31+
('Ibrahim Jarif',
32+
'[email protected]'), ('Amar Prakash Pandey',
33+
3534

3635
# Application definition
3736

@@ -95,20 +94,24 @@
9594

9695
AUTH_PASSWORD_VALIDATORS = [
9796
{
98-
'NAME': 'django.contrib.auth.password_validation.'
99-
'UserAttributeSimilarityValidator',
97+
'NAME':
98+
'django.contrib.auth.password_validation.'
99+
'UserAttributeSimilarityValidator',
100100
},
101101
{
102-
'NAME': 'django.contrib.auth.password_validation.'
103-
'MinimumLengthValidator',
102+
'NAME':
103+
'django.contrib.auth.password_validation.'
104+
'MinimumLengthValidator',
104105
},
105106
{
106-
'NAME': 'django.contrib.auth.password_validation.'
107-
'CommonPasswordValidator',
107+
'NAME':
108+
'django.contrib.auth.password_validation.'
109+
'CommonPasswordValidator',
108110
},
109111
{
110-
'NAME': 'django.contrib.auth.password_validation.'
111-
'NumericPasswordValidator',
112+
'NAME':
113+
'django.contrib.auth.password_validation.'
114+
'NumericPasswordValidator',
112115
},
113116
]
114117

@@ -154,9 +157,7 @@
154157
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
155158
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
156159

157-
STATICFILES_DIRS = (
158-
os.path.join(BASE_DIR, 'main/'),
159-
)
160+
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'main/'), )
160161

161162
EMAIL_HOST = 'smtp.gmail.com'
162163
EMAIL_HOST_USER = 'email'

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ whitenoise==3.3.1
88
django-allauth==0.33.0
99
django-crispy-forms==1.7.0
1010
flake8==3.4.1
11+
pre-commit==1.4.1

0 commit comments

Comments
 (0)