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

Problem importing celery to enable tasks #501

Merged
merged 17 commits into from
Dec 4, 2022
Merged
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/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Build docs
run: |
cd docs
sphinx-build -b html -n -d _build/doctrees . _build/html
sphinx-build -b html -n -d _build/doctrees . _build/html
38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint

on: [push, pull_request]

jobs:
flake8:
name: flake8
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: flake8
run: flake8

isort:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: isort
run: isort --check --diff explorer
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7, 3.8]
python-version: [ 3.8]
requirements-file: [
django-2.2.txt,
django-3.0.txt,
django-3.1.txt,
django-3.2.txt
]
os: [
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
tmp
venv/
.venv/
.tox/

# Sphinx documentation
docs/_build/
Expand Down
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ci:
autofix_commit_msg: |
ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci
autofix_prs: false
autoupdate_commit_msg: 'ci: pre-commit autoupdate'
autoupdate_schedule: monthly

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/adamchainz/django-upgrade
rev: '1.7.0'
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]

- repo: https://github.com/PyCQA/flake8
rev: 5.0.2
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-merge-conflict
- id: mixed-line-ending

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import explorer


sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('.'))

Expand Down
2 changes: 1 addition & 1 deletion docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Snapshots
'schedule': crontab(hour=1, minute=0)
}

- Requires celery, obviously. Also uses djcelery and tinys3. All
- Requires celery, obviously. Also uses boto3. All
of these deps are optional and can be installed with
``pip install -r optional-requirements.txt``
- The checkbox for opting a query into a snapshot is ALL THE WAY
Expand Down
11 changes: 11 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ S3 Bucket for snapshot upload
EXPLORER_S3_BUCKET = None


S3 link expiration
******************

S3 link expiration time. Defaults to 3600 seconds (1hr) if not specified.
Links are generated as presigned urls for security

.. code-block:: python

EXPLORER_S3_S3_LINK_EXPIRATION = 3600


From email
**********

Expand Down
2 changes: 0 additions & 2 deletions explorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ def get_version(short=False):


__version__ = get_version()

default_app_config = 'explorer.apps.ExplorerAppConfig'
4 changes: 2 additions & 2 deletions explorer/actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tempfile
from collections import defaultdict
from datetime import date
import tempfile
from zipfile import ZipFile
from wsgiref.util import FileWrapper
from zipfile import ZipFile

from django.http import HttpResponse

Expand Down
5 changes: 4 additions & 1 deletion explorer/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf import settings
from pydoc import locate

from django.conf import settings


# The 'correct' configuration for Explorer looks like:

# EXPLORER_CONNECTIONS = {
Expand Down Expand Up @@ -124,6 +126,7 @@
S3_ACCESS_KEY = getattr(settings, "EXPLORER_S3_ACCESS_KEY", None)
S3_SECRET_KEY = getattr(settings, "EXPLORER_S3_SECRET_KEY", None)
S3_BUCKET = getattr(settings, "EXPLORER_S3_BUCKET", None)
S3_LINK_EXPIRATION: int = getattr(settings, "EXPLORER_S3_S3_LINK_EXPIRATION", 3600)
FROM_EMAIL = getattr(
settings, 'EXPLORER_FROM_EMAIL', '[email protected]'
)
Expand Down
5 changes: 3 additions & 2 deletions explorer/charts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Optional, Iterable
from io import BytesIO
from typing import Iterable, Optional

from django.core.exceptions import ImproperlyConfigured


try:
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import seaborn as sns
from matplotlib.figure import Figure
except ImportError:
from . import app_settings

Expand Down
3 changes: 1 addition & 2 deletions explorer/exporters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import codecs
import csv
import json
import string
import uuid
from datetime import datetime
from io import StringIO, BytesIO
from io import BytesIO, StringIO

from django.core.serializers.json import DjangoJSONEncoder
from django.utils.module_loading import import_string
Expand Down
10 changes: 3 additions & 7 deletions explorer/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from django.forms import (
BooleanField, CharField, ModelForm, ValidationError
)
from django.forms import BooleanField, CharField, ModelForm, ValidationError
from django.forms.widgets import CheckboxInput, Select

from explorer.app_settings import (
EXPLORER_DEFAULT_CONNECTION, EXPLORER_CONNECTIONS
)
from explorer.models import Query, MSG_FAILED_BLACKLIST
from explorer.app_settings import EXPLORER_CONNECTIONS, EXPLORER_DEFAULT_CONNECTION
from explorer.models import MSG_FAILED_BLACKLIST, Query


class SqlField(CharField):
Expand Down
2 changes: 1 addition & 1 deletion explorer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models, migrations
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion explorer/migrations/0002_auto_20150501_1515.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion explorer/migrations/0003_query_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion explorer/migrations/0006_query_connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion explorer/migrations/0007_querylog_connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
22 changes: 9 additions & 13 deletions explorer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
from time import time

from django.conf import settings
from django.db import models, DatabaseError, transaction
from django.db import DatabaseError, models, transaction
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from explorer import app_settings
from explorer.utils import (
passes_blacklist,
swap_params,
extract_params,
shared_dict_update,
get_s3_bucket,
get_params_for_url,
get_valid_connection
extract_params, get_params_for_url, get_s3_bucket, get_valid_connection, passes_blacklist, s3_url,
shared_dict_update, swap_params,
)


MSG_FAILED_BLACKLIST = "Query failed the SQL blacklist: %s"


Expand Down Expand Up @@ -137,13 +133,13 @@ def shared(self):
def snapshots(self):
if app_settings.ENABLE_TASKS:
b = get_s3_bucket()
keys = b.list(prefix=f'query-{self.id}/snap-')
keys_s = sorted(keys, key=lambda k: k.last_modified)
objects = b.objects.filter(Prefix=f'query-{self.id}/snap-')
objects_s = sorted(objects, key=lambda k: k.last_modified)
return [
SnapShot(
k.generate_url(expires_in=0, query_auth=False),
k.last_modified
) for k in keys_s
s3_url(b, o.key),
o.last_modified
) for o in objects_s
]


Expand Down
2 changes: 1 addition & 1 deletion explorer/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def view_permission(request, **kwargs):
return app_settings.EXPLORER_PERMISSION_VIEW(request)\
or user_can_see_query(request, **kwargs)\
or (app_settings.EXPLORER_TOKEN_AUTH_ENABLED()
and (request.META.get('HTTP_X_API_TOKEN') ==
and (request.headers.get('X-Api-Token') ==
app_settings.EXPLORER_TOKEN
or request.GET.get('token') == app_settings.EXPLORER_TOKEN))

Expand Down
8 changes: 2 additions & 6 deletions explorer/schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from django.core.cache import cache

from explorer.app_settings import (
EXPLORER_SCHEMA_INCLUDE_TABLE_PREFIXES,
EXPLORER_SCHEMA_EXCLUDE_TABLE_PREFIXES,
EXPLORER_SCHEMA_INCLUDE_VIEWS,
ENABLE_TASKS,
EXPLORER_ASYNC_SCHEMA,
EXPLORER_CONNECTIONS
ENABLE_TASKS, EXPLORER_ASYNC_SCHEMA, EXPLORER_CONNECTIONS, EXPLORER_SCHEMA_EXCLUDE_TABLE_PREFIXES,
EXPLORER_SCHEMA_INCLUDE_TABLE_PREFIXES, EXPLORER_SCHEMA_INCLUDE_VIEWS,
)
from explorer.tasks import build_schema_cache_async
from explorer.utils import get_valid_connection
Expand Down
Loading