mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-19 23:35:04 +01:00
[FIX] Grammar and spelling
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
# Development on Windows 10 with WSL and Visual Studio Code
|
||||
|
||||
This document describes step-by-step how to setup a complete development environment for Alliance Auth apps on Windows 10 with Windows Subsystem for Linux (WSL) and Visual Studio Code.
|
||||
This document describes step-by-step how to set up a complete development environment for Alliance Auth apps on Windows 10 with Windows Subsystem for Linux (WSL) and Visual Studio Code.
|
||||
|
||||
The main benefit of this setup is that it runs all services and code in the native Linux environment (WSL) and at the same time can be full controlled from within a comfortable Windows IDE (Visual Studio Code) including code debugging.
|
||||
The main benefit of this setup is that it runs all services and code in the native Linux environment (WSL) and at the same time can be fully controlled from within a comfortable Windows IDE (Visual Studio Code) including code debugging.
|
||||
|
||||
In addition all tools described in this guide are open source or free software.
|
||||
In addition, all tools described in this guide are open source or free software.
|
||||
|
||||
:::{hint}
|
||||
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation please see chapter **Installation**.
|
||||
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation, please see chapter **Installation**.
|
||||
:::
|
||||
|
||||
## Overview
|
||||
|
||||
The development environment consists of the following components:
|
||||
|
||||
- Visual Studio Code with Remote WSL and Python extension
|
||||
- Visual Studio Code with the Remote WSL and Python extension
|
||||
- WSL with Ubuntu (18.04. LTS or higher)
|
||||
- Python environment on WSL (3.8 or higher)
|
||||
- MySQL server on WSL
|
||||
@@ -22,15 +22,15 @@ The development environment consists of the following components:
|
||||
- Alliance Auth on WSL
|
||||
- Celery on WSL
|
||||
|
||||
We will use the build-in Django development web server, so we don't need to setup a WSGI server or a web server.
|
||||
We will use the build-in Django development web server, so we don't need to set up a WSGI server or a web server.
|
||||
|
||||
:::{note}
|
||||
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance we recommend WSL 2.
|
||||
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance, we recommend WSL 2.
|
||||
:::
|
||||
|
||||
## Requirement
|
||||
|
||||
The only requirement is a PC with Windows 10 and Internet connection in order to download the additional software components.
|
||||
The only requirement is a PC with Windows 10 and Internet connection to download the additional software components.
|
||||
|
||||
## Installing Windows apps
|
||||
|
||||
@@ -45,7 +45,7 @@ The only requirement is a PC with Windows 10 and Internet connection in order to
|
||||
- Open the app and install the following VSC extensions:
|
||||
- Remote WSL
|
||||
- Connect to WSL. This will automatically install the VSC server on the VSC server for WSL
|
||||
- Once connected to WSL install the Python extension on the WSL side
|
||||
- Once connected to WSL, install the Python extension on the WSL side
|
||||
|
||||
## Setting up WSL / Linux
|
||||
|
||||
@@ -64,13 +64,13 @@ sudo apt-get install gettext
|
||||
|
||||
### Install Python
|
||||
|
||||
Next we need to install Python and related development tools.
|
||||
Next, we need to install Python and related development tools.
|
||||
|
||||
:::{note}
|
||||
Should your Ubuntu come with a newer version of Python we recommend to still setup your dev environment with the oldest Python 3 version currently supported by AA (e.g Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
|
||||
You an check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
|
||||
Should your Ubuntu come with a newer version of Python we recommend to still set up your dev environment with the oldest Python 3 version currently supported by AA (e.g., Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
|
||||
You can check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
|
||||
|
||||
If you install a different python version from the default you need to adjust some of the commands below to install appopriate versions of those packages for example using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
|
||||
If you install a different python version from the default, you need to adjust some commands below to install appopriate versions of those packages, for example, using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
|
||||
|
||||
```shell
|
||||
sudo apt-get install python3.8 python3.8-dev python3.8-venv python3-setuptools python3-pip python-pip
|
||||
@@ -108,7 +108,7 @@ sudo apt-get install mysql-server mysql-client libmysqlclient-dev
|
||||
We chose to use MySQL instead of MariaDB, because the standard version of MariaDB that comes with this Ubuntu distribution will not work with AA.
|
||||
:::
|
||||
|
||||
We need to apply a permission fix to mysql or you will get a warning with every startup:
|
||||
We need to apply a permission fix to mysql, or you will get a warning with every startup:
|
||||
|
||||
```shell
|
||||
sudo usermod -d /var/lib/mysql/ mysql
|
||||
@@ -120,7 +120,7 @@ Start the mysql server
|
||||
sudo service mysql start
|
||||
```
|
||||
|
||||
Create database and user for AA
|
||||
Create a database and user for AA
|
||||
|
||||
```shell
|
||||
sudo mysql -u root
|
||||
@@ -141,7 +141,7 @@ sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
|
||||
```
|
||||
|
||||
:::{note}
|
||||
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine and you have to manually start them. For convenience we recommend putting these commands in a bash script. Here is an example:
|
||||
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine, and you have to manually start them. For convenience, we recommend putting these commands in a bash script. Here is an example:
|
||||
|
||||
```shell
|
||||
#/bin/bash
|
||||
@@ -154,7 +154,7 @@ sudo redis-server --daemonize yes
|
||||
|
||||
### Setup dev folder on WSL
|
||||
|
||||
Setup your folders on WSL bash for your dev project. Our approach will setup one AA project with one venv and multiple apps running under the same AA project, but each in their own folder and git.
|
||||
Set up your folders on WSL bash for your dev project. Our approach will set up one AA project with one venv and multiple apps running under the same AA project, but each in their own folder and git.
|
||||
|
||||
A good location for setting up this folder structure is your home folder or a subfolder of your home:
|
||||
|
||||
@@ -167,7 +167,7 @@ A good location for setting up this folder structure is your home folder or a su
|
||||
|- ...
|
||||
```
|
||||
|
||||
Following this approach you can also setup additional AA projects, e.g. aa-dev-2, aa-dev-3 if needed.
|
||||
Following this approach, you can also set up additional AA projects, e.g. aa-dev-2, aa-dev-3 if needed.
|
||||
|
||||
Create the root folder `aa-dev`.
|
||||
|
||||
@@ -203,13 +203,13 @@ pip install -U pip setuptools wheel
|
||||
pip install allianceauth
|
||||
```
|
||||
|
||||
Now we are ready to setup our AA instance. Make sure to run this command in your aa-dev folder:
|
||||
Now we are ready to set up our AA instance. Make sure to run this command in your aa-dev folder:
|
||||
|
||||
```shell
|
||||
allianceauth start myauth
|
||||
```
|
||||
|
||||
Next we will setup our VSC project for aa-dev by starting it directly from the WSL bash:
|
||||
Next, we will set up our VSC project for aa-dev by starting it directly from the WSL bash:
|
||||
|
||||
```shell
|
||||
code .
|
||||
@@ -217,11 +217,11 @@ code .
|
||||
|
||||
First you want to make sure exclude the venv folder from VSC as follows:
|
||||
Open settings and go to Files:Exclude
|
||||
Add pattern: `**/venv`
|
||||
Add the pattern: `**/venv`
|
||||
|
||||
### Create EVE Online SSO App
|
||||
|
||||
For the Eve Online related setup you need to create a SSO app on the developer site:
|
||||
For the Eve Online related setup you need to create an SSO app on the developer site:
|
||||
|
||||
- Create your Eve Online SSO App on the [Eve Online developer site](https://developers.eveonline.com/)
|
||||
- Add all ESI scopes
|
||||
@@ -277,7 +277,7 @@ REGISTRATION_VERIFY_EMAIL = False
|
||||
|
||||
### Migrations and superuser
|
||||
|
||||
Before we can start AA we need to run migrations:
|
||||
Before we can start AA, we need to run migrations:
|
||||
|
||||
```shell
|
||||
cd myauth
|
||||
@@ -300,7 +300,7 @@ We are now ready to run out AA instance with the following command:
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
Once running you can access your auth site on the browser under `http://localhost:8000`. Or the admin site under `http://localhost:8000/admin`
|
||||
Once running, you can access your auth site on the browser under `http://localhost:8000`. Or the admin site under `http://localhost:8000/admin`
|
||||
|
||||
:::{hint}
|
||||
You can start your AA server directly from a terminal window in VSC or with a VSC debug config (see chapter about debugging for details).
|
||||
@@ -308,14 +308,14 @@ You can start your AA server directly from a terminal window in VSC or with a VS
|
||||
|
||||
:::{note}
|
||||
**Debug vs. Non-Debug mode**
|
||||
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that helps a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
|
||||
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that help a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
|
||||
|
||||
When you turn off debug mode you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Just start your server with the following option: ``python manage.py runserver --insecure``
|
||||
When you turn off debug mode, you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Start your server with the following option: ``python manage.py runserver --insecure``
|
||||
:::
|
||||
|
||||
### Celery
|
||||
|
||||
In addition you can start a celery worker instance for myauth. For development purposed it makes sense to only start one instance and add some additional logging.
|
||||
In addition, you can start a celery worker instance for myauth. For development purposes, it makes sense to only start one instance and add some additional logging.
|
||||
|
||||
This can be done from the command line with the following command in the myauth folder (where manage.py is located):
|
||||
|
||||
@@ -323,21 +323,21 @@ This can be done from the command line with the following command in the myauth
|
||||
celery -A myauth worker -l info -P solo
|
||||
```
|
||||
|
||||
Same as AA itself you can start Celery from any terminal session, from a terminal window within VSC or as a debug config in VSC (see chapter about debugging for details). For convenience we recommend starting Celery as debug config.
|
||||
Same as AA itself, you can start Celery from any terminal session, from a terminal window within VSC or as a debug config in VSC (see chapter about debugging for details). For convenience, we recommend starting Celery as debug config.
|
||||
|
||||
## Debugging setup
|
||||
|
||||
To be able to debug your code you need to add debugging configuration to VSC. At least one for AA and one for celery.
|
||||
To be able to debug your code, you need to add a debugging configuration to VSC. At least one for AA and one for celery.
|
||||
|
||||
### Breakpoints
|
||||
|
||||
By default VSC will break on any uncaught exception. Since every error raised by your tests will cause an uncaught exception we recommend to deactivate this feature.
|
||||
By default, VSC will break on any uncaught exception. Since every error raised by your tests will cause an uncaught exception, we recommend deactivating this feature.
|
||||
|
||||
To deactivate open click on the debug icon to switch to the debug view. Then un-check "Uncaught Exceptions" on the breakpoints window.
|
||||
To deactivate, click on the debug icon to switch to the debug view. Then uncheck "Uncaught Exceptions" in the "Breakpoints" window.
|
||||
|
||||
### AA debug config
|
||||
|
||||
In VSC click on Debug / Add Configuration and choose "Django". Should Django not appear as option make sure to first open a Django file (e.g. the local.py settings) to help VSC detect that you are using Django.
|
||||
In VSC, click on Debug / Add Configuration and choose "Django". Should Django not appear as an option, make sure to first open a Django file (e.g., the local.py settings) to help VSC detect that you are using Django.
|
||||
|
||||
The result should look something like this:
|
||||
|
||||
@@ -359,7 +359,7 @@ The result should look something like this:
|
||||
|
||||
### Debug celery
|
||||
|
||||
For celery we need another debug config, so that we can run it in parallel to our AA instance.
|
||||
For celery, we need another debug config, so that we can run it in parallel to our AA instance.
|
||||
|
||||
Here is an example debug config for Celery:
|
||||
|
||||
@@ -387,7 +387,7 @@ Here is an example debug config for Celery:
|
||||
|
||||
### Debug config for unit tests
|
||||
|
||||
Finally it makes sense to have a dedicated debug config for running unit tests. Here is an example config for running all tests of the app `example`.
|
||||
Finally, it makes sense to have a dedicated debug config for running unit tests. Here is an example config for running all tests of the app `example`.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -407,11 +407,11 @@ Finally it makes sense to have a dedicated debug config for running unit tests.
|
||||
},
|
||||
```
|
||||
|
||||
You can also specify to run just a part of your test suite down to a test method. Just give the full path to the test you want to run, e.g. `example.test.test_models.TestDemoModel.test_this_method`
|
||||
You can also specify to run just a part of your test suite down to a test method. Give the full path to the test you want to run, e.g. `example.test.test_models.TestDemoModel.test_this_method`
|
||||
|
||||
### Debugging normal python scripts
|
||||
|
||||
Finally you may also want to have a debug config to debug a non-Django Python script:
|
||||
Finally, you may also want to have a debug config to debug a non-Django Python script:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -447,39 +447,37 @@ Extension for Visual Studio Code - Markdown linting and style checking for Visua
|
||||
|
||||
#### Live Server
|
||||
|
||||
Live Server allows you to start a mini webserver for any file quickly. This can e.g. be useful for looking at changes to to Sphinx docs.: [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
|
||||
Live Server allows you to start a mini webserver for any file quickly. This can e.g. be useful for looking at changes to Sphinx docs.: [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
|
||||
|
||||
### Django apps
|
||||
|
||||
#### Django Extensions
|
||||
|
||||
[django-extensions](https://django-extensions.readthedocs.io/en/latest/) is a swiss army knife for django developers with adds a lot of very useful features to your Django site. Here are a few highlights:
|
||||
[django-extensions](https://django-extensions.readthedocs.io/en/latest/) is a swiss army knife for django developers with adds a lot of useful features to your Django site. Here are a few highlights:
|
||||
|
||||
- shell_plus - An enhanced version of the Django shell. It will auto-load all your models at startup so you don't have to import anything and can use them right away.
|
||||
- graph_models - Creates a dependency graph of Django models. Visualizing a model dependency structure can be very useful for trying to understand how an existing Django app works, or e.g. how all the AA models work together.
|
||||
- runserver_plus - The standard runserver stuff but with the Werkzeug debugger baked in. This is a must have for any serious debugging.
|
||||
- `shell_plus` - An enhanced version of the Django shell. It will autoload all your models at startup, so you don't have to import anything and can use them right away.
|
||||
- `graph_models` - Creates a dependency graph of Django models. Visualizing a model dependency structure can be useful for trying to understand how an existing Django app works, or e.g., how all the AA models work together.
|
||||
- `runserver_plus` - The standard runserver stuff but with the debugger baked in. This is a must-have for any serious debugging.
|
||||
|
||||
#### Django Debug Toolbar
|
||||
|
||||
The [Django Debug Toolbar](https://github.com/jazzband/django-debug-toolbar) is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.
|
||||
|
||||
E.g. this tool is invaluable to debug and fix performance issues with Django queries.
|
||||
The [Django Debug Toolbar](https://github.com/jazzband/django-debug-toolbar) is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content. This tool is invaluable to debug and fix performance issues with Django queries.
|
||||
|
||||
### Windows applications
|
||||
|
||||
#### DBeaver
|
||||
|
||||
DBeaver is a free universal database tool and works with many different kinds of databases include MySQL. It can be installed on Windows 10 and will be able to help manage your MySQL databases running on WSL.
|
||||
DBeaver is a free universal database tool and works with many different kinds of databases including MySQL. It can be installed on Windows 10 and will be able to help manage your MySQL databases running on WSL.
|
||||
|
||||
Install from here. [DBeaver](https://dbeaver.io/)
|
||||
|
||||
## Adding apps for development
|
||||
|
||||
The idea behind the particular folder structure of aa-dev is to have each and every app in its own folder and git repo. To integrate them with the AA instance they need to be installed once using the -e option that enabled editing of the package. And then added to the INSTALLED_APPS settings.
|
||||
The idea behind the particular folder structure of aa-dev is to have each and every app in its own folder and git repo. To integrate them with the AA instance, they need to be installed once using the -e option that enabled editing of the package. And then added to the INSTALLED_APPS settings.
|
||||
|
||||
To demonstrate let's add the example plugin to our environment.
|
||||
To demonstrate, let's add the example plugin to our environment.
|
||||
|
||||
Open a WSL bash and navigate to the aa-dev folder. Make sure you have activate your virtual environment. (`source venv/bin/activate`)
|
||||
Open a WSL bash and navigate to the aa-dev folder. Make sure you have activated your virtual environment. (`source venv/bin/activate`)
|
||||
|
||||
Run these commands:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user