Repository: ImperialCollegeLondon/django-passwordless-login (language: python)

Issue:
Publish on PyPI
Make this app pip installable. Requires adding a version numbering system like bumpversion.


Discussion / hints:

Fix patch:
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..2558215
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,3 @@
+[flake8]
+max-line-length = 88
+exclude = .venv/,passwordless_login/migrations/
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 15d72ac..8b40443 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,20 +1,17 @@
 on: push
 jobs:
   qa:
-    runs-on: ubuntu-18.04
+    runs-on: ubuntu-20.04
     steps:
       - uses: actions/checkout@v2
       - uses: actions/setup-python@v2
         with:
-          python-version: 3.8
+          python-version: 3.9
+      - uses: pre-commit/action@v2.0.2
       - name: Install prerequisites
         run: |
           python -m pip install -q -U pip
           python -m pip install -q -r requirements.txt
-      - name: Run linter
-        run: |
-          python -m pip install -q flake8
-          flake8
       - name: Run tests
         run: |
           python run_tests.py
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..2cff268
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,33 @@
+name: Deploy to PyPI and TestPyPI
+
+on: push
+
+jobs:
+  deploy:
+
+    runs-on: ubuntu-latest
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Get history and tags for SCM versioning to work
+      run: |
+        git fetch --prune --unshallow
+        git fetch --all --tags
+    - name: Set up Python
+      uses: actions/setup-python@v2
+      with:
+        python-version: 3.9
+
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        pip install build
+    - name: Build package
+      run: python -m build
+
+    - name: Publish package
+      if: startsWith(github.ref, 'refs/tags')
+      uses: pypa/gh-action-pypi-publish@release/v1
+      with:
+        user: __token__
+        password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..688aa40
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,16 @@
+repos:
+  - repo: https://github.com/timothycrosley/isort
+    rev: "5.10.1"
+    hooks:
+      - id: isort
+        additional_dependencies: [toml]
+  - repo: https://github.com/psf/black
+    rev: "22.3.0"
+    hooks:
+      - id: black
+        exclude: powbal_core/migrations/
+  - repo: https://gitlab.com/pycqa/flake8
+    rev: 3.9.2
+    hooks:
+      - id: flake8
+        exclude: powbal_core/migrations/
diff --git a/MANIFEST.in b/MANIFEST.in
index 36b715f..b3fe293 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,3 +1,4 @@
 include README.md
 recursive-include passwordless_login/static *
 recursive-include passwordless_login/templates *
+include requirements.txt
diff --git a/passwordless_login/settings.py b/passwordless_login/settings.py
index f36f6fd..1092725 100644
--- a/passwordless_login/settings.py
+++ b/passwordless_login/settings.py
@@ -1,4 +1,5 @@
 import datetime
+
 from django.conf import settings
 
 # Add sesame backend and middleware to project settings
diff --git a/passwordless_login/views.py b/passwordless_login/views.py
index 87b0242..2052d14 100644
--- a/passwordless_login/views.py
+++ b/passwordless_login/views.py
@@ -2,7 +2,6 @@
 from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
 
 import sesame.utils
-
 from django.contrib.auth import get_user_model
 from django.core.exceptions import ValidationError
 from django.core.mail import send_mail
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..f1138dc
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,6 @@
+[tool.black]
+exclude = '\.venv/|main/migrations/'
+[tool.isort]
+line_length = 88
+multi_line_output = 3
+include_trailing_comma = true
diff --git a/setup.py b/setup.py
index 10a3141..ca516ec 100644
--- a/setup.py
+++ b/setup.py
@@ -5,12 +5,18 @@
 with Path("requirements.txt").open("r") as f:
     dependencies = f.readlines()
 
+with Path("README.md").open("r") as f:
+    long_description = f.read()
+
 setup(
     name="django-passwordless-login",
     version="0.0.1",
+    description="Login to your Django app with a link sent by email.",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
     url="https://github.com/ImperialCollegeLondon/django-passwordless-login",
-    author="Research Computing Service, Imperial College London",
-    author_email="rcs-support@imperial.ac.uk",
+    author="Adrian D'Alessandro",
+    author_email="a.dalessandro@imperial.ac.uk",
     install_requires=dependencies,
     extras_require={},
     packages=find_packages("."),


Test patch:
diff --git a/passwordless_login/tests.py b/passwordless_login/tests.py
index 74d5802..fb87107 100644
--- a/passwordless_login/tests.py
+++ b/passwordless_login/tests.py
@@ -1,9 +1,9 @@
 import re
+from unittest.mock import patch
 
 from django.contrib.auth import get_user_model
 from django.core import mail
 from django.test import TestCase
-from unittest.mock import patch
 
 
 @patch("django.conf.settings.CREATE_NEW_USERS", True)
diff --git a/run_tests.py b/run_tests.py
index 5b5bdb6..ad6bbe0 100644
--- a/run_tests.py
+++ b/run_tests.py
@@ -1,8 +1,8 @@
 import sys
 
 import django
-from django.test.runner import DiscoverRunner
 from django.conf import settings
+from django.test.runner import DiscoverRunner
 
 
 def run_tests(*test_args):