Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Add black, isort and pre-commit hook #6787

Merged
merged 4 commits into from Jan 24, 2020

Conversation

iamareebjamal
Copy link
Member

@iamareebjamal iamareebjamal commented Jan 24, 2020

  • Add isort for sorting imports
  • Add black for formatting
  • Add pre-commit hooks for standard checks

Fixes #6766

tests/hook_main.py Outdated Show resolved Hide resolved
tests/hook_main.py Outdated Show resolved Hide resolved
from app.factories.attendee import AttendeeFactoryBase, AttendeeFactory
from app.api.attendees import get_sold_and_reserved_tickets_count
from app.api.helpers.db import save_to_db
from app.api.helpers.order import delete_related_attendees_for_order, set_expiry_for_order

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

populate_db.py Outdated Show resolved Hide resolved
app/models/user.py Outdated Show resolved Hide resolved
app/api/orders.py Outdated Show resolved Hide resolved
app/api/users.py Outdated Show resolved Hide resolved
app/api/user_favourite_events.py Outdated Show resolved Hide resolved
app/api/tickets.py Outdated Show resolved Hide resolved
app/api/tickets.py Outdated Show resolved Hide resolved
)
from app.api.event_topics import EventTopicDetail, EventTopicList, EventTopicRelationship
from app.api.event_types import EventTypeDetail, EventTypeList, EventTypeRelationship
from app.api.events import EventCopyResource, EventDetail, EventList, EventRelationship

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'app.api.events.EventCopyResource' imported but unused

EventSubTopicRelationshipOptional,
EventSubTopicRelationshipRequired,
)
from app.api.event_topics import EventTopicDetail, EventTopicList, EventTopicRelationship

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

app/api/modules.py Outdated Show resolved Hide resolved
)
from app.api.helpers.ICalExporter import ICalExporter
from app.api.helpers.mail import check_smtp_config, send_export_mail, send_import_mail
from app.api.helpers.notification import send_notif_after_export, send_notif_after_import

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

app/api/helpers/tasks.py Outdated Show resolved Hide resolved
app/api/helpers/scheduled_jobs.py Outdated Show resolved Hide resolved
app/api/events.py Outdated Show resolved Hide resolved
from flask_jwt_extended import current_user
from sqlalchemy.orm.exc import NoResultFound

from app.api.helpers.errors import ForbiddenError, NotFoundError, UnprocessableEntityError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

app/api/attendees.py Outdated Show resolved Hide resolved
from app.api.auth import return_file
from app.api.helpers.db import safe_query, get_count
from app.api.helpers.db import get_count, safe_query
from app.api.helpers.errors import ForbiddenError, NotFoundError, UnprocessableEntityError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@codecov
Copy link

codecov bot commented Jan 24, 2020

Codecov Report

Merging #6787 into development will decrease coverage by 0.06%.
The diff coverage is 57.93%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #6787      +/-   ##
===============================================
- Coverage        65.38%   65.31%   -0.07%     
===============================================
  Files              302      302              
  Lines            15348    15319      -29     
===============================================
- Hits             10035    10006      -29     
  Misses            5313     5313
Impacted Files Coverage Δ
app/models/base.py 100% <ø> (ø) ⬆️
app/models/track.py 67.64% <ø> (ø) ⬆️
app/factories/event_invoice.py 100% <ø> (ø) ⬆️
app/factories/track.py 100% <ø> (ø) ⬆️
app/factories/session.py 100% <ø> (ø) ⬆️
app/api/admin_sales/utils.py 40% <ø> (ø) ⬆️
app/factories/speaker.py 100% <ø> (ø) ⬆️
app/models/page.py 60% <ø> (ø) ⬆️
app/api/schema/modules.py 100% <ø> (ø) ⬆️
app/api/settings.py 63.04% <ø> (+0.82%) ⬆️
... and 368 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9791fb7...14b73ff. Read the comment docs.

@@ -4057,7 +4223,9 @@ def order_statistics_event_get(transaction):
db.session.commit()


@hooks.before("Order Statistics > Order Statistics Details By Ticket > Show Order Statistics By Ticket")
@hooks.before(
"Order Statistics > Order Statistics Details By Ticket > Show Order Statistics By Ticket"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (93 > 90 characters)

@hooks.before("Order Statistics > Order Statistics Details By Event > Show Order Statistics By Event")

@hooks.before(
"Order Statistics > Order Statistics Details By Event > Show Order Statistics By Event"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 90 characters)

@@ -3992,7 +4153,8 @@ def event_sessions_export_pdf_get(transaction):


@hooks.before(
"Event Export > Start Speakers Export as PDF > Start a Task to Export Speakers of an Event as PDF")
"Event Export > Start Speakers Export as PDF > Start a Task to Export Speakers of an Event as PDF"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (102 > 90 characters)

@@ -3979,7 +4139,8 @@ def event_speakers_export_csv_get(transaction):


@hooks.before(
"Event Export > Start Sessions Export as PDF > Start a Task to Export Sessions of an Event as PDF")
"Event Export > Start Sessions Export as PDF > Start a Task to Export Sessions of an Event as PDF"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (102 > 90 characters)

@@ -3966,7 +4125,8 @@ def event_sessions_export_csv_get(transaction):


@hooks.before(
"Event Export > Start Speakers Export as CSV > Start a Task to Export Speakers of an Event as CSV")
"Event Export > Start Speakers Export as CSV > Start a Task to Export Speakers of an Event as CSV"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (102 > 90 characters)

@@ -3875,7 +4027,8 @@ def event_export_ical_get(transaction):


@hooks.before(
"Event Export > Start Event Export as xCalendar > Start a Task to Export an Event as xCalendar")
"Event Export > Start Event Export as xCalendar > Start a Task to Export an Event as xCalendar"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (99 > 90 characters)

@@ -3862,7 +4013,8 @@ def event_export_post(transaction):


@hooks.before(
"Event Export > Start Event Export as iCal file > Start a Task to Export an Event as iCal event")
"Event Export > Start Event Export as iCal file > Start a Task to Export an Event as iCal event"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (100 > 90 characters)

@@ -3834,7 +3982,9 @@ def stripe_authorization_delete(transaction):
db.session.commit()


@hooks.before("Stripe Authorization > Stripe Authorization for an Event > Get Stripe Authorization Details of an Event")
@hooks.before(
"Stripe Authorization > Stripe Authorization for an Event > Get Stripe Authorization Details of an Event"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (109 > 90 characters)

@@ -3648,7 +3777,9 @@ def custom_placeholder_sub_topic_get_detail(transaction):


# ------------------------- Custom Placeholders -------------------------
@hooks.before("Custom Placeholders > Custom Placeholders Collection > List All Event Custom Placeholders")
@hooks.before(
"Custom Placeholders > Custom Placeholders Collection > List All Event Custom Placeholders"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (95 > 90 characters)

@@ -3631,7 +3759,8 @@ def event_event_sub_topic_get_detail(transaction):


@hooks.before(
"Event Sub Topics > Event Sub Topic of Custom Placeholder > Event Sub Topic Details of Custom Placeholder")
"Event Sub Topics > Event Sub Topic of Custom Placeholder > Event Sub Topic Details of Custom Placeholder"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (110 > 90 characters)

@iamareebjamal iamareebjamal changed the title ref: Sort imports using isort ref: Add black, isort and pre-commit hook Jan 24, 2020
@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 47
- Added 12
           

Clones added
============
- app/api/admin_statistics_api/sessions.py  1
- app/api/admin_statistics_api/mails.py  1
- app/api/speakers.py  1
- app/api/order_statistics/events.py  5
- app/api/attendees.py  3
- app/api/tax.py  1
- app/api/sessions.py  1
- app/api/access_codes.py  1
- app/api/order_statistics/tickets.py  6
- app/api/admin_statistics_api/users.py  1
- app/api/tickets.py  1
- app/api/orders.py  2
- app/models/discount_code.py  1
- app/api/admin_sales/events.py  1
- app/models/access_code.py  1
- app/api/admin_sales/organizer.py  1
         

Clones removed
==============
+ app/models/event_sub_topic.py  -1
+ app/models/event_type.py  -1
+ tests/all/integration/api/helpers/test_systemnotifications.py  -1
         

See the complete overview on Codacy

@@ -613,21 +840,34 @@ def omise_checkout(order_identifier):
try:
charge = OmisePaymentsManager.charge_payment(order_identifier, token)
except omise.errors.BaseError as e:
logging.exception(f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors""")
logging.exception(
f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: invalid syntax

)
max = (
db.session.query(func.sum(Ticket.quantity.label('sum')))
.filter(Ticket.event_id == obj_id, Ticket.deleted_at == None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'DiscountCode', secondary=discount_codes_tickets, backref="tickets"
)

def __init__(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: as argument

TicketHolder.created_at + datetime.timedelta(minutes=order_expiry_time)
< datetime.datetime.utcnow()).delete(synchronize_session=False)
TicketHolder.query.filter(
TicketHolder.order_id == None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speakers = Speaker.query.filter(
Speaker.photo_url.isnot(None),
or_(
Speaker.icon_image_url == None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys.path.insert(1, path.abspath(path.join(__file__, "../..")))

from flask_migrate import Migrate
from flask import Flask
from app.models import db
from app.models.user import OWNER
from app.models.user_token_blacklist import UserTokenBlackListTime # noqa Workaround for registering unimported model
from app.models.user_token_blacklist import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -386,8 +388,9 @@ def import_event_json(task_handle, zip_path, creator_id):
except ValueError:
db.session.delete(new_event)
db.session.commit()
raise make_error(item[0], er=ServerError(source='Zip Upload',
detail='Invalid json'))
raise make_error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events = Event.query.filter(
Event.original_image_url.isnot(None),
or_(
Event.thumbnail_image_url == None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
from app.api.event_topics import EventTopicDetail, EventTopicList, EventTopicRelationship
from app.api.event_types import EventTypeDetail, EventTypeList, EventTypeRelationship
from app.api.events import EventCopyResource, EventDetail, EventList, EventRelationship
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.logger.warning(f'Using random secret "{ random_secret }" for development server. '
'This is NOT recommended. Set proper SECRET_KEY in .env or environment variables')
app.logger.warning(
f'Using random secret "{ random_secret }" for development server. '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: invalid syntax

attendee_list = []
for ticket in tickets:
for ticket_amount in range(ticket['quantity']):
attendee = TicketHolder(**result[0], event_id=int(data['event_id']), ticket_id=int(ticket['id']))
attendee = TicketHolder(
**result[0], event_id=int(data['event_id']), ticket_id=int(ticket['id'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: invalid syntax

)
from app.api.event_topics import EventTopicDetail, EventTopicList, EventTopicRelationship
from app.api.event_types import EventTypeDetail, EventTypeList, EventTypeRelationship
from app.api.events import EventCopyResource, EventDetail, EventList, EventRelationship
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal iamareebjamal merged commit b7ed60b into fossasia:development Jan 24, 2020
@iamareebjamal iamareebjamal deleted the isort branch January 24, 2020 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add black for formatting
3 participants