diff --git a/.github/workflows/black.yml b/.github/workflows/ruff.yml similarity index 64% rename from .github/workflows/black.yml rename to .github/workflows/ruff.yml index d8ffb339..181ecfdf 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/ruff.yml @@ -1,4 +1,4 @@ -name: Black Formatter +name: Ruff Lint Check on: pull_request: @@ -6,8 +6,8 @@ on: - "**.py" jobs: - lint: + ruff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: psf/black@stable + - uses: astral-sh/ruff-action@v3 diff --git a/labconnect/errors/__init__.py b/labconnect/errors/__init__.py index 049285a0..7323fbe8 100644 --- a/labconnect/errors/__init__.py +++ b/labconnect/errors/__init__.py @@ -6,4 +6,4 @@ error_blueprint = Blueprint("errors", __name__, template_folder="templates") -from . import routes +from . import routes # noqa diff --git a/labconnect/errors/routes.py b/labconnect/errors/routes.py index 733dd43b..f1bfc409 100644 --- a/labconnect/errors/routes.py +++ b/labconnect/errors/routes.py @@ -1,4 +1,4 @@ -from flask import Response, make_response, render_template +from flask import Response, make_response from . import error_blueprint diff --git a/labconnect/helpers.py b/labconnect/helpers.py index 57467631..a39a15da 100644 --- a/labconnect/helpers.py +++ b/labconnect/helpers.py @@ -1,4 +1,3 @@ -import json from enum import Enum as EnumPython import orjson diff --git a/labconnect/main/__init__.py b/labconnect/main/__init__.py index 262d5d8d..13613c97 100644 --- a/labconnect/main/__init__.py +++ b/labconnect/main/__init__.py @@ -6,4 +6,4 @@ main_blueprint = Blueprint("main", __name__) -from . import auth_routes, discover_routes, opportunity_routes, routes +from . import auth_routes, discover_routes, opportunity_routes, routes # noqa diff --git a/labconnect/main/discover_routes.py b/labconnect/main/discover_routes.py index 06b82880..116e0cff 100644 --- a/labconnect/main/discover_routes.py +++ b/labconnect/main/discover_routes.py @@ -1,5 +1,3 @@ -from flask_jwt_extended import get_jwt_identity, jwt_required - from labconnect import db from labconnect.models import ( ClassYears, @@ -35,7 +33,7 @@ def discover_data(jwt_identity, limit): Opportunities.location, LabManager.id.label("lab_manager_id"), ) - .where(Opportunities.active == True) + .where(Opportunities.active) .join( RecommendsClassYears, Opportunities.id == RecommendsClassYears.class_year, @@ -61,7 +59,7 @@ def discover_data(jwt_identity, limit): if jwt_identity is None or data is None: data = db.session.execute( db.select(Opportunities) - .where(Opportunities.active == True) + .where(Opportunities.active) .limit(limit) .order_by(Opportunities.last_updated.desc()) ).scalars() diff --git a/labconnect/main/opportunity_routes.py b/labconnect/main/opportunity_routes.py index 3fa48c11..090e2944 100644 --- a/labconnect/main/opportunity_routes.py +++ b/labconnect/main/opportunity_routes.py @@ -171,7 +171,6 @@ def packageIndividualOpportunity(opportunityInfo): def packageOpportunityCard(opportunity): - # get professor and department by getting Leads and LabManager query = db.session.execute( db.select(Leads, LabManager, User.first_name, User.last_name) @@ -232,7 +231,7 @@ def getOpportunities(): # Handle GET requests for fetching default active opportunities data = db.session.execute( db.select(Opportunities) - .where(Opportunities.active == True) + .where(Opportunities.active) .limit(20) .order_by(Opportunities.last_updated.desc()) .distinct() @@ -263,7 +262,7 @@ def filterOpportunities(): where_conditions = [] query = ( db.select(Opportunities) - .where(Opportunities.active == True) + .where(Opportunities.active) .limit(20) .order_by(Opportunities.last_updated) .distinct() @@ -462,9 +461,7 @@ def filterOpportunities(): @main_blueprint.get("/getOpportunityCards") def getOpportunityCards(): # query database for opportunity - query = db.session.execute( - db.select(Opportunities).where(Opportunities.active == True) - ) + query = db.session.execute(db.select(Opportunities).where(Opportunities.active)) data = query.fetchall() # return data in the below format if opportunity is found @@ -497,7 +494,6 @@ def getOpportunityCards(): @main_blueprint.get("/staff/opportunities/") def getLabManagerOpportunityCards(rcs_id: str) -> list[dict[str, str]]: - query = ( db.select( Opportunities.id, @@ -534,7 +530,6 @@ def getLabManagerOpportunityCards(rcs_id: str) -> list[dict[str, str]]: @main_blueprint.get("/profile/opportunities/") def getProfileOpportunities(rcs_id: str) -> list[dict[str, str]]: - query = ( db.select( Opportunities.id, @@ -661,7 +656,7 @@ def createOpportunity(): try: pay = int(request_data["hourlyPay"]) - except: + except ValueError: pay = None one = True if "1" in request_data["credits"] else False @@ -769,7 +764,9 @@ def editOpportunity_get(opportunity_id): "type": ( "Any" if len(credits) > 0 and opportunity.pay and opportunity.pay > 0 - else "For Pay" if opportunity.pay and opportunity.pay > 0 else "For Credit" + else "For Pay" + if opportunity.pay and opportunity.pay > 0 + else "For Credit" ), "hourlyPay": str(opportunity.pay), "credits": credits, @@ -791,7 +788,6 @@ def editOpportunity_get(opportunity_id): @main_blueprint.put("/editOpportunity/") @jwt_required() def editOpportunity(opportunity_id): - user_id = get_jwt_identity() if not request.data or not user_id: abort(400) @@ -827,7 +823,7 @@ def editOpportunity(opportunity_id): try: pay = int(request_data["hourlyPay"]) - except: + except ValueError: pay = None one = True if "1" in request_data["credits"] else False @@ -889,14 +885,14 @@ def editOpportunity(opportunity_id): db.session.commit() # Add the updated list of managers - if "lab_manager_ids" in data: - for lab_manager_id in data["lab_manager_ids"]: - new_lead = Leads( - lab_manager_id=lab_manager_id, opportunity_id=opportunity_id - ) - db.session.add(new_lead) - - db.session.commit() # Commit all changes + # if "lab_manager_ids" in data: + # for lab_manager_id in data["lab_manager_ids"]: + # new_lead = Leads( + # lab_manager_id=lab_manager_id, opportunity_id=opportunity_id + # ) + # db.session.add(new_lead) + + # db.session.commit() # Commit all changes return {"data": "Opportunity Updated"}, 200 diff --git a/labconnect/main/routes.py b/labconnect/main/routes.py index 7c68809b..d216cbb8 100644 --- a/labconnect/main/routes.py +++ b/labconnect/main/routes.py @@ -41,7 +41,6 @@ def departmentCards(): @main_blueprint.get("/departments/") def departmentDetails(department: str): - department_data = db.session.execute( db.select( RPIDepartments.id, @@ -92,7 +91,6 @@ def departmentDetails(department: str): @main_blueprint.get("/profile") @jwt_required() def profile(): - user_id = get_jwt_identity() data = db.session.execute( @@ -133,7 +131,6 @@ def profile(): @main_blueprint.get("/staff/") @jwt_required() def getProfessorProfile(id: str): - data = db.session.execute( db.select( User.preferred_name, @@ -208,7 +205,6 @@ def force_error(): @main_blueprint.get("/majors") def majors() -> list[dict[str, str]]: - data = db.session.execute(db.select(Majors).order_by(Majors.code)).scalars() if not data: @@ -224,11 +220,8 @@ def majors() -> list[dict[str, str]]: @main_blueprint.get("/years") def years() -> list[int]: - data = db.session.execute( - db.select(ClassYears) - .order_by(ClassYears.class_year) - .where(ClassYears.active == True) + db.select(ClassYears).order_by(ClassYears.class_year).where(ClassYears.active) ).scalars() if not data: diff --git a/labconnect/models.py b/labconnect/models.py index 513259dc..7fa9a00f 100644 --- a/labconnect/models.py +++ b/labconnect/models.py @@ -1,4 +1,3 @@ -from atexit import register from sqlalchemy import Enum, Index, event, func from sqlalchemy.dialects.postgresql import TSVECTOR diff --git a/requirements.txt b/requirements.txt index a6866749..253bfce0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,6 +26,7 @@ pytest==8.3.4 pytest-cov==6.0.0 python3-saml==1.16.0 pytz==2024.2 +ruff==0.9.5 sentry-sdk==2.19.2 setuptools==70.3.0 six==1.17.0 diff --git a/tests/conftest.py b/tests/conftest.py index c5b9c959..403ec2fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,6 @@ import pytest from labconnect import create_app -from labconnect.models import * # -------- # Fixtures