Development Setup - usnistgov/NEMO GitHub Wiki
For Windows Users, it is recommended to install all the programs as Administrator
Download and Install Python
- 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
Download and Install Git
- 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 gitoryum install git. If you are running MacOS, simply rungit --versionand it should prompt you to install it If you are running Windows, I recommend installing git bash
Download and Install Pycharm
- Go to Pycharm Download Page
- Download the right version of Pycharm for your system
- Install it
Checkout NEMO github
- 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
Add Python Interpreter for NEMO
- 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"
Enable Python Formatting with black
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 blackto 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=120in the "Settings" field
- Click "OK"
Enable HTML Formatting with djlint
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 djlintto install djLint on NEMO VirtualEnv - Run
djlint . --reformat --max-attribute-length=100 --max-line-length=120after making changes to html files or use pre-commit hooks (see below)
Set up pre-commit hooks
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 djlintorpip 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
Create Settings for NEMO
- In the left side panel, right click on the main NEMO folder (not NEMO -> NEMO subfolder) and select "New -> Python File"
- Enter the name
settingsand 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 osBASE_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"),
Initialize NEMO and populate database
- 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
Start NEMO
- 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_USERkey 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")