Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding dev container config #1

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c77f716
adding dev container config
drifter089 Oct 10, 2024
b076ea3
updated docekr file
drifter089 Oct 10, 2024
96d333b
updated docker file
drifter089 Oct 10, 2024
151bc2d
update: include java
GbotemiB Oct 14, 2024
05cf1c4
docker docs init
GbotemiB Oct 14, 2024
0d65aac
review welcome message for new users
GbotemiB Oct 14, 2024
a3d22ca
running tutorial before push
drifter089 Oct 21, 2024
952583a
fixing clone command in CI
drifter089 Oct 21, 2024
9a1fb06
fixing variable value
drifter089 Oct 21, 2024
ad189c5
Fix issue of adding H2 store in `add_extra_components` rule (#1134)
yerbol-akhmetov Oct 15, 2024
fffe9c7
[pre-commit.ci] pre-commit autoupdate (#1131)
pre-commit-ci[bot] Oct 16, 2024
ed8e300
Add a restriction to rasterio version (#1146)
ekatef Oct 16, 2024
95e0aab
Enable configfile specification for mock_snakemake (#1135)
yerbol-akhmetov Oct 16, 2024
fb5c61b
update: set env file required for cluster network
GbotemiB Oct 22, 2024
4fc5fc3
update: include mac into the CI
GbotemiB Oct 28, 2024
b54eacd
adding user as secret
drifter089 Oct 29, 2024
5a6e210
delete duplicate file and add user as secret
drifter089 Oct 29, 2024
8abaa7b
setup docekr on macos
drifter089 Oct 29, 2024
a2f570e
trying colima for docekr setup on mac
drifter089 Oct 29, 2024
9f4a0bf
adding mac docker setup
drifter089 Oct 29, 2024
928195e
installing colima on mac
drifter089 Oct 29, 2024
d50db33
disable buildkit for docker
drifter089 Oct 29, 2024
781f8ee
add buildx plugin
drifter089 Oct 29, 2024
d6188d2
include documentation for using docker container
GbotemiB Nov 6, 2024
49e5c5f
update docker docs
GbotemiB Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "pypsa earth dev",
"image": "ghcr.io/drifter089/pypsa-earth:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind,consistency=cached",
"initializeCommand": "docker pull ghcr.io/drifter089/pypsa-earth:latest",
"workspaceFolder": "/workspaces",
"postAttachCommand": "bash .devcontainer/setup.sh"
}
6 changes: 6 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# mv ../pypsa-eur/* ./
# echo 'solved tutorial files are copied to workspace'

cat .devcontainer/welcome-message.txt
21 changes: 21 additions & 0 deletions .devcontainer/welcome-message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@




👋 Welcome to the PyPSA-Earth Development Environment!

We’re excited to have you here! This setup allows you to contribute to PyPSA-Earth effortlessly using a development container in VS Code.

📖 Getting Started for New Users

• For a step-by-step guide on setting up your environment, debugging, and making your first contribution, refer to the PyPSA-Earth README. It covers everything you need to know as a newcomer.
• The configuration files for the development container are located in the .github/.devcontainer folder.

💡 Tips for New Users

• Make the most of VS Code by using the Command Palette (Cmd/Ctrl + Shift + P or F1) for quick access to features and commands.
• If you’re new to development containers, learn the basics at containers.dev.

🚀 Start Exploring and Happy Coding!

Don’t hesitate to reach out if you need help—our community is here to support you.
33 changes: 33 additions & 0 deletions .github/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "pypsa earth dev",
"build": {
"dockerfile": "../../Dockerfile"
},

"features": {
"ghcr.io/devcontainers-contrib/features/bash-command:1": {},
"ghcr.io/eliises/devcontainer-features/bash-profile:1": {}
},
"customizations": {
"vscode": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"ms-toolsai.jupyter",
"zainchen.json",
"tomoki1207.pdf",
"grapecity.gc-excelviewer"
]
}
},

"postCreateCommand": "python -m pip install --upgrade debugpy"
}
5 changes: 5 additions & 0 deletions .github/.devcontainer/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cp config.tutorial.yaml config.yaml

snakemake -j 1 solve_all_networks
63 changes: 63 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Dev Container Build and Push Image

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "v*.*.*"
pull_request:
branches: [main]


jobs:
build-and-push:
strategy:
fail-fast: false
matrix:
os:
- [ubuntu-latest]
- [ macos-13 ]

runs-on: ${{ matrix.os }}

steps:
-
name: Checkout
id: checkout
uses: actions/checkout@v1

- name: Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install docker docker-buildx
brew install colima
colima start
while ! docker info >/dev/null 2>&1; do sleep 1; done
mkdir -p ~/.docker/cli-plugins
ln -sfn $(which docker-buildx) ~/.docker/cli-plugins/docker-buildx

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
-
name: Build Dev Container Image
uses: devcontainers/[email protected]
with:
subFolder: .github
imageName: ghcr.io/${{ github.repository }}
cacheFrom: ghcr.io/${{ github.repository }}
push: never

- name: Test Container Image
run: |
docker run --rm ghcr.io/${{ github.repository }} /bin/bash -c "git clone -b devContainers https://github.com/drifter089/pypsa-earth.git && cd pypsa-earth && bash .github/.devcontainer/test.sh"

- name: Push Container Image
if: ${{ success() }}
run: |
docker push ghcr.io/${{ github.repository }}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exclude: ^(LICENSES)

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
Expand Down Expand Up @@ -49,7 +49,7 @@ repos:

# Formatting with "black" coding style
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
# Format Python files
- id: black
Expand Down
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM condaforge/mambaforge

RUN conda update -n base conda
RUN conda install -n base conda-libmamba-solver
RUN conda config --set solver libmamba

RUN apt-get update && apt-get install -y bash git

WORKDIR /pypsa-earth

COPY ./envs ./temp

RUN conda env create -n pypsa-earth -f temp/environment.yaml

RUN conda init bash

RUN touch ~/.bashrc && echo "conda activate pypsa-earth" >> ~/.bashrc

SHELL ["/bin/bash", "--login", "-c"]

ENV PATH /opt/conda/envs/pypsa-earth/bin:$PATH

RUN conda install conda-forge::openjdk -y

RUN rm -r temp

RUN conda clean -afy && \
rm -rf /tmp/*

ENV LD_PRELOAD=/opt/conda/envs/pypsa-earth/lib/python3.10/site-packages/sklearn/utils/../../../../libgomp.so.1

CMD ["bash"]

3 changes: 2 additions & 1 deletion config.tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ version: 0.4.1
tutorial: true


countries: ["NG", "BJ"]
countries: ["NG"]

enable:
retrieve_databundle: true
build_natura_raster: true
progress_bar: false

Expand Down
48 changes: 48 additions & 0 deletions doc/docker_containers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

.. _docker_containers:

Alternate Installation with Docker
===============================================

This is an alternative way to create a development environment for PyPSA-Earth. This method is useful for users who are not familiar with programming or Python, or who do not want to install Python on their local machine. It uses Docker containers to create a development environment for PyPSA-Earth.

This section provides a step-by-step guide on how to set up and use Docker containers to run PyPSA-Earth.

Steps:

1. Install Docker: Follow the instructions for your operating system:

* `Windows <https://docs.docker.com/desktop/install/windows-install/>`_
* `Linux <https://docs.docker.com/desktop/install/linux/>`_
* `MacOS <https://docs.docker.com/desktop/install/mac-install/>`_

Ensure Docker is installed on your system.

2. Install GitHub Desktop for your OS `here <https://desktop.github.com/download/>`_.

3. Clone the repository:
* Open GitHub Desktop.
* Click on "File" in the top left corner.
* Click on "Clone Repository".
* Paste the following URL in the URL field:

.. code:: bash

https://github.com/drifter089/pypsa-earth.git

* Click on "Clone".
* Choose the location where you want to save the repository.
* Click on "Current Branch: main" and select `devContainers`.
* Click on "Open in Visual Studio Code".

The repository will be cloned to your local machine.

4. Rebuild and open in a container:
* Open the repository in VSCode.
* Click on the green icon in the bottom left corner of the VSCode window.
* Click on "Reopen in Container".
* Wait for the container to build and open the repository in the container.

The environment will be ready for use. You can now run PyPSA-Earth in the container.


2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Documentation

* :doc:`introduction`
* :doc:`installation`
* :doc:`docker_containers`
* :doc:`short_tutorial`
* :doc:`tutorial`
* :doc:`data_workflow`
Expand All @@ -140,6 +141,7 @@ Documentation

introduction
installation
docker_containers
short_tutorial
tutorial
data_workflow
Expand Down
4 changes: 4 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ E.g. if a new rule becomes available describe how to use it `make test` and in o

* Include a dedicated cutout for Europe in bundle_config.yaml `PR #1125 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1125>`_

* Fix the mismatch between buses and x, y locations while creating H2 Stores `PR #1134 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1134>`_

* Enable configfile specification for mock_snakemake `PR #1135 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1135>`_

PyPSA-Earth 0.4.1
=================

Expand Down
2 changes: 1 addition & 1 deletion envs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies:
# GIS dependencies:
- cartopy
- descartes
- rasterio!=1.2.10
- rasterio!=1.2.10, <=1.3.11
- rioxarray

# Plotting
Expand Down
18 changes: 15 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ def get_aggregation_strategies(aggregation_strategies):
return bus_strategies, generator_strategies


def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
def mock_snakemake(
rulename, root_dir=None, submodule_dir=None, configfile=None, **wildcards
):
"""
This function is expected to be executed from the "scripts"-directory of "
the snakemake project. It returns a snakemake.script.Snakemake object,
Expand All @@ -534,6 +536,8 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
----------
rulename: str
name of the rule for which the snakemake object should be generated
configfile: str
path to config file to be used in mock_snakemake
wildcards:
keyword arguments fixing the wildcards. Only necessary if wildcards are
needed.
Expand Down Expand Up @@ -566,9 +570,17 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards):
if os.path.exists(p):
snakefile = p
break

if isinstance(configfile, str):
with open(configfile, "r") as file:
configfile = yaml.safe_load(file)

workflow = sm.Workflow(
snakefile, overwrite_configfiles=[], rerun_triggers=[]
) # overwrite_config=config
snakefile,
overwrite_configfiles=[],
rerun_triggers=[],
overwrite_config=configfile,
)
workflow.include(snakefile)
workflow.global_resources = {}
try:
Expand Down
2 changes: 1 addition & 1 deletion scripts/add_extra_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def attach_stores(n, costs, config):

_add_missing_carriers_from_costs(n, costs, carriers)

buses_i = n.buses.query("carrier == 'AC'").index
buses_i = n.buses.index
bus_sub_dict = {k: n.buses[k].values for k in ["x", "y", "country"]}

if "H2" in carriers:
Expand Down
Loading