Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Lint with black and isort (#22)
Browse files Browse the repository at this point in the history
* Add linters to tox & gh actions

- Add flake8, black and isort to our tox configuraion.
- Make black and isort run automatically with tox and gh actions workflow.

* Automatically reformat imports with isort

* Automatically reformat code with black.
  • Loading branch information
jonathangreen authored Oct 18, 2021
1 parent 72e7025 commit 3e4f339
Show file tree
Hide file tree
Showing 187 changed files with 22,586 additions and 18,518 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
name: Test Server Core
name: Lint & Test
on: [push, pull_request]

jobs:
test-core:
name: Run Core Tests
lint:
name: Lint
runs-on: ubuntu-latest

# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. This prevents duplicated runs on internal PRs.
# Some discussion of this here:
# https://github.community/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Python Packages
run: |
pip install --upgrade pip
pip install tox
- name: Run isort
run: tox -e isort

- name: Run Black
run: tox -e black

test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
19 changes: 12 additions & 7 deletions analytics.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

import importlib
import contextlib
import importlib
import os
from collections import defaultdict

from sqlalchemy.orm.session import Session

from .model import ExternalIntegration
from .config import CannotLoadConfiguration
from .model import ExternalIntegration
from .util.datetime_helpers import utc_now


class Analytics(object):

GLOBAL_ENABLED = None
Expand All @@ -22,15 +23,17 @@ def __init__(self, _db):
Analytics.LIBRARY_ENABLED = set()
# Find a list of all the ExternalIntegrations set up with a
# goal of analytics.
integrations = _db.query(ExternalIntegration).filter(ExternalIntegration.goal==ExternalIntegration.ANALYTICS_GOAL)
integrations = _db.query(ExternalIntegration).filter(
ExternalIntegration.goal == ExternalIntegration.ANALYTICS_GOAL
)
# Turn each integration into an analytics provider.
for integration in integrations:
kwargs = {}
module = integration.protocol
if module.startswith('.'):
if module.startswith("."):
# This is a relative import. Import it relative to
# this module. This should only happen during tests.
kwargs['package'] =__name__
kwargs["package"] = __name__
else:
# This is an absolute import. Trust sys.path to find it.
pass
Expand All @@ -48,7 +51,9 @@ def __init__(self, _db):
self.library_providers[library.id].append(provider)
Analytics.LIBRARY_ENABLED.add(library.id)
else:
self.initialization_exceptions[integration.id] = "Module %s does not have Provider defined." % module
self.initialization_exceptions[integration.id] = (
"Module %s does not have Provider defined." % module
)
except (ImportError, CannotLoadConfiguration) as e:
self.initialization_exceptions[integration.id] = e

Expand Down
Loading

0 comments on commit 3e4f339

Please sign in to comment.