Skip to content

Commit

Permalink
chore: split utils folder between api and scripts (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Sep 24, 2023
1 parent e638c72 commit 45d137a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion basedosdados_api/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.log import DEFAULT_LOGGING

from basedosdados_api.settings.base import * # noqa
from utils import getenv
from basedosdados_api.utils import getenv

INSTALLED_APPS += ["django_extensions"] # noqa: F405

Expand Down
2 changes: 1 addition & 1 deletion basedosdados_api/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from google.oauth2 import service_account

from basedosdados_api.settings.base import * # noqa
from utils import getadmins, getenv
from basedosdados_api.utils import getadmins, getenv

DEBUG = False
SECRET_KEY = getenv("DJANGO_SECRET_KEY")
Expand Down
18 changes: 18 additions & 0 deletions basedosdados_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# -*- coding: utf-8 -*-
from os import getenv as _getenv

from django.conf import settings

DB_NAME = settings.DATABASES.get("default", {}).get("NAME", "")
DB_ENGINE = settings.DATABASES.get("default", {}).get("ENGINE", "")


def getadmins():
"""Get admins from environment variable"""
admins = getenv("ADMINS")
if admins is None:
return []
return [admin.split(",") for admin in admins.split(";")]


def getenv(var, default=None):
"""Get environment variable or raise exception if not set"""
value = _getenv(var, default)
if value is None:
raise ValueError(f"Environment variable {var} not set")
return value


def is_remote():
"""Check if it is remote environment"""
return "prod" in settings.SETTINGS_MODULE
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrations/20230803_migrate_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from random import choice
from string import ascii_letters, digits, punctuation

from utils.graphql import gql
from scripts.utils import gql

query = """
query ($offset: Int!) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrations/20230807_migrate_careers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from csv import DictReader
from os import getenv

from utils.graphql import gql
from scripts.utils import gql

query = """
query ($offset: Int!) {
Expand Down
File renamed without changes.
17 changes: 0 additions & 17 deletions utils/__init__.py

This file was deleted.

0 comments on commit 45d137a

Please sign in to comment.