Skip to content

Commit

Permalink
Init project
Browse files Browse the repository at this point in the history
  • Loading branch information
nhymxu committed May 12, 2021
1 parent 7376401 commit d950f68
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install build dependencies
run: pip install -U setuptools wheel build

- name: Build
run: python -m build .

- name: Publish
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
skip_existing: true
34 changes: 34 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python test

on:
push:
branches: [ master, main ]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

name: Python ${{ matrix.python-version }} test

steps:
- uses: actions/checkout@v2

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
shell: bash
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Install dependencies
shell: bash
run: pip install -r tests/requirements.txt

- run: python runtests.py
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.venv/
dist
build
poetry.lock
*.egg-info
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Dung Nguyen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# template-repository
# django-floc-disable

[![unit test](https://github.com/nhymxu/django-floc-disable/actions/workflows/test-python.yml/badge.svg?branch=main)](https://github.com/nhymxu/django-floc-disable/actions/workflows/test-python.yml)

Django middleware to disable Google's Federated Learning of Cohorts (`FLoC`) tracking

## Python / Django Support

- Python 3.6+
- Django versions 3+

## Usage

Install django-floc-disable:

```shell
pip install django-floc-disable
```

Add it to your `INSTALLED_APPS`:

```python
MIDDLEWARE = (
# ...
'django_floc_disable.middleware.FLoCDisableMiddleware',
# ...
)
```

This will set the `Permissions-Policy` header to a value of
`interest-cohort=()` for every request served by Django.

## Support

* Issues: <https://github.com/nhymxu/django-floc-disable/issues>
* Here you can [donate](https://dungnt.net/donate.html) for this project.

## License

The MIT License (MIT). Please see [License File](LICENSE.txt) for more information.
1 change: 1 addition & 0 deletions django_floc_disable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
5 changes: 5 additions & 0 deletions django_floc_disable/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class FlocDisableConfig(AppConfig):
name = 'floc_disable'
9 changes: 9 additions & 0 deletions django_floc_disable/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class FLoCDisableMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
response['Permissions-Policy'] = "interest-cohort=()"

return response
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
15 changes: 15 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys

import django
from django.conf import settings
from django.test.utils import get_runner

if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["tests"])
sys.exit(bool(failures))
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[metadata]
# This includes the license file(s) in the wheel.
# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
license_files = LICENSE.txt
37 changes: 37 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from setuptools import setup, find_packages
import pathlib

here = pathlib.Path(__file__).parent.resolve()

project_name = "django-floc-disable"

long_description = (here / 'README.md').read_text(encoding='utf-8')

setup(
name="django-floc-disable",
version="0.1.0",
description="Django middleware to disable Google FLoC tracking",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/nhymxu/django-floc-disable",
author="Dung Nguyen",
project_urls={
"Bug Tracker": "https://github.com/nhymxu/django-floc-disable/issues",
"Funding": "https://dungnt.net/donate.html",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3 :: Only',
],
package_dir={project_name: project_name},
packages=find_packages(),
python_requires=">=3.6",
install_requires=['Django'],
)
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
django>3
21 changes: 21 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DEBUG = False

SECRET_KEY = "not-secret"

DATABASES = {
"default": {"ENGINE": "django.db.backends.sqlite3", "LOCATION": ":memory:"}
}

ALLOWED_HOSTS = ["*"]

INSTALLED_APPS = []

MIDDLEWARE = (
'django_floc_disable.middleware.FLoCDisableMiddleware',
)

ROOT_URLCONF = "tests.test_urls"

STATIC_URL = "/static/"

TEMPLATES = []
6 changes: 6 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from django.http import HttpResponse

urlpatterns = [
path("", lambda request: HttpResponse("Hello World"), name="index")
]
8 changes: 8 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.test import TestCase


class MiddlewareTest(TestCase):
def test_middleware(self):
response = self.client.get('/')

self.assertEqual(response["Permissions-Policy"], 'interest-cohort=()')

0 comments on commit d950f68

Please sign in to comment.