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

Update workflows #40

Merged
merged 7 commits into from
Oct 13, 2020
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
10 changes: 0 additions & 10 deletions .black

This file was deleted.

13 changes: 6 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ ignore=
D200
# Imperative docstring declarations
D401

# Type annotation for `self`
TYP101
TYP102 # for cls

# Missing docstring in __init__
D107

# Missing docstring in public package
D104

# Missing type annotations for `**kwargs`
TYP003

# Whitespace before ':'. Black formats code this way.
E203

# 1 blank line required between summary line and description
D205

# First line should end with a period - here we have a few cases where the first line is too long, and
# this issue can't be fixed without using noqa notation
D400
# Missing type annotations for self
ANN101
# Missing type annotation for cls in classmethod
ANN102
# Missing type annotations for **kwargs
ANN003

exclude =
.git,
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements-test-base.txt
pip install -r tests/requirements-test-django3.txt
pip install poetry
poetry install
- name: Test with pytest
run: |
pytest --cov=django_guid tests/ --cov-report=xml
poetry run pytest --cov=django_guid tests/ --verbose --color=yes --assert=plain --cov-report=xml
poetry run coverage report
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
26 changes: 9 additions & 17 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Publish django-guid to PyPI and TestPyPI 📦
name: Publish django-guid to PyPI 📦

on: push
on:
JonasKs marked this conversation as resolved.
Show resolved Hide resolved
release:
types: [published]

jobs:
build-and-publish:
Expand All @@ -9,24 +11,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-publish-pypi.txt
- name: Build
pip install poetry
- name: Build and publish
run: |
python setup.py sdist bdist_wheel
- name: Publish distribution of django-guid to Test PyPI 📦
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && contains(github.ref, '-rc')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution of django-guid to PyPI 📦
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && !contains(github.ref, '-rc')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
poetry config pypi-token.pypi ${{ secrets.pypi_password }}
poetry publish --build --no-interaction
15 changes: 8 additions & 7 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements-test-base.txt
pip install -r tests/requirements-test-django2.txt
pip install poetry
poetry install
pip install Django==2.2.12
- name: Lint with flake8
run: |
pip install flake8
Expand All @@ -29,7 +30,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Test with pytest
run: |
pytest --cov=django_guid tests/
poetry run pytest --cov=django_guid tests/

django-3:
runs-on: ubuntu-latest
Expand All @@ -46,8 +47,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements-test-base.txt
pip install -r tests/requirements-test-django3.txt
pip install poetry
poetry install
- name: Lint with flake8
run: |
pip install flake8
Expand All @@ -57,4 +58,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Test with pytest
run: |
pytest --cov=django_guid tests/
poetry run pytest --cov=django_guid tests/
11 changes: 11 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
use_parentheses=True
line_length=120
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
default_section=THIRDPARTY
42 changes: 29 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
rev: 20.8b1
hooks:
- id: black
language_version: python3.8
args: ['--quiet', '--config=.black']
args: ['--quiet']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: detect-private-key
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear==19.8.0', # Looks for likely bugs and design problems
'flake8-comprehensions==3.0.1', # Looks for unnecessary generator functions that can be converted to list comprehensions
'flake8-bugbear==20.1.4', # Looks for likely bugs and design problems
'flake8-comprehensions==3.2.3', # Looks for unnecessary generator functions that can be converted to list comprehensions
'flake8-deprecated==1.3', # Looks for method deprecations
'flake8-use-fstring==1.0', # Enforces use of f-strings over .format and %s
'flake8-use-fstring==1.1', # Enforces use of f-strings over .format and %s
'flake8-print==3.1.4', # Checks for print statements
'flake8-docstrings==1.5.0', # Verifies that all functions/methods have docstrings
'flake8-type-annotations==0.1.0', # Looks for misconfigured type annotations
'flake8-annotations==1.1.1', # Enforces type annotation
'flake8-logging-format==0.6.0', # Enforces log formatting to be correct
'flake8-annotations==2.4.0', # Enforces type annotation
]
args: ['--enable-extensions=G']
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/pycqa/isort
rev: 5.5.2
hooks:
- id: isort
files: 'django_guid/.*'
- id: isort
files: 'tests/.*'
- repo: local
hooks:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
files: ^(CHANGELOG.rst|README.rst)$
files: ^(CHANGELOG.rst|README.rst|CONTRIBUTING.rst|CONTRIBUTORS.rst|docs/api.rst|docs/extended_example.rst|docs/index.rst|docs/install.rst/index.rst|docs/integration.rst/index.rst|docs/publish.rst/index.rst|docs/settings.rst/index.rst|docs/troubleshooting.rst)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.782'
hooks:
- id: mypy
9 changes: 5 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Contributing to Django GUID
This package is open to contributions. To contribute, please follow these steps:

1. Fork the upstream django-guid repository into a personal account.
2. Install development requirements from ``requirements-dev.txt``.
3. Install pre-commit (linting) by running ``pre-commit install``.
2. Install poetry running ``pip install poetry`` or ``curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -``
3. Install dependencies by running ``poetry install``
3. Install pre-commit (for linting) by running ``pre-commit install``
4. Create a new branch for you changes
5. Push the topic branch to your personal fork.
6. Create a pull request to the django-guid repository with a detailed explanation of why you propose the changes should be made.
5. Push the topic branch to your personal fork
6. Create a pull request to the django-guid repository with a detailed explanation of why you propose the changes should be made
3 changes: 2 additions & 1 deletion demoproj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"""

import os
from typing import List

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'secret'

DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS: List[str] = []

# Application definition

Expand Down
2 changes: 1 addition & 1 deletion demoproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
from django.urls import path

from demoproj.views import index_view, rest_view, no_guid
from demoproj.views import index_view, no_guid, rest_view

urlpatterns = [
path('', index_view, name='index'),
Expand Down
2 changes: 1 addition & 1 deletion demoproj/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.http import HttpRequest, JsonResponse
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.request import Request
from rest_framework.response import Response

from demoproj.services.useless_file import useless_function

Expand Down
11 changes: 7 additions & 4 deletions django_guid/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import List
from warnings import warn

from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.inspect import func_accepts_kwargs

from django_guid.integrations import Integration

class Settings(object):

class Settings:
"""
Settings for django_guid read from the Django settings in `settings.py`.

Expand All @@ -17,8 +20,8 @@ def __init__(self) -> None:
self.VALIDATE_GUID = True
self.RETURN_HEADER = True
self.EXPOSE_HEADER = True
self.INTEGRATIONS = []
self.IGNORE_URLS = []
self.INTEGRATIONS: List[Integration] = []
self.IGNORE_URLS: List[str] = []
self.SKIP_CLEANUP = None # Deprecated - to be removed in the next major version

if hasattr(django_settings, 'DJANGO_GUID'):
Expand Down Expand Up @@ -48,7 +51,7 @@ def __init__(self) -> None:
raise ImproperlyConfigured('IGNORE_URLS must be an array of strings')
# Note: stripping the '/' from the beginning and end of the path of the URLS,
# this is since some people would write a path as "/path/one/two/" while others would write "path/one/two"
self.IGNORE_URLS = {url.strip('/') for url in self.IGNORE_URLS}
self.IGNORE_URLS = list({url.strip('/') for url in self.IGNORE_URLS})

self._validate_and_setup_integrations()

Expand Down
6 changes: 4 additions & 2 deletions django_guid/integrations/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Optional

from django.core.exceptions import ImproperlyConfigured


class Integration(object):
class Integration:
"""
Integration base class.
"""

identifier = None # The name of your integration
identifier: Optional[str] = None # The name of your integration

def __init__(self) -> None:
if self.identifier is None:
Expand Down
8 changes: 4 additions & 4 deletions django_guid/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import threading
import uuid
from typing import Callable, Union
from typing import Callable, Dict, Optional, Union

from django.apps import apps
from django.core.exceptions import ImproperlyConfigured
Expand All @@ -12,13 +12,13 @@
logger = logging.getLogger('django_guid')


class GuidMiddleware(object):
class GuidMiddleware:
"""
Gets a GUID from a request header, or generates a GUID if none is found, for each incoming request.
Stored GUIDs are accessible from anywhere in the Django app.
"""

_guid = {}
_guid: Dict[threading.Thread, str] = {}

def __init__(self, get_response: Callable) -> None:
"""
Expand Down Expand Up @@ -67,7 +67,7 @@ def __call__(self, request: HttpRequest) -> Union[HttpRequest, HttpResponse]:
return response

@classmethod
def get_guid(cls, default: str = None) -> str:
def get_guid(cls, default: Optional[str] = None) -> str:
"""
Fetches the GUID of the current thread from _guid.
If no value has been set for the current thread yet, a default value is returned.
Expand Down
Loading