Skip to content

Commit

Permalink
Merge pull request #315 from UW-GAC/maint/pip-tools
Browse files Browse the repository at this point in the history
Switch to using pip-tools for package version requirements
  • Loading branch information
amstilp authored Nov 16, 2023
2 parents 859195b + 732c60d commit dfc4f8b
Show file tree
Hide file tree
Showing 11 changed files with 683 additions and 138 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
python-version: 3.9
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
requirements/requirements.txt
requirements/test-requirements.txt
# Run all pre-commit hooks on all the files.
# Getting only staged files can be tricky in case a new PR is opened
Expand Down Expand Up @@ -75,29 +75,30 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
requirements/requirements.txt
requirements/test-requirements.txt
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/local.txt
pip install pip-tools
pip-sync requirements/requirements.txt requirements/test-requirements.txt
- name: Run tests
run: coverage run -p -m pytest
env:
# We can set this to an empty string, since we'll never make an API call.
ANVIL_API_SERVICE_ACCOUNT_FILE: foo

- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: .coverage.*

pytest-sqlite:
runs-on: ubuntu-latest

steps:
- name: Checkout Code Repository
uses: actions/[email protected]
Expand All @@ -108,26 +109,27 @@ jobs:
python-version: 3.8
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
requirements/requirements.txt
requirements/test-requirements.txt
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/local.txt
pip install pip-tools
pip-sync requirements/requirements.txt requirements/test-requirements.txt
- name: Run tests
run: coverage run -p -m pytest
env:
# We can set this to an empty string, since we'll never make an API call.
ANVIL_API_SERVICE_ACCOUNT_FILE: foo

- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: .coverage.*

coverage:
needs:
- pytest-mariadb
Expand Down Expand Up @@ -159,4 +161,3 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

89 changes: 50 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gregor-django ==========
# gregor-django

GREGoR Dynamic Web Apps Oauth Client Site

Expand All @@ -8,28 +8,29 @@ GREGoR Dynamic Web Apps Oauth Client Site

[![Built with Cookiecutter Django](https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg?logo=cookiecutter)](https://github.com/pydanny/cookiecutter-django/)

Setup Application \^\^\^\^\^\^\^\^\^\^\^\^\^\^
## Setup Application

Brief details on how to deploy this application in dev:

- create virtualenv (python 3.8 or greater required)
- create virtualenv: python -m venv venv
- activate virtualenv: source venv/bin/activate
- create virtualenv (prefer python 3.8 to match staging/prod servers)
- create virtualenv: `python -m venv venv`
- activate virtualenv: `source venv/bin/activate`
- clone repository
- cd into project root dir
- python -m pip install -r requirements/local.txt
- python manage.py migrate
- python manage.py createsuperuser
- python manage.py runserver_plus
- `python -m pip install pip-tools`
- `pip-sync requirements/requirements.txt test-requirements.txt dev-requirements.txt`
- `python manage.py migrate`
- `python manage.py createsuperuser`
- `python manage.py runserver_plus`
- visit your \<site url\>/admin to login as super user you just
created
- by default manage.py uses config/settings/local.py if you want
custom config, you can create a username_local.py config file that
includes local.py and use it by setting the following environment
- by default `manage.py` uses `config/settings/local.py` if you want
custom config, you can create a `username_local.py` config file that
includes `local.py` and use it by setting the following environment
variable ie:
- export DJANGO_SETTINGS_MODULE=config.settings.username_local

Enable oauth login for github \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
## Enable oauth login for github

- Create a github client ID and Secret [Instructions
here](https://django-allauth.readthedocs.io/en/latest/providers.html#github)
Expand All @@ -47,7 +48,7 @@ Enable oauth login for github \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
- login at the oauth server site and follow instructions to grant
permissions and create oauth account

# Enable oauth login for drupal
## Enable oauth login for drupal

- [Configuration and setup instructions for drupal simple_oauth
provider](gregor_django/drupal_oauth_provider/docs/provider.md)
Expand All @@ -67,7 +68,7 @@ Enable oauth login for github \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
- login at the oauth server site and follow instructions to grant
permissions and create oauth account

# Troubleshooting
## Troubleshooting

> Check your callback url. Your django development server may be running
> at <http://localhost:8000/accounts/github/login/callback/> instead of
Expand All @@ -81,13 +82,13 @@ Example:
Django version 3.1.13, using settings 'config.settings.local'
Development server is running at http://[127.0.0.1]:8000/

# Type checks
## Type checks

Running type checks with mypy:

$ mypy gregor_django

# Test coverage
## Test coverage

To run the tests, check your test coverage, and generate an HTML
coverage report:
Expand All @@ -96,29 +97,39 @@ coverage report:
$ coverage html
$ open htmlcov/index.html (git bash on windows use start instead of open)

Running tests with pytest and unittest
\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~
### Running tests with pytest and unittest

$ pytest
$ python manage.py test

# Basic steps to add/alter code

1. git checkout -b \<feature_branch_name\> (Create and switch to
feature branch)
2. make changes, test changes, document changes, commit often
3. run tests: pytest, python manage.py test
4. test coverage: (see above)
5. type checks: mypy gregor_django
6. git add your changes
7. manually run pre-commit if you did not install
8. git commit your changes
9. repeat steps 3-8
10. merge in any changes to main
1. git checkout main
2. git pull
3. git checkout \<feature_branch_name\>
4. git rebase main
10. git push origin \<feature_branch_name\>
11. review or request review of changes in github
12. submit pull request in github
## Basic steps to add/alter code

- git checkout -b \<feature_branch_name\> (Create and switch to feature branch)
- sync requirements: `pip-sync requirements/requirements.txt test-requirements.txt dev-requirements.txt`
- make changes, test changes, document changes, commit often
- run tests: `pytest`, `python manage.py test`
- test coverage: (see above)
- type checks: `mypy gregor_django`
- git add your changes
- manually run pre-commit if you did not install
- git commit your changes
- repeat steps 3-8
- merge in any changes to main
- git checkout main
- git pull
- git checkout \<feature_branch_name\>
- git rebase main
- git push origin \<feature_branch_name\>
- review or request review of changes in github
- submit pull request in github

## Compiling requirements files

Requriements files must be compiled in the correct order to handle layering.

```
cd requirements/
pip-compile requirements.in
pip-compile test-requirements.in
pip-compile dev-requirements.in
```
30 changes: 0 additions & 30 deletions requirements/base.txt

This file was deleted.

30 changes: 30 additions & 0 deletions requirements/dev-requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-c requirements.txt
-c test-requirements.txt

Werkzeug # https://github.com/pallets/werkzeug
ipdb # https://github.com/gotcha/ipdb

# Testing
# ------------------------------------------------------------------------------
mypy # https://github.com/python/mypy
django-stubs # https://github.com/typeddjango/django-stubs

# Documentation
# ------------------------------------------------------------------------------
# 7.2 drops support for Python 3.8
sphinx # https://github.com/sphinx-doc/sphinx
sphinx-autobuild # https://github.com/GaretJax/sphinx-autobuild

# Code quality
# ------------------------------------------------------------------------------
flake8 # https://github.com/PyCQA/flake8
flake8-isort # https://github.com/gforcada/flake8-isort
black # https://github.com/psf/black
pylint-django # https://github.com/PyCQA/pylint-django
pre-commit # https://github.com/pre-commit/pre-commit

# Security
# ------------------------------------------------------------------------------
safety # https://github.com/pyupio/safety

django-debug-toolbar # https://github.com/jazzband/django-debug-toolbar
Loading

0 comments on commit dfc4f8b

Please sign in to comment.