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

Django v4.2 #4931

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
- name: Install deps
run: |
pip install --upgrade pip
pip install tox==4.20.0
pip install tox==4.23.2
sudo apt update
sudo apt install gdal-bin
- name: Setup config
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ bpd/data/untracked/*
bpd/data/epa*
bpd/data/BEDES*
**/*-old
lin/migrations/disabled
htmlcov/
src/
node_modules/

# JetBrains tends to suggest a venv directory in the project root for virtual environments
Expand All @@ -66,9 +64,6 @@ seed/tests/output
test.sqlite

docs/build/
docs/scripts/Gemfile.lock
docs/scripts/.python-version
docs/scripts/seed_issues.csv
docs/htmlout

lokalise.cfg
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
types_or: [yaml, markdown, css, scss]
# https://docs.astral.sh/ruff/integrations/#pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.9.1
hooks:
# Run the linter
- id: ruff
Expand Down
28 changes: 18 additions & 10 deletions config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import os
from distutils.util import strtobool
from typing import Union

from django.utils.translation import gettext_lazy as _
from kombu.serialization import register
Expand All @@ -26,17 +26,21 @@

USE_I18N = True
LANGUAGES = (
("en", _("English")),
("en-us", _("English")),
("fr-ca", _("French (Canada)")),
("es", _("Spanish")),
)
LOCALE_PATHS = ("locale",)
LANGUAGE_CODE = "en-us"

SECRET_KEY = os.environ.get("SECRET_KEY", "default-ns=nb-w)#2ue-mtu!s&2krzfee1-t)^z7y8gyrp6mx^d*weifh")

CSRF_COOKIE_SAMESITE = "Strict"

SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
# Default to expiring cookies after 2 weeks
SESSION_COOKIE_AGE = int(os.environ.get("COOKIE_EXPIRATION", 1_209_600))
SESSION_COOKIE_SAMESITE = "Strict"

TEMPLATES = [
{
Expand Down Expand Up @@ -89,7 +93,6 @@
"django_extensions",
"django_filters",
"rest_framework",
"crispy_forms", # needed to squash warnings around collectstatic with rest_framework
"post_office",
"django_celery_beat",
"treebeard",
Expand Down Expand Up @@ -202,9 +205,7 @@
},
}

# LOGIN_URL = "two_factor:login"
LOGIN_REDIRECT_URL = "two_factor:profile"
# LOGIN_REDIRECT_URL = "/app/"
LOGIN_REDIRECT_URL = "/app/#/profile/two_factor_profile"

APPEND_SLASH = True

Expand All @@ -218,6 +219,7 @@
)
CELERY_WORKER_MAX_TASKS_PER_CHILD = 1
CELERY_ACCEPT_CONTENT = ["seed_json", "pickle"]
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True
CELERY_TASK_SERIALIZER = "seed_json"
CELERY_RESULT_SERIALIZER = "seed_json"
CELERY_RESULT_EXPIRES = 86400 # 24 hours
Expand Down Expand Up @@ -304,10 +306,16 @@
"LOGOUT_URL": "/accounts/logout",
}

try:
EEEJ_LOAD_SMALL_TEST_DATASET = bool(strtobool(os.environ.get("EEEJ_LOAD_SMALL_TEST_DATASET", "False")))
except Exception:
EEEJ_LOAD_SMALL_TEST_DATASET = False

def yn(s: Union[bool, str]) -> bool:
if isinstance(s, bool):
return s
if isinstance(s, str):
return s.lower() in ["y", "yes", "t", "true", "on", "1"]
return False


EEEJ_LOAD_SMALL_TEST_DATASET = yn(os.environ.get("EEEJ_LOAD_SMALL_TEST_DATASET", "False"))

BSYNCR_SERVER_HOST = os.environ.get("BSYNCR_SERVER_HOST")
BSYNCR_SERVER_PORT = os.environ.get("BSYNCR_SERVER_PORT", "80")
Expand Down
8 changes: 3 additions & 5 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import importlib.util
import logging
import os
from distutils.util import strtobool

from celery.utils import LOG_LEVELS

Expand Down Expand Up @@ -37,6 +36,8 @@
# this celery log level is currently not overridden.
CELERY_LOG_LEVEL = LOG_LEVELS["WARNING"]

TESTING_MAPQUEST_API_KEY = os.environ.get("TESTING_MAPQUEST_API_KEY", "<your_key_here>")

REQUIRE_UNIQUE_EMAIL = False

INTERNAL_IPS = ("127.0.0.1",)
Expand Down Expand Up @@ -85,7 +86,4 @@
SF_SECURITY_TOKEN = os.environ.get("SF_SECURITY_TOKEN", "")

# load small EEEJ dataset for testing
try:
EEEJ_LOAD_SMALL_TEST_DATASET = bool(strtobool(os.environ.get("EEEJ_LOAD_SMALL_TEST_DATASET", "True")))
except Exception:
EEEJ_LOAD_SMALL_TEST_DATASET = True
EEEJ_LOAD_SMALL_TEST_DATASET = yn(os.environ.get("EEEJ_LOAD_SMALL_TEST_DATASET", "True")) # noqa: F405
36 changes: 18 additions & 18 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import include, path, re_path
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
from two_factor.urls import urlpatterns as tf_urls
from two_factor.urls import urlpatterns as two_factor_urls

from config.views import robots_txt
from seed.api.base.urls import urlpatterns as api
Expand All @@ -37,27 +37,27 @@ def trigger_error(request):


urlpatterns = [
re_path(r"^accounts/password/reset/done/$", password_reset_done, name="password_reset_done"),
re_path(
r"^accounts/password/reset/complete/$",
path("accounts/password/reset/done/", password_reset_done, name="password_reset_done"),
path(
"accounts/password/reset/complete/",
password_reset_complete,
name="password_reset_complete",
),
path("accounts/password/reset/confirm/<uidb64>/<token>/", password_reset_confirm, name="password_reset_confirm"),
# Application
re_path(r"^", include(("seed.landing.urls", "seed.landing"), namespace="landing")),
re_path(r"^app/", include(("seed.urls", "seed"), namespace="seed")),
re_path(r"^documentation/", include(("seed.docs.urls", "seed.docs"), namespace="docs")),
path("", include(("seed.landing.urls", "seed.landing"), namespace="landing")),
path("app/", include(("seed.urls", "seed"), namespace="seed")),
path("documentation/", include(("seed.docs.urls", "seed.docs"), namespace="docs")),
# root configuration items
re_path(r"^i18n/", include("django.conf.urls.i18n")),
re_path(r"^robots\.txt", robots_txt, name="robots_txt"),
path("i18n/", include("django.conf.urls.i18n")),
path("robots.txt", robots_txt, name="robots_txt"),
# API
re_path(r"^api/health_check/$", health_check, name="health_check"),
re_path(r"^api/swagger/$", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
re_path(r"^api/version/$", version, name="version"),
re_path(r"^api/", include((api, "seed"), namespace="api")),
re_path(r"^account/login", CustomLoginView.as_view(), name="login"),
re_path(r"^", include(tf_urls)),
path("api/health_check/", health_check, name="health_check"),
path("api/swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
path("api/version/", version, name="version"),
path("api/", include((api, "seed"), namespace="api")),
path("account/login", CustomLoginView.as_view(), name="login"),
path("", include(two_factor_urls)),
# test sentry error
path("sentry-debug/", trigger_error),
]
Expand All @@ -76,7 +76,7 @@ def trigger_error(request):
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [
# test URLs
re_path(r"^angular_js_tests/$", angular_js_tests, name="angular_js_tests"),
path("angular_js_tests/", angular_js_tests, name="angular_js_tests"),
# admin
re_path(r"^admin/", admin.site.urls),
path("admin/", admin.site.urls),
]
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ignore_missing_imports = True
exclude = (?x)(
^docs\/source\/conf\.py$
| ^seed\/tests\/test_search\.py$
| ^src\/.*$
| ^venv\/.*$
)

Expand Down
6 changes: 3 additions & 3 deletions requirements/aws.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r base.txt
boto3==1.35.21
django-ses==4.1.1
uWSGI==2.0.26; sys_platform != "win32"
boto3==1.36.1
django-ses==4.3.2
uWSGI==2.0.28; sys_platform != "win32"
33 changes: 15 additions & 18 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Django
django==3.2.25 # TODO update

# Used by django-filter. See here: https://github.com/carltongibson/django-filter/blob/fe90e3a5fdeaff0983d1325a3e9dcf3458ef078f/docs/guide/rest_framework.txt#L210
django-crispy-forms==1.8.1 # Update to major version 2
django==4.2.18

# Persistence stores
psycopg2-binary==2.9.9
psycopg2-binary==2.9.10

# Background process management
celery==5.4.0
Expand All @@ -14,7 +11,7 @@ django-redis==5.4.0
hiredis==3.0.0

brotli==1.1.0
django-compressor==4.4 # Update after Django 4.2
django-compressor==4.5.1
django-extensions==3.2.3
django-model-utils==5.0.0

Expand All @@ -23,14 +20,14 @@ pytz==2024.2
python-dateutil==2.9.0.post0

# Metric/imperial units support
django-pint==0.7.3
django-pint==0.7.3 # https://github.com/hgrecco/pint/issues/2065

# API
djangorestframework==3.15.1 # Update after Django 4.2
django-post_office==3.8.0 # Update after Django 4.2
drf-yasg==1.21.7
django-filter==22.1 # Update after Django 4.2 and drf-spectacular
drf-nested-routers==0.94.0 # Update after Django 4.2
djangorestframework==3.15.2
django-post-office==3.9.0
drf-yasg==1.21.8
django-filter==22.1 # Update after drf-spectacular
drf-nested-routers==0.94.1

# Server monitoring
sentry-sdk==2.14.0
Expand All @@ -48,26 +45,26 @@ requests==2.32.3
probablepeople==0.5.5
xmlschema==3.4.2
lark==1.2.2
pandas==2.2.2
pandas==2.2.3

# Parsing and managing geojson data (this is only used in managed tasks at the moment)
geojson==3.1.0

# BuildingSync Asset Extractor
# this also includes the lxml dependency required by SEED
buildingsync-asset-extractor==v0.2.0
buildingsync-asset-extractor==v0.2.1

# Salesforce Integration
seed-salesforce==0.1.0
seed-salesforce==0.1.1

# geospatial and pnnl/buildingid-py
shapely==2.0.6
usaddress==0.5.10
pnnl-buildingid @ git+https://github.com/SEED-platform/buildingid@bdb0a6e
usaddress==0.5.11
pnnl-buildingid @ git+https://github.com/SEED-platform/buildingid@df04c15

django-treebeard==4.7.1

django-two-factor-auth[phonenumbers]==1.16.0 # Update after Django 4.2
django-two-factor-auth[phonenumbers]==1.17.0
qrcode[pil]==7.4.2
pyotp==2.9.0

Expand Down
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Local development dependencies go here
-r test.txt
django-debug-toolbar==4.3.0 # Update after Django 4.2
django-debug-toolbar==4.4.6
14 changes: 5 additions & 9 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
-r base.txt

# general
coverage==7.6.1
coveralls==4.0.1
tox==4.20.0 # Keep this in sync with ci.yml
psutil==6.0.0
coverage==7.6.10
coveralls==4.0.1 # https://github.com/TheKevJames/coveralls-python/pull/542
tox==4.23.2 # Keep this in sync with ci.yml
psutil==6.1.1

# python testing
Faker==29.0.0
Expand All @@ -16,8 +16,7 @@ pytest-django==4.9.0
urllib3==1.26.20 # TODO update after vcrpy supports v2

# static code analysis
pre-commit==3.8.0
ruff==0.8.3
pre-commit==4.0.1

# documentation and spelling
Sphinx==7.4.7 # TODO update after python 3.9
Expand All @@ -27,6 +26,3 @@ docutils==0.20.1

# property-based testing
hypothesis==6.112.1

# static type checking
mypy==1.11.2
2 changes: 1 addition & 1 deletion seed/analysis_pipelines/better/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_building_analysis(self, better_building_id, better_analysis_id):
try:
response = requests.request("GET", url, headers=headers, timeout=60)
if response.status_code == 404:
return None, [f'BETTER analysis could not be fetched: Status Code: 404 {response.json()["detail"]}']
return None, [f"BETTER analysis could not be fetched: Status Code: 404 {response.json()['detail']}"]
if response.status_code != 200:
return None, [f"BETTER analysis could not be fetched: Status Code: {response.status_code}"]
response_json = response.json()
Expand Down
8 changes: 4 additions & 4 deletions seed/analysis_pipelines/better/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _prepare_analysis(self, property_view_ids, start_analysis=False):
# validate the configuration
validation_errors = _validate_better_config(analysis)
if validation_errors:
raise AnalysisPipelineError(f'Analysis configuration is invalid: {"; ".join(validation_errors)}')
raise AnalysisPipelineError(f"Analysis configuration is invalid: {'; '.join(validation_errors)}")

progress_data = self.get_progress_data(analysis)

Expand Down Expand Up @@ -380,10 +380,10 @@ def _process_results(self, analysis_id):

ee_measure_column_data_paths = [
ExtraDataColumnPath(
f'better_recommendation_{ee_measure_name["name"].lower().replace(" ", "_")}',
f'BETTER Recommendation: {ee_measure_name["name"]}',
f"better_recommendation_{ee_measure_name['name'].lower().replace(' ', '_')}",
f"BETTER Recommendation: {ee_measure_name['name']}",
1,
f'assessment.ee_measures.{ee_measure_name["token"]}',
f"assessment.ee_measures.{ee_measure_name['token']}",
)
for ee_measure_name in ee_measure_names
]
Expand Down
4 changes: 2 additions & 2 deletions seed/analysis_pipelines/bsyncr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _validate_bsyncr_config(analysis):
if model_type not in BSYNCR_MODEL_TYPE_MAP:
return [
f'Analysis configuration.model_type "{model_type}" is invalid. '
f'Must be one of the following: {", ".join(BSYNCR_MODEL_TYPE_MAP.keys())}'
f"Must be one of the following: {', '.join(BSYNCR_MODEL_TYPE_MAP.keys())}"
]

return []
Expand All @@ -80,7 +80,7 @@ def _prepare_analysis(self, property_view_ids, start_analysis=False):

validation_errors = _validate_bsyncr_config(Analysis.objects.get(id=self._analysis_id))
if validation_errors:
raise AnalysisPipelineError(f'Unexpected error(s) while validating analysis configuration: {"; ".join(validation_errors)}')
raise AnalysisPipelineError(f"Unexpected error(s) while validating analysis configuration: {'; '.join(validation_errors)}")

progress_data = self.get_progress_data()

Expand Down
Loading
Loading