Skip to content

Commit

Permalink
Merge pull request #27 from Datafalk/feat/docker
Browse files Browse the repository at this point in the history
feat(docker): create docker dev environment
  • Loading branch information
dyoussef authored Oct 17, 2024
2 parents 194bba7 + 0e9bf6e commit fd18e3c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ RUN apt-get update && apt-get install --no-install-recommends -y --quiet \
&& rm -rf /var/lib/apt/lists/*

# copy and install cars with mccnn plugin capabilities installed (but not configured by default)
WORKDIR /cars
COPY . /cars/
WORKDIR /app

# Install fiona and rasterio with gdal / proj from otb
RUN make clean && make install-gdal

# Create a virtual environment
RUN python3 -m venv /app/venv

# source venv/bin/activate in docker mode
ENV VIRTUAL_ENV='/cars/venv'
ENV VIRTUAL_ENV='/app/venv'
ENV PATH="$VIRTUAL_ENV/bin:$PATH"


# Copy only necessary files for installation
COPY . /app/cars

# Install fiona and rasterio with gdal / proj from otb
WORKDIR /app/cars
RUN CARS_VENV=$VIRTUAL_ENV make clean && CARS_VENV=$VIRTUAL_ENV make install-gdal-dev


# hadolint ignore=DL3013,SC2102
RUN python -m pip cache purge

Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ install-gdal: install-deps-gdal ## install cars (not editable) with dev, docs, n
@echo "CARS ${CARS_VERSION} installed in dev mode in virtualenv ${CARS_VENV}"
@echo "CARS venv usage: source ${CARS_VENV}/bin/activate; cars -h"

.PHONY: install-gdal-dev
install-gdal-dev: install-deps-gdal ## install cars dev (editable) with dev, docs, notebook dependencies
@test -f ${CARS_VENV}/bin/cars || ${CARS_VENV}/bin/pip install .[dev,docs,notebook,pandora_mccnn]
@test -f .git/hooks/pre-commit || echo " Install pre-commit hook"
@test -f .git/hooks/pre-commit || ${CARS_VENV}/bin/pre-commit install -t pre-commit
@test -f .git/hooks/pre-push || ${CARS_VENV}/bin/pre-commit install -t pre-push
@echo "CARS ${CARS_VERSION} installed in dev mode in virtualenv ${CARS_VENV}"
@echo "CARS venv usage: source ${CARS_VENV}/bin/activate; cars -h"

.PHONY: install-pandora-mccnn
install-pandora-mccnn: install-deps ## install cars (not editable) with dev, docs, notebook dependencies
@test -f ${CARS_VENV}/bin/cars || ${CARS_VENV}/bin/pip install .[dev,docs,notebook,pandora_mccnn]
Expand Down Expand Up @@ -226,6 +235,7 @@ clean: clean-venv clean-build clean-precommit clean-pyc clean-test clean-docs cl
.PHONY: clean-venv
clean-venv:
@echo "+ $@"
@echo ${CARS_VENV}
@rm -rf ${CARS_VENV}

.PHONY: clean-build
Expand Down
23 changes: 19 additions & 4 deletions docs/source/contributing_the_project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ Particularly, it uses the following pip editable install:
With this pip install mode, source code modifications directly impacts ``cars`` command line.


Setting up a development environment with docker
================================================

To setup a development environment with docker, run the following command:

.. code-block:: console
docker build -t cars-dev -f Dockerfile .
docker run -it -v "$(pwd)":/app/cars --entrypoint=/bin/bash cars-dev
You're ready to use CARS, all files in the current directory are mounted in the container.



Coding guide
============

Expand All @@ -55,8 +70,8 @@ Here are some rules to apply when developing a new functionality:
* **Test**: Each new functionality shall have a corresponding test in its module's test file. This test shall, if possible, check the function's outputs and the corresponding degraded cases.
* **Documentation**: All functions shall be documented (object, parameters, return values).
* **Use type hints**: Use the type hints provided by the `typing` python module.
* **Use doctype**: Follow sphinx default doctype for automatic API
* **Quality code**: Correct project quality code errors with pre-commit automatic workflow (see below)
* **Use doctype**: Follow sphinx default doctype for automatic API.
* **Quality code**: Correct project quality code errors with pre-commit automatic workflow (see below).
* **Factorization**: Factorize the code as much as possible. The command line tools shall only include the main workflow and rely on the cars python modules.
* **Be careful with user interface upgrade:** If major modifications of the user interface or of the tool's behaviour are done, update the user documentation (and the notebooks if necessary).
* **Logging and no print**: The usage of the `print()` function is forbidden: use the `logging` python standard module instead.
Expand Down Expand Up @@ -107,7 +122,7 @@ Jupyter notebooks

CARS contains notebooks in tutorials directory.

To generate a Jupyter kernel with CARS installation, use:
To generate a `Jupyter kernel <https://jupyter.org/install>`_ with CARS installation, use:

.. code-block:: console
Expand Down Expand Up @@ -180,7 +195,7 @@ If necessary, Black doesn’t reformat blocks that start with "# fmt: off" and e
Flake8
------
`Flake8`_ is a command-line utility for enforcing style consistency across Python projects. By default it includes lint checks provided by the PyFlakes project, PEP-0008 inspired style checks provided by the PyCodeStyle project, and McCabe complexity checking provided by the McCabe project. It will also run third-party extensions if they are found and installed.
`Flake8`_ is a command-line utility for enforcing style consistency across Python projects. By default it includes lint checks provided by the `PyFlakes project <https://github.com/PyCQA/pyflakes>`_ , PEP-0008 inspired style checks provided by the `PyCodeStyle project <https://github.com/PyCQA/pycodestyle>`_ , and McCabe complexity checking provided by the `McCabe project <https://github.com/PyCQA/mccabe>`_. It will also run third-party extensions if they are found and installed.

CARS ``flake8`` configuration is done in `setup.cfg <https://raw.githubusercontent.com/CNES/cars/master/setup.cfg>`_

Expand Down

0 comments on commit fd18e3c

Please sign in to comment.