Skip to content

Commit

Permalink
move tracker files to better python structure [#170916197] (GamesDone…
Browse files Browse the repository at this point in the history
…Quick#203)

make an actual Python package

[#170916197]
  • Loading branch information
uraniumanchor authored Sep 11, 2020
1 parent f49e807 commit fe92e55
Show file tree
Hide file tree
Showing 245 changed files with 309 additions and 276 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build
.webpack_build_cache/
*.manifest.json
node_modules/
static/gen/
dist/
tracker/static/gen/
yarn-error.log
TEST*.xml
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
static/
tracker/static/
123 changes: 111 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,122 @@
See setup instructions in the top level repository: https://github.com/GamesDoneQuick/donation-tracker-toplevel
# Django Donation Tracker

## Contributing
## Requirements

### `pre-commit`
- Python 3.6, 3.7 (3.8 is untested)

This project uses [`pre-commit`](https://pre-commit.com/) to run linters and other checks before every commit.
Additionally, if you are planning on developing, and/or building the JS bundles yourself:

- Node 12.x
- `yarn` (`npm i -g yarn`)
- `pre-commit` (`pip install pre-commit`)

If you need to isolate your development environment, some combination of `direnv`, `pyenv`, `nvm`, and/or `asdf` will be
very helpful.

## Deploying

This app shouldn't require any special treatment to deploy. You should be able to install it with pip, either from PyPI
(preferred so that you don't have to build the JS bundles yourself), GitHub, or locally.

For further reading on what else your server needs to look like:

- [Deploying Django](https://docs.djangoproject.com/en/2.2/howto/deployment/)
- [Deploying Django Channels](https://channels.readthedocs.io/en/latest/deploying.html)

Docker should also work but support is still in the experimental phases.

## Development Quick Start

`pre-commit` has been added as part of `requirements.txt`, so new installs should automatically get it, but if not, you can get it manually with pip, and then install the hooks with the `pre-commit` binary.
Start up a new Django Project like the [Django Tutorial](https://docs.djangoproject.com/en/2.2/intro/tutorial01/).

- `pip install django~=2.2`
- `django-admin startproject tracker_development`
- `cd tracker_development`

Clone the Git repo and install it in edit mode:

- `git clone [email protected]:GamesDoneQuick/donation-tracker`
- `pip install -e donation-tracker`

Install remaining development dependencies:

- `cd donation-tracker`
- `yarn`
- `pre-commit install`
- `pre-commit install --hook-type pre-push`

Add the following apps to the `INSTALLED_APPS` section of `tracker_development/settings.py`:

```
pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-push
'channels',
'post_office',
'paypal.standard.ipn',
'tracker',
'timezone_field',
'ajax_select',
'mptt',
```

And now every time you `git commit` or `git push`, the appropriate checks will run!
Add the following chunk somewhere in `settings.py`:

_Note:_ You _can_ bypass these checks by adding `--no-verify` when you commit or push, though this is highly discouraged in most cases. In the future, CI tests may fail if any of these checks are not satisfied.
```python
from tracker import ajax_lookup_channels
AJAX_LOOKUP_CHANNELS = ajax_lookup_channels.AJAX_LOOKUP_CHANNELS
ASGI_APPLICATION = 'tracker_development.routing.application'
CHANNEL_LAYERS = {'default': {'BACKEND': 'channels.layers.InMemoryChannelLayer'}}
```

Create a file next called `routing.py` next to `settings.py` and put the following in it:

If the pre-commit hooks fail on your first commit with them, make sure you are not inside of a submodule! This can affect where `pre-commit` tries to install hooks, and cloning the tools (specifically, `black`) can cause an error.
```python
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.urls import path

To avoid this, clone this repo separately to a new folder (not as a submodule), run `pre-commit install`, and make a fake commit to get the environment tools installed. These tools are globalized, so going back and committing from the submodule copy should now work!
import tracker.routing

application = ProtocolTypeRouter({
'websocket': AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
[path('tracker/', URLRouter(tracker.routing.websocket_urlpatterns))]
)
)
),
})
```

Edit the `tracker_development/urls.py` file to look something like this:

```python
from django.contrib import admin
from django.urls import path, include

import tracker.urls
import ajax_select.urls

urlpatterns = [
path('admin/', admin.site.urls),
path('admin/lookups/', include(ajax_select.urls)),
path('tracker/', include(tracker.urls, namespace='tracker')),
]
```

In the main project folder:

- `python manage.py runserver`

In a separate shell, in the `donation-tracker` folder:

- `yarn start`

If everything boots up correctly, you should be able to visit the [Index Page](http://localhost:8080/tracker). Additionally, you should be able to open the [Websocket Test Page](http://localhost:8080/tracker/websocket_test/) and see the heartbeat. If the page loads but the pings don't work, Channels isn't set up correctly. The [Channels Documentation](https://channels.readthedocs.io/en/latest/installation.html) may be helpful.

## Contributing

This project uses [`pre-commit`](https://pre-commit.com/) to run linters and other checks before every commit.

If you followed the instructions above, `pre-commit` should run the appropriate hooks every time you commit or push.

_Note:_ You _can_ bypass these checks by adding `--no-verify` when you commit or push, though this is highly discouraged in most cases. In the future, CI tests may fail if any of these checks are not satisfied.
75 changes: 28 additions & 47 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,35 @@ jobs:
Python37:
PYTHON_VERSION: '3.7'

variables:
TOPLEVEL_REVISION: e170b3970c805b4b0c9cb9167c57c78d62f27dd5

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(PYTHON_VERSION)'
architecture: 'x64'

- script: |
mv -v $(Build.SourcesDirectory) $(Agent.BuildDirectory)/tracker
git clone git://github.com/GamesDoneQuick/donation-tracker-toplevel $(Build.SourcesDirectory)
cd $(Build.SourcesDirectory)
git reset --hard $(TOPLEVEL_REVISION)
mv -v $(Agent.BuildDirectory)/tracker $(Build.SourcesDirectory)
cp -v tracker/ci/.env.ci $(Build.SourcesDirectory)/.env
displayName: 'Install toplevel around the tracker'
- task: PythonScript@0
displayName: 'Export project path'
inputs:
scriptSource: 'inline'
script: |
"""Search all subdirectories for `manage.py`."""
from glob import iglob
from os import path
manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
if not manage_py:
raise SystemExit('Could not find a Django project')
project_location = path.dirname(path.abspath(manage_py))
print('Found Django project in', project_location)
print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))
- task: CacheBeta@1
inputs:
key: pip | $(Agent.OS) | tracker/requirements.txt
key: pip | $(Agent.OS) | requirements.txt | setup.py
path: $(Pipeline.Workspace)/../../.cache/pip
displayName: 'Cache pip'

- script: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install -r tracker/tests/requirements.txt
displayName: 'Install python prerequisites'
- task: CacheBeta@1
inputs:
key: yarn | $(Agent.OS) | tracker/yarn.lock
path: $(Build.SourcesDirectory)/tracker/node_modules
key: yarn | $(Agent.OS) | production | yarn.lock
path: $(Build.SourcesDirectory)/node_modules
displayName: 'Cache yarn'

- script: |
cd tracker
yarn install --frozen-lockfile
displayName: 'Install node prerequisites'
python -m pip install --upgrade pip setuptools wheel
pip install -e .
pip install -r tests/requirements.txt
displayName: 'Install python prerequisites'
- script: |
cd tracker
python check_migrations.py
displayName: 'Check for bad or missing migrations'
- script: |
cd tracker
yarn build
displayName: 'Generate webpack manifest'
- script: |
cd tracker
python runtests.py --parallel --no-input
displayName: 'Run Django tests'
Expand All @@ -92,6 +53,26 @@ jobs:
testRunTitle: 'Python $(PYTHON_VERSION)'
condition: succeededOrFailed()

- job: build_package
displayName: Tracker Package
steps:
- task: CacheBeta@1
inputs:
key: pip | $(Agent.OS) | requirements.txt | setup.py
path: $(Pipeline.Workspace)/../../.cache/pip
displayName: 'Cache pip'

- task: CacheBeta@1
inputs:
key: yarn | $(Agent.OS) | production | yarn.lock
path: $(Build.SourcesDirectory)/node_modules
displayName: 'Cache yarn'

- script: |
python -m pip install --upgrade pip setuptools wheel
python setup.py package
displayName: 'Build Package'
- job: tracker_frontend_tests
dependsOn: []
displayName: Tracker Frontend
Expand All @@ -102,7 +83,7 @@ jobs:
steps:
- task: Cache@2
inputs:
key: yarn | $(Agent.OS) | yarn.lock
key: yarn | $(Agent.OS) | development | yarn.lock
path: $(YARN_CACHE_FOLDER)
displayName: 'Cache yarn'

Expand Down
13 changes: 0 additions & 13 deletions ci/.env.ci

This file was deleted.

22 changes: 0 additions & 22 deletions commandutil.py

This file was deleted.

10 changes: 0 additions & 10 deletions context_processors.py

This file was deleted.

Loading

0 comments on commit fe92e55

Please sign in to comment.