-
Notifications
You must be signed in to change notification settings - Fork 64
Development Setup
Mathieu Rampant edited this page Apr 3, 2024
·
18 revisions
For Windows Users, it is recommended to install all the programs as Administrator
- Check if you have Python (3.6+) installed by running
python --version
- If you don't have python on your system, download the latest version on Python's Website
- Install it. Make sure to check "Add Python to PATH" on Windows
- Check if you have git installed by running
git --version
- If you don't have it already, install Git using
apt-get install git
,dnf install git
oryum install git
. If you are running MacOS, simply rungit --version
and it should prompt you to install it If you are running Windows, I recommend installing git bash
- Go to Pycharm Download Page
- Download the right version of Pycharm for your system
- Install it
- Start Pycharm and select "Checkout from Version Control", then select "Git"
- Use the following parameters:
- URL:
https://github.com/usnistgov/NEMO.git
- Directory: <the directory where you want NEMO's code to be>
- The code should now be downloaded and the project should be available in Pycharm
- Go to "File -> Settings" (windows) or "Pycharm -> Preferences" on MacOS
- Go to "Project: NEMO -> Project Interpreter"
- Click on "No Interpreter" then "Show All..."
- Click on "+" to create a new interpreter.
- Select "Virtualenv Environment". Base Interpreter should be already selected as the version you installed in step 1
- Click "Ok"
Starting in version 5.0.0, NEMO uses Black for python formatting. In order to have your code style checked automatically:
- In the bottom of the Pycharm IDE, click "Terminal"
- Execute
pip install black
to install Black on NEMO VirtualEnv - Then either set it up in Pycharm or use pre-commit hooks
- To set it up directly in Pycharm:
- Go to "File -> Settings" (windows) or "Pycharm -> Preferences" on MacOS.
- Go to "Editor -> Code Style -> Python" and uncheck "use tab character"
- Go to "Tools -> Black" or "Tools -> Actions on Save -> Black -> Configure" and
- Enable the two check-boxes under "Use Black formatter:"
- Add
--line-length=120
in the "Settings" field
- Click "OK"
Starting in version 5.4.0, NEMO uses djLint for html formatting. In order to have your code style checked automatically:
- In the bottom of the Pycharm IDE, click "Terminal"
- Execute
pip install djlint
to install djLint on NEMO VirtualEnv - Run
djlint . --reformat --max-attribute-length=100 --max-line-length=120
after making changes to html files or use pre-commit hooks (see below)
To make code formatting easier, it is recommended to set up pre-commit hooks to have both python and html files automatically formatted.
- In the bottom of the Pycharm IDE, click "Terminal"
- Execute
pip install pre-commit black djlint
orpip install ./["dev-tools"]
to install pre-commit and the other tools on NEMO VirtualEnv - Enable hooks by running
pre-commit install
- To run pre-commit hooks on all files, run
pre-commit run --all-files
- In the left side panel, right click on the main NEMO folder (not NEMO -> NEMO subfolder) and select "New -> Python File"
- Enter the name
settings
and confirm. - In the settings.py file, if you see a notification to install package requirements, do it.
- In settings.py, paste the settings from Settings
- Make sure you have in settings.py:
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DEBUG = True
-
'NEMO.middleware.RemoteUserAuthenticationMiddleware'
is in middleware - Uncomment
AUTHENTICATION_BACKENDS = ['NEMO.views.authentication.RemoteUserAuthenticationBackend']
ALLOWED_HOSTS = ['localhost']
- use file email backend with
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'email_sink/')
- database with name
'NAME': os.path.join(BASE_DIR, 'nemo.db'),
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'resources/icons')
- for file logging, use
"filename": os.path.join(BASE_DIR, "nemo.log"),
- for error_file logging, use
"filename": os.path.join(BASE_DIR, "nemo_error.log"),
- in the bottom of the Pycharm IDE, click "Terminal"
- execute
pip install .
(this step can take several minutes) - execute
python manage.py migrate
- execute
python manage.py loaddata ./resources/fixtures/splash_pad.json
- In the top right corner of Pycharm, click "Add Configuration..."
- Click "+" and select "Python", then enter the following:
- "Name":
start nemo
- "Script Path":
manage.py
- "Parameters":
runserver localhost:8000
- In "Environment Variables", add
REMOTE_USER
key and valuecaptain
- In "working directory", select the NEMO folder
- Click "Apply"
You can now run your saved configuration and access NEMO at http://localhost:8000
If you want to login as someone else, simply change the REMOTE_USER environment variable to another username (like "ned" or "professor")