mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Merge pull request #402 from GSA/notify-api-387
notify-api-387 Scan projects for unused code
This commit is contained in:
2
.github/workflows/checks.yml
vendored
2
.github/workflows/checks.yml
vendored
@@ -46,6 +46,8 @@ jobs:
|
|||||||
run: pipenv run flake8 .
|
run: pipenv run flake8 .
|
||||||
- name: Check imports alphabetized
|
- name: Check imports alphabetized
|
||||||
run: pipenv run isort --check-only ./app ./tests
|
run: pipenv run isort --check-only ./app ./tests
|
||||||
|
- name: Check for dead code
|
||||||
|
run: make dead-code
|
||||||
- name: Run tests with coverage
|
- name: Run tests with coverage
|
||||||
run: pipenv run coverage run --omit=*/notifications_utils/* -m pytest -n4 --maxfail=10
|
run: pipenv run coverage run --omit=*/notifications_utils/* -m pytest -n4 --maxfail=10
|
||||||
env:
|
env:
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -47,6 +47,11 @@ run-celery: ## Run celery, TODO remove purge for staging/prod
|
|||||||
--loglevel=INFO \
|
--loglevel=INFO \
|
||||||
--concurrency=4
|
--concurrency=4
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: dead-code
|
||||||
|
dead-code:
|
||||||
|
pipenv run vulture ./app --min-confidence=100
|
||||||
|
|
||||||
.PHONY: run-celery-beat
|
.PHONY: run-celery-beat
|
||||||
run-celery-beat: ## Run celery beat
|
run-celery-beat: ## Run celery beat
|
||||||
pipenv run celery \
|
pipenv run celery \
|
||||||
|
|||||||
1
Pipfile
1
Pipfile
@@ -62,6 +62,7 @@ gds-metrics = {version = "==0.2.4", ref = "6f1840a57b6fb1ee40b7e84f2f18ec229de8a
|
|||||||
packaging = "==23.1"
|
packaging = "==23.1"
|
||||||
notifications-utils = {editable = true, ref = "main", git = "https://github.com/GSA/notifications-utils.git"}
|
notifications-utils = {editable = true, ref = "main", git = "https://github.com/GSA/notifications-utils.git"}
|
||||||
newrelic = "*"
|
newrelic = "*"
|
||||||
|
vulture = "==2.7"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
exceptiongroup = "==1.1.2"
|
exceptiongroup = "==1.1.2"
|
||||||
|
|||||||
@@ -357,17 +357,17 @@ def setup_sqlalchemy_events(app):
|
|||||||
# need this or db.engine isn't accessible
|
# need this or db.engine isn't accessible
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
@event.listens_for(db.engine, 'connect')
|
@event.listens_for(db.engine, 'connect')
|
||||||
def connect(dbapi_connection, connection_record):
|
def connect(dbapi_connection, connection_record): # noqa
|
||||||
# connection first opened with db
|
# connection first opened with db
|
||||||
TOTAL_DB_CONNECTIONS.inc()
|
TOTAL_DB_CONNECTIONS.inc()
|
||||||
|
|
||||||
@event.listens_for(db.engine, 'close')
|
@event.listens_for(db.engine, 'close')
|
||||||
def close(dbapi_connection, connection_record):
|
def close(dbapi_connection, connection_record): # noqa
|
||||||
# connection closed (probably only happens with overflow connections)
|
# connection closed (probably only happens with overflow connections)
|
||||||
TOTAL_DB_CONNECTIONS.dec()
|
TOTAL_DB_CONNECTIONS.dec()
|
||||||
|
|
||||||
@event.listens_for(db.engine, 'checkout')
|
@event.listens_for(db.engine, 'checkout')
|
||||||
def checkout(dbapi_connection, connection_record, connection_proxy):
|
def checkout(dbapi_connection, connection_record, connection_proxy): # noqa
|
||||||
try:
|
try:
|
||||||
# connection given to a web worker
|
# connection given to a web worker
|
||||||
TOTAL_CHECKED_OUT_DB_CONNECTIONS.inc()
|
TOTAL_CHECKED_OUT_DB_CONNECTIONS.inc()
|
||||||
@@ -405,7 +405,7 @@ def setup_sqlalchemy_events(app):
|
|||||||
current_app.logger.exception("Exception caught for checkout event.")
|
current_app.logger.exception("Exception caught for checkout event.")
|
||||||
|
|
||||||
@event.listens_for(db.engine, 'checkin')
|
@event.listens_for(db.engine, 'checkin')
|
||||||
def checkin(dbapi_connection, connection_record):
|
def checkin(dbapi_connection, connection_record): # noqa
|
||||||
try:
|
try:
|
||||||
# connection returned by a web worker
|
# connection returned by a web worker
|
||||||
TOTAL_CHECKED_OUT_DB_CONNECTIONS.dec()
|
TOTAL_CHECKED_OUT_DB_CONNECTIONS.dec()
|
||||||
|
|||||||
@@ -572,8 +572,9 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
|
|||||||
print(f'update service {service.id} with default')
|
print(f'update service {service.id} with default')
|
||||||
set_default_free_allowance_for_service(service, year)
|
set_default_free_allowance_for_service(service, year)
|
||||||
|
|
||||||
|
# We use noqa to protect this method from the vulture dead code check. Otherwise, the params ctx and param
|
||||||
def validate_mobile(ctx, param, value):
|
# will trigger vulture and cause a build failure.
|
||||||
|
def validate_mobile(ctx, param, value): # noqa
|
||||||
if (len(''.join(i for i in value if i.isdigit())) != 10):
|
if (len(''.join(i for i in value if i.isdigit())) != 10):
|
||||||
raise click.BadParameter("mobile number must have 10 digits")
|
raise click.BadParameter("mobile number must have 10 digits")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user