Skip to content

Set up local environment

Bruno Lajoie edited this page Nov 27, 2022 · 27 revisions

Setup Python development environment

  1. Ensure you are using Python Python 3.8 (We recommend using pyenv to handle different Python versions.)

  2. Ensure you have the dependency management tool Poetry installed by this guide. The easiest is to do pip install poetry

  3. Ensure you have the dependency tool tesseract installed, following the instructions in this guide.

  4. From the root folder, install the dependencies in a virtual environment:

    poetry install -E parsers
    

You can now run a few different commands:

poetry run lint # linting
poetry run test # run unit tests
poetry run check # run both linting and tests

You might need to have zlib and libjpeg installed on your machine.

To ensure all dependencies required by opencv are installed, you can run apt-get update && apt-get install -y python3-opencv

Having problems?

First up, make sure you're using Python 3.8. Also, see Troubleshooting for fixes to common issues.

If it's still not working, please create an issue where you include the output from poetry debug so that we can help debug it.

Setup frontend environment

  1. Ensure you have nodejs 14.15 or higher installed.

  2. Run:

    npm install --global yarn
  3. In the web folder run:

    yarn install
  4. Do the same from the mockserver folder:

    yarn install

Running the frontend map

There are two ways to run the frontend map the quickest and easiest way is to use snowpack and the second way is to use the docker container.

Snowpack

  1. Run the following command in the web folder:

    yarn run develop
  2. Go to http://localhost:8080/ and you should see the map!

  3. Color the map by opening a new terminal in the web folder and starting the mockserver with the following command:

    yarn run mockserver

Docker

  1. Install docker

  2. First, you need to compile the frontend. Open a terminal in the root directory and run:

    docker-compose build
    
  3. Start the application by running:

    docker-compose up
    

    This will watch over source file changes, run nonstop and watch changes you make in the code to recompile the frontend if needed.

  4. Go to http://localhost:8000/ and you should now see the map!

  5. You can run the mockserver to color the map by running from the mockserver folder:

    yarn run start
    

Notes:

  • The backend handles the calculation of carbon emissions. The map data from the mock server provides dummy data from the state file.

See Troubleshooting for common issues and fixes when building the map locally.

Code formatting

Your code contributions can't be merged with the codebase unless they respect the electricityMap contrib code formatting.

To check whether you code respects the formatting, you can run the following commands:

Python

poetry run check

If you see that your code fails the formatting check, you can autoformat it by running:

poetry run format

JavaScript, JSON, CSS, YML and more:

npx prettier --check .

And if the check fails you can run the following command to fix it:

npx prettier --write .
Clone this wiki locally