Skip to content

Commit

Permalink
Merge pull request #550 from UW-GAC/maint/use-ruff
Browse files Browse the repository at this point in the history
Switch to ruff
  • Loading branch information
amstilp authored Apr 30, 2024
2 parents 4ae379d + 3dfbbc6 commit cad7dfb
Show file tree
Hide file tree
Showing 98 changed files with 1,677 additions and 4,887 deletions.
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ repos:
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.2
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ['--config=setup.cfg']
additional_dependencies: [flake8-isort]
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
Expand Down
20 changes: 20 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
line-length = 120
exclude = [
"**/migrations/**",
"*/static/CACHE/*",
"venv",
"docs",
]

[lint]
extend-select = [
"E",
"F",
"W", # pycodestyle warnings
"I", # isort
"DJ", # flake8-django
"E501", # line-too-long
]

[lint.isort]
known-first-party = ["primed", "config", ]
44 changes: 11 additions & 33 deletions add_cdsa_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@
major_version = factories.AgreementMajorVersionFactory.create(version=1)

# Create some agreement versions
v10 = factories.AgreementVersionFactory.create(
major_version=major_version, minor_version=0
)
v11 = factories.AgreementVersionFactory.create(
major_version=major_version, minor_version=1
)
v10 = factories.AgreementVersionFactory.create(major_version=major_version, minor_version=0)
v11 = factories.AgreementVersionFactory.create(major_version=major_version, minor_version=1)

# Create a couple signed CDSAs.
dup = DataUsePermission.objects.get(abbreviation="GRU")
Expand All @@ -57,9 +53,7 @@
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CC"),
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1001.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1001.signed_agreement.anvil_access_group)

cdsa_1002 = factories.MemberAgreementFactory.create(
signed_agreement__cc_id=1002,
Expand All @@ -70,9 +64,7 @@
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1002.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1002.signed_agreement.anvil_access_group)

cdsa_1003 = factories.MemberAgreementFactory.create(
signed_agreement__cc_id=1003,
Expand All @@ -83,9 +75,7 @@
signed_agreement__version=v10,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1003.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1003.signed_agreement.anvil_access_group)

cdsa_1004 = factories.MemberAgreementFactory.create(
signed_agreement__cc_id=1004,
Expand All @@ -96,9 +86,7 @@
signed_agreement__version=v11,
study_site=StudySite.objects.get(short_name="CARDINAL"),
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1004.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1004.signed_agreement.anvil_access_group)

cdsa_1005 = factories.DataAffiliateAgreementFactory.create(
signed_agreement__cc_id=1005,
Expand All @@ -108,9 +96,7 @@
study=Study.objects.get(short_name="Amish"),
signed_agreement__version=v10,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1005.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1005.signed_agreement.anvil_access_group)

cdsa_1006 = factories.DataAffiliateAgreementFactory.create(
signed_agreement__cc_id=1006,
Expand All @@ -122,9 +108,7 @@
additional_limitations="This data can only be used for testing the app.",
requires_study_review=True,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1006.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1006.signed_agreement.anvil_access_group)

cdsa_1007 = factories.DataAffiliateAgreementFactory.create(
signed_agreement__cc_id=1007,
Expand All @@ -135,9 +119,7 @@
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1007.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1007.signed_agreement.anvil_access_group)

cdsa_1008 = factories.DataAffiliateAgreementFactory.create(
signed_agreement__cc_id=1008,
Expand All @@ -148,9 +130,7 @@
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1008.signed_agreement.anvil_access_group
)
GroupGroupMembershipFactory.create(parent_group=cdsa_group, child_group=cdsa_1008.signed_agreement.anvil_access_group)

cdsa_1009 = factories.NonDataAffiliateAgreementFactory.create(
signed_agreement__cc_id=1009,
Expand Down Expand Up @@ -236,8 +216,6 @@
cdsa_workspace_3 = factories.CDSAWorkspaceFactory.create(
workspace__billing_project__name="demo-primed-cdsa",
workspace__name="DEMO_PRIMED_CDSA_ARIC_1",
study=Study.objects.create(
short_name="ARIC", full_name="Atherosclerosis Risk in Communities"
),
study=Study.objects.create(short_name="ARIC", full_name="Atherosclerosis Risk in Communities"),
data_use_permission=dup,
)
32 changes: 8 additions & 24 deletions add_collaborative_analysis_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,15 @@


# Add accounts to the auth domains.
account_1 = AccountFactory.create(
user__name="Adrienne", verified=True, email="[email protected]"
)
account_2 = AccountFactory.create(
user__name="Ben", verified=True, email="[email protected]"
)
account_3 = AccountFactory.create(
user__name="Matt", verified=True, email="[email protected]"
)
account_4 = AccountFactory.create(
user__name="Stephanie", verified=True, email="[email protected]"
)
account_1 = AccountFactory.create(user__name="Adrienne", verified=True, email="[email protected]")
account_2 = AccountFactory.create(user__name="Ben", verified=True, email="[email protected]")
account_3 = AccountFactory.create(user__name="Matt", verified=True, email="[email protected]")
account_4 = AccountFactory.create(user__name="Stephanie", verified=True, email="[email protected]")

# Set up collab analysis workspace one
# analyst group
GroupAccountMembershipFactory.create(
account=account_1, group=collaborative_analysis_workspace_1.analyst_group
)
GroupAccountMembershipFactory.create(
account=account_2, group=collaborative_analysis_workspace_1.analyst_group
)
GroupAccountMembershipFactory.create(account=account_1, group=collaborative_analysis_workspace_1.analyst_group)
GroupAccountMembershipFactory.create(account=account_2, group=collaborative_analysis_workspace_1.analyst_group)
# auth domains
GroupAccountMembershipFactory.create(
account=account_1,
Expand All @@ -84,12 +72,8 @@

# Set up collab analysis workspace two
# analyst group
GroupAccountMembershipFactory.create(
account=account_3, group=collaborative_analysis_workspace_2.analyst_group
)
GroupAccountMembershipFactory.create(
account=account_4, group=collaborative_analysis_workspace_2.analyst_group
)
GroupAccountMembershipFactory.create(account=account_3, group=collaborative_analysis_workspace_2.analyst_group)
GroupAccountMembershipFactory.create(account=account_4, group=collaborative_analysis_workspace_2.analyst_group)
# auth domains
GroupAccountMembershipFactory.create(
account=account_3,
Expand Down
28 changes: 7 additions & 21 deletions add_dbgap_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@

# Studies
fhs = StudyFactory.create(short_name="FHS", full_name="Framingham Heart Study")
mesa = StudyFactory.create(
short_name="MESA", full_name="Multi-Ethnic Study of Atherosclerosis"
)
aric = StudyFactory.create(
short_name="ARIC", full_name="Atherosclerosis Risk in Communities"
)
mesa = StudyFactory.create(short_name="MESA", full_name="Multi-Ethnic Study of Atherosclerosis")
aric = StudyFactory.create(short_name="ARIC", full_name="Atherosclerosis Risk in Communities")

# dbGaP study accessions
dbgap_study_accession_fhs = factories.dbGaPStudyAccessionFactory.create(
dbgap_phs=7, studies=[fhs]
)
dbgap_study_accession_mesa = factories.dbGaPStudyAccessionFactory.create(
dbgap_phs=209, studies=[mesa]
)
dbgap_study_accession_aric = factories.dbGaPStudyAccessionFactory.create(
dbgap_phs=280, studies=[aric]
)
dbgap_study_accession_fhs = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=7, studies=[fhs])
dbgap_study_accession_mesa = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=209, studies=[mesa])
dbgap_study_accession_aric = factories.dbGaPStudyAccessionFactory.create(dbgap_phs=280, studies=[aric])


# Create some dbGaP workspaces.
Expand Down Expand Up @@ -78,9 +68,7 @@
dbgap_project_id=33119,
)
# Add a snapshot
dar_snapshot_1 = factories.dbGaPDataAccessSnapshotFactory.create(
dbgap_application=dbgap_application_1
)
dar_snapshot_1 = factories.dbGaPDataAccessSnapshotFactory.create(dbgap_application=dbgap_application_1)
# Add some data access requests.
dar_1_1 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_1,
Expand Down Expand Up @@ -112,9 +100,7 @@
dbgap_project_id=33371,
)
# Add a snapshot
dar_snapshot_2 = factories.dbGaPDataAccessSnapshotFactory.create(
dbgap_application=dbgap_application_2
)
dar_snapshot_2 = factories.dbGaPDataAccessSnapshotFactory.create(dbgap_application=dbgap_application_2)
# Add some data access requests, only for FHS.
dar_1_1 = factories.dbGaPDataAccessRequestForWorkspaceFactory.create(
dbgap_workspace=workspace_fhs_1,
Expand Down
12 changes: 3 additions & 9 deletions add_phenotype_inventory_input_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@

# Share workspaces with PRIMED_ALL
primed_all = ManagedGroupFactory.create(name="PRIMED_ALL")
WorkspaceGroupSharingFactory.create(
workspace=workspace_dbgap.workspace, group=primed_all
)
WorkspaceGroupSharingFactory.create(
workspace=workspace_cdsa.workspace, group=primed_all
)
WorkspaceGroupSharingFactory.create(
workspace=workspace_open_access.workspace, group=primed_all
)
WorkspaceGroupSharingFactory.create(workspace=workspace_dbgap.workspace, group=primed_all)
WorkspaceGroupSharingFactory.create(workspace=workspace_cdsa.workspace, group=primed_all)
WorkspaceGroupSharingFactory.create(workspace=workspace_open_access.workspace, group=primed_all)
20 changes: 5 additions & 15 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base settings to build other settings files upon.
"""

from pathlib import Path

import environ
Expand Down Expand Up @@ -135,9 +136,7 @@
]
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
Expand Down Expand Up @@ -264,12 +263,7 @@
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"formatters": {"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(process)d %(thread)d %(message)s"}},
"handlers": {
"console": {
"level": "DEBUG",
Expand Down Expand Up @@ -407,9 +401,5 @@
DRUPAL_API_CLIENT_ID = env("DRUPAL_API_CLIENT_ID", default="")
DRUPAL_API_CLIENT_SECRET = env("DRUPAL_API_CLIENT_SECRET", default="")
DRUPAL_API_REL_PATH = env("DRUPAL_API_REL_PATH", default="mockapi")
DRUPAL_DATA_AUDIT_DEACTIVATE_USERS = env(
"DRUPAL_DATA_AUDIT_DEACTIVATE_USERS", default=False
)
DRUPAL_DATA_AUDIT_REMOVE_USER_SITES = env(
"DRUPAL_DATA_AUDIT_REMOVE_USER_SITES", default=False
)
DRUPAL_DATA_AUDIT_DEACTIVATE_USERS = env("DRUPAL_DATA_AUDIT_DEACTIVATE_USERS", default=False)
DRUPAL_DATA_AUDIT_REMOVE_USER_SITES = env("DRUPAL_DATA_AUDIT_REMOVE_USER_SITES", default=False)
12 changes: 3 additions & 9 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env(
"DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend"
)
EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")

# WhiteNoise
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -73,10 +71,6 @@
# ANVIL_CDSA_GROUP_PREFIX = env(
# "ANVIL_CDSA_GROUP_PREFIX", default="DEV_PRIMED_CDSA_ACCESS"
# )
ANVIL_DATA_ACCESS_GROUP_PREFIX = env(
"ANVIL_DATA_ACCESS_GROUP_PREFIX", default="DEV_PRIMED"
)
ANVIL_DATA_ACCESS_GROUP_PREFIX = env("ANVIL_DATA_ACCESS_GROUP_PREFIX", default="DEV_PRIMED")
ANVIL_CDSA_GROUP_NAME = env("ANVIL_CDSA_GROUP_NAME", default="DEV_PRIMED_CDSA")
ANVIL_CC_ADMINS_GROUP_NAME = env(
"ANVIL_CC_ADMINS_GROUP_NAME", default="DEV_PRIMED_CC_ADMINS"
)
ANVIL_CC_ADMINS_GROUP_NAME = env("ANVIL_CC_ADMINS_GROUP_NAME", default="DEV_PRIMED_CC_ADMINS")
19 changes: 4 additions & 15 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@
# in our apache configuration. Having in both places causes duplicate header
SECURE_HSTS_SECONDS = 0
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True
)
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool("DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True
)
SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
# Since we have disabled HSTS above we get a warning when running check --deploy
# we are manually silencing this as we have verified apache is enforcing
# https://docs.djangoproject.com/en/dev/ref/checks/#security
Expand All @@ -79,9 +75,7 @@
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
DEFAULT_FROM_EMAIL = env(
"DJANGO_DEFAULT_FROM_EMAIL", default="gac-django <[email protected]>"
)
DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL", default="gac-django <[email protected]>")
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL)
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
Expand Down Expand Up @@ -130,12 +124,7 @@
"()": "maintenance_mode.logging.RequireNotMaintenanceMode503",
},
},
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"formatters": {"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(process)d %(thread)d %(message)s"}},
"handlers": {
"mail_admins": {
"level": "ERROR",
Expand Down
Loading

0 comments on commit cad7dfb

Please sign in to comment.