Skip to content

Commit

Permalink
Revert "Revert "chore: Fix lint (#597)""
Browse files Browse the repository at this point in the history
This reverts commit 3ad1203.
  • Loading branch information
ashwin1111 committed Feb 3, 2025
1 parent 7699a77 commit 8d31bb9
Show file tree
Hide file tree
Showing 151 changed files with 5,268 additions and 3,701 deletions.
113 changes: 113 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[flake8]
extend-ignore =
# Comparison to true should be 'if cond is true:' or 'if cond:'
E712,
# Comparison to None should be 'cond is None:' (E711)
E711,
# Line break occurred before a binary operator (W503)
W503,
# Missing whitespace after ',', ';', or ':' (E231)
E231,
# Line too long (82 > 79 characters) (E501)
E501,
# E251 unexpected spaces around keyword / parameter equals
E251,
# E502 the backslash is redundant between brackets
E502,
# E128 continuation line under-indented for visual indent
E128,
# E125 continuation line with same indent as next logical line
E125,
# E131 continuation line unaligned for hanging indent
E131,
# E129 visually indented line with same indent as next logical line
E129,
# Multiple spaces after ',' (E241)
E241,
# Missing docstring in public package (D104)
D104
# Missing docstring in public module (D100)
D100,
# Missing docstring in public method (D102)
D102,
# Missing docstring in public nested class (D106)
D106,
# Missing Missing docstring in __init__(D107)
D107
# Multi-line docstring summary should start at the first line (D212)
D212,
# First line should end with a period, question mark, or exclamation point
D415
# 1 blank line required between summary line and description
D205,
# One line docstring should fit on one line with quotes
D200
# Missing type annotation for *args
ANN002,
# Missing type annotation for **kwargs
ANN003,
# Missing type annotation for self in method
ANN101,
# Missing type annotation for cls in class method
ANN102,
# Missing return type annotation for special method
ANN204,
# Too complex static method call
C901,





max-line-length = 99
max-complexity = 19
ban-relative-imports = true

# Select additional checks
select = B,C,E,F,N,W,I25,D,ANN,D1

# Docstring convention
docstring-convention = google

# Return type and parameter annotations
# ANN201: Missing return type annotation for public function
# ANN202: Missing return type annotation for private function
# ANN001-ANN003: Missing type annotations for arguments
require-return-type = true
require-parameter-type = true

# Import order and spacing
# I25: Import sorting
# I100: Import statements are in wrong order
# I201: Missing newline between import groups
application-import-names = apps,tests
import-order-style = pep8

# Variable and operator spacing
# E225: Missing whitespace around operator
# E226: Missing whitespace around arithmetic operator
# E251: Unexpected spaces around keyword parameter equals

# Function spacing
# E302: Expected 2 blank lines, found 0
# E303: Too many blank lines
# E305: Expected 2 blank lines after class or function definition

# Unused imports and variables
# F401: Module imported but unused
# F841: Local variable name is assigned to but never used
extend-select =
E225,
E226,
E251,
E302,
E303,
E305,
F401,
F841

# Ignore rules for specific directories (e.g., exclude from 'dir_name' directory)
per-file-ignores =
tests/*: ANN001,ANN201

exclude = *env, *.yml, .flake8, *.txt, *.yaml, gunicorn_config.py, apps/*/migrations/*, manage.py, fyle-integrations-db-migrations/*, fyle_intacct_api/*, create_sql_migration.py, scripts/*
8 changes: 7 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,30 @@ jobs:
run: |
docker compose -f docker-compose-pipeline.yml build
docker compose -f docker-compose-pipeline.yml up -d
docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-fail-under=93 --junit-xml=test-reports/report.xml | tee pytest-coverage.txt
docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --cov-report=xml --cov-report=term-missing --cov-fail-under=93 --junit-xml=test-reports/report.xml | tee pytest-coverage.txt
echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV
echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV
env:
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3

- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
if: ${{ always() && github.ref != 'refs/heads/master' }}
with:
create-new-comment: true
junitxml-path: ./test-reports/report.xml
pytest-coverage-path: ./pytest-coverage.txt

- name: Stop Services
run: docker compose -f docker-compose-pipeline.yml down

- name: Evaluate Coverage
if: ${{ (env.STATUS == 'FAIL') || (env.FAILED > 0) }}
run: exit 1

- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: ${{ always() && github.ref != 'refs/heads/master' }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ COPY . /fyle-intacct-api/
WORKDIR /fyle-intacct-api

# Do linting checks
RUN pylint --load-plugins pylint_django --rcfile=.pylintrc apps/**.py
RUN flake8 .

# Expose development port
EXPOSE 8000
Expand Down
14 changes: 9 additions & 5 deletions apps/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging

from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError
from fyle.platform.exceptions import NoPrivilegeError
from rest_framework.response import Response
from rest_framework.views import status
from rest_framework.exceptions import ValidationError

from fyle.platform.exceptions import NoPrivilegeError
from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError

from apps.fyle.models import ExpenseGroup
from apps.mappings.models import GeneralMapping
from apps.workspaces.models import FyleCredential, SageIntacctCredential, Workspace, Configuration
Expand All @@ -14,9 +15,12 @@
logger.level = logging.INFO


def handle_view_exceptions():
def decorator(func):
def new_fn(*args, **kwargs):
def handle_view_exceptions() -> callable:
"""
Decorator to handle exceptions in views
"""
def decorator(func: callable) -> callable:
def new_fn(*args, **kwargs) -> callable:
try:
return func(*args, **kwargs)
except ExpenseGroup.DoesNotExist:
Expand Down
31 changes: 14 additions & 17 deletions apps/fyle/actions.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
from datetime import datetime, timezone
from typing import List
import logging

from django.conf import settings
from django.db.models import Q

from fyle_integrations_platform_connector import PlatformConnector
from fyle.platform.internals.decorators import retry
from fyle_integrations_platform_connector import PlatformConnector
from fyle.platform.exceptions import InternalServerError, RetryException
from fyle_accounting_mappings.models import ExpenseAttribute

from apps.fyle.constants import DEFAULT_FYLE_CONDITIONS
from apps.fyle.models import ExpenseGroup, Expense
from apps.workspaces.models import FyleCredential, Workspace

from .helpers import get_updated_accounting_export_summary, get_batched_expenses
from apps.fyle.models import Expense
from apps.workspaces.models import Workspace

from apps.fyle.helpers import get_updated_accounting_export_summary, get_batched_expenses

logger = logging.getLogger(__name__)
logger.level = logging.INFO


def __bulk_update_expenses(expense_to_be_updated: List[Expense]) -> None:
def __bulk_update_expenses(expense_to_be_updated: list[Expense]) -> None:
"""
Bulk update expenses
:param expense_to_be_updated: expenses to be updated
Expand All @@ -31,7 +26,7 @@ def __bulk_update_expenses(expense_to_be_updated: List[Expense]) -> None:
Expense.objects.bulk_update(expense_to_be_updated, ['is_skipped', 'accounting_export_summary'], batch_size=50)


def update_expenses_in_progress(in_progress_expenses: List[Expense]) -> None:
def update_expenses_in_progress(in_progress_expenses: list[Expense]) -> None:
"""
Update expenses in progress in bulk
:param in_progress_expenses: in progress expenses
Expand All @@ -55,7 +50,7 @@ def update_expenses_in_progress(in_progress_expenses: List[Expense]) -> None:
__bulk_update_expenses(expense_to_be_updated)


def mark_expenses_as_skipped(final_query: Q, expenses_object_ids: List, workspace: Workspace) -> None:
def mark_expenses_as_skipped(final_query: Q, expenses_object_ids: list, workspace: Workspace) -> None:
"""
Mark expenses as skipped in bulk
:param final_query: final query
Expand Down Expand Up @@ -90,7 +85,7 @@ def mark_expenses_as_skipped(final_query: Q, expenses_object_ids: List, workspac
__bulk_update_expenses(expense_to_be_updated)


def mark_accounting_export_summary_as_synced(expenses: List[Expense]) -> None:
def mark_accounting_export_summary_as_synced(expenses: list[Expense]) -> None:
"""
Mark accounting export summary as synced in bulk
:param expenses: List of expenses
Expand All @@ -112,10 +107,12 @@ def mark_accounting_export_summary_as_synced(expenses: List[Expense]) -> None:
Expense.objects.bulk_update(expense_to_be_updated, ['accounting_export_summary', 'previous_export_state'], batch_size=50)


def update_failed_expenses(failed_expenses: List[Expense], is_mapping_error: bool) -> None:
def update_failed_expenses(failed_expenses: list[Expense], is_mapping_error: bool) -> None:
"""
Update failed expenses
:param failed_expenses: Failed expenses
:param is_mapping_error: Is mapping error
:return: None
"""
expense_to_be_updated = []
for expense in failed_expenses:
Expand All @@ -140,7 +137,7 @@ def update_failed_expenses(failed_expenses: List[Expense], is_mapping_error: boo
__bulk_update_expenses(expense_to_be_updated)


def update_complete_expenses(exported_expenses: List[Expense], url: str) -> None:
def update_complete_expenses(exported_expenses: list[Expense], url: str) -> None:
"""
Update complete expenses
:param exported_expenses: Exported expenses
Expand Down Expand Up @@ -201,7 +198,7 @@ def __handle_post_accounting_export_summary_exception(exception: Exception, work


@retry(n=3, backoff=1, exceptions=InternalServerError)
def bulk_post_accounting_export_summary(platform: PlatformConnector, payload: List[dict]):
def bulk_post_accounting_export_summary(platform: PlatformConnector, payload: list[dict]) -> None:
"""
Bulk post accounting export summary with retry of 3 times and backoff of 1 second which handles InternalServerError
:param platform: Platform connector object
Expand All @@ -211,7 +208,7 @@ def bulk_post_accounting_export_summary(platform: PlatformConnector, payload: Li
platform.expenses.post_bulk_accounting_export_summary(payload)


def create_generator_and_post_in_batches(accounting_export_summary_batches: List[dict], platform: PlatformConnector, workspace_id: int) -> None:
def create_generator_and_post_in_batches(accounting_export_summary_batches: list[dict], platform: PlatformConnector, workspace_id: int) -> None:
"""
Create generator and post in batches
:param accounting_export_summary_batches: Accounting export summary batches
Expand Down
1 change: 0 additions & 1 deletion apps/fyle/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@

from .models import ExpenseGroup, Expense


admin.site.register(ExpenseGroup)
admin.site.register(Expense)
7 changes: 5 additions & 2 deletions apps/fyle/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@


class FyleConfig(AppConfig):
"""
Fyle app config
"""
name = 'apps.fyle'

def ready(self):
def ready(self) -> None:
super(FyleConfig, self).ready()
import apps.fyle.signals
import apps.fyle.signals # noqa
Loading

0 comments on commit 8d31bb9

Please sign in to comment.