From dff8214d26e7968620da1a40036f9a758385d228 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 29 Oct 2023 13:48:40 -0300 Subject: [PATCH 1/9] TST: remove travis CI file, no longer used --- .travis.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b2ec516aa..000000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: python -python: - - "3.8" -install: - - make install - - pip install -r requirements-tests.txt -before_script: - - make verify-lint -script: - - make test -deploy: - provider: pypi - username: __token__ - password: - secure: ZgTCJPP2JyS9IoJeFZo1x8dwUmFW3ZZ5OzHKJvb/zKZXhpkQsaKWQOu79E00KYq2r36O6gnKiut8XbGuJoCcbIyZiPELizZ7KZskl+pJRhk78YAwb9eIp0yY7Fso6LmdDuYAdxLBHvaFcEpb60IEOXv6iBPbGSKIR18xVdOBzbb/kbscpOPez9Zmdgz6jTQYRwHA8BwW5Eo02FG20GDGiQCzbfhDZbIQcoHLXLM1fEDRLKZl7yBJOO62RGaMaTyn88CrGTIL5cz3od8okLS2c4FJvxGdieMw6LuCXOcJYWKhPCGGBXUOBEfjeEH0rVQz9YRV4Q+l2us/UtRAMXDWGCjWq8cnQU/4CUVWqxkF/7SN/CytkaKGJ0outqYO0nqT1zgRohiIJqL0lW6VrMHDSonA03VEq5DrueIh4/XAPMj4Vl7PIv8R1ztKm+vHEPO6fEjTd2S9B7mIc4VuOLI0NJuaPemlAO4HnIU/WO49T06QTVhjOdzoNnvN/N9W8mBnvMmytvTVvGyF0gAKpvFx48YxsI4ltTLyVjRTrV30mDrylUHr8bGkB2SI/ZEhQFLuO3J1qK7zitgT5h9ZXRtGMs5N08GMhHtAyKdRUmzLtb0+baZnkoLNi8XYbd0Np8fLwH+M080Soy4robPai+ZnZQKLyRObcxhRsfqKuu7L0LI= - on: - tags: true - branch: master From 88f279881afa6c24b045c91f8156549c402dd644 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 29 Oct 2023 14:49:52 -0300 Subject: [PATCH 2/9] TST: update workflow to run on new python 3.12 --- .github/workflows/test_pytest.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index 7ca507dde..8b7bf15b9 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -7,13 +7,13 @@ on: - "**.py" jobs: - fail_if_pull_request_is_draft: + fail_if_pr_is_draft: if: github.event.pull_request.draft == true runs-on: ubuntu-18.04 steps: - name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass. run: exit 1 - run_pytest_and_doctest: + pytest_and_doctest: runs-on: ${{ matrix.os }} strategy: matrix: @@ -23,7 +23,7 @@ jobs: - windows-latest python-version: - 3.8 - - 3.11 + - 3.12 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 4542d9df1ac665bd040d08db95c2a451c6ddce4f Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 29 Oct 2023 16:37:01 -0300 Subject: [PATCH 3/9] ENH: adding docker files --- .dockerignore | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++++ docker-compose.yml | 24 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..3ee85f1d4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,46 @@ +# Python files +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +db.sqlite3 +/db.sqlite3 +pip-log.txt +pip-delete-this-directory.txt +.pytest_cache/ + +# Documentation and Tests +docs/ +.coverage +readthedocs.yml +.travis.yml +Makefile + +# Binary and Package files +*.egg-info/ +*.egg +dist/ +build/ + +# VCS +.git/ +.gitignore +.gitattributes +.github/ + +# IDEs and Editors +.vscode + +# Virtual environments +.venv +venv +ENV/ +env/ + +# Others +*.log + +# Docker +Dockerfile +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..34553e2ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Set base image +# python:latest will get the latest version of python, on linux +# Get a full list of python images here: https://hub.docker.com/_/python/tags +FROM python:latest + +# set the working directory in the container +WORKDIR /RocketPy + +# Ensure pip is updated +RUN python3 -m pip install --upgrade pip + +# Copy the dependencies file to the working directory +COPY requirements.txt . +COPY requirements-tests.txt . + +# Install dependencies +# Use a single RUN instruction to minimize the number of layers +RUN pip install \ + -r requirements.txt \ + -r requirements-tests.txt + +# copy the content of the local src directory to the working directory +COPY . . + +# command to run on container start +# print the operational system and the python version +CMD [ "python3", "-c", "import platform;import sys; print('Python ', sys.version, ' running on ', platform.platform())" ] + +# Install the rocketpy package # TODO: check if I can put this in editable mode +RUN pip install . diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..af9afbddd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + python38-linux: + image: python:3.8 + volumes: + - .:/app + working_dir: /app + command: bash -c "pip install . && pip install -r requirements-tests.txt && pytest && cd rocketpy && pytest --doctest-modules" + logging: + options: + max-size: "10m" + max-file: "3" + + python312-linux: + image: python:3.12 + volumes: + - .:/app + working_dir: /app + command: bash -c "pip install . && pip install -r requirements-tests.txt && pytest && cd rocketpy && pytest --doctest-modules" + logging: + options: + max-size: "10m" + max-file: "3" \ No newline at end of file From 243d266ccc37f464e33f40096bcb8ad0810ec072 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Sun, 29 Oct 2023 16:37:41 -0300 Subject: [PATCH 4/9] DOC: docker instructions attached to the docs --- docs/development/docker.rst | 174 ++++++++++++++++++++++++++++++++++++ docs/development/index.rst | 1 + 2 files changed, 175 insertions(+) create mode 100644 docs/development/docker.rst diff --git a/docs/development/docker.rst b/docs/development/docker.rst new file mode 100644 index 000000000..cc64d6cfd --- /dev/null +++ b/docs/development/docker.rst @@ -0,0 +1,174 @@ +RocketPy with docker +===================== + +RocketPy does not provide an official docker image, but you can build one +yourself using the provided `Dockerfile` and `docker-compose.yml` files. + +Benefits +-------- + +Docker allows you to run applications in containers. The main benefits of +using docker are: + +1. **Isolation**: run RocketPy in a fresh environment, without + worrying about dependencies. +2. **Portability**: run RocketPy on any operational system that supports + docker, including the 3 main operational systems (Windows, Linux and Mac). +3. **Reproducibility**: ensure that tour code is working regardless of the + operational system. + +Using docker will be specially important when you are not sure if the code +additions will still run on different operational systems. + +Although we have a set of GitHub actions to test the code on different +operational systems every time a pull request is made, it is important to +submit a PR only after you are sure that the code will run flawlessly, +otherwise quota limits may be reached on GitHub. + +Requirements +------------- + +Before you start, you need to install on your machine: + +1. `Docker `__, to build and run the image. +2. `Docker Compose `__, to compose multiple images at once. +3. Also, make sure you have cloned the RocketPy repository in your machine! + +Build the image +---------------- + +To build the image, run the following command on your terminal: + +.. code-block:: console + + docker build -t rocketpy-image -f Dockerfile . + + +This will build the image and tag it as `rocketpy-image` (you can apply another +name of your preference if you want). + +An image is a read-only template with instructions for creating a Docker +container (see `Docker docs `__). + +This process may take a while, since it will create an image that could easily +be 1.5 GB in size. +But don't worry, you just need to build the image once. + +Run the container +----------------- + +Now that you have the image, you can run it as a container: + +.. code-block:: console + + docker run -it --entrypoint /bin/bash rocketpy-image + + +This will run the container and open a bash terminal inside it. +If you are using VSCode, you can even integrate the running container into your +IDE, allowing you to code and test directly within the container environment. +This is particularly useful if you want to maintain your usual development setup +while ensuring consistency in the execution environment. +For more details on how to do this, refer to the +`VSCode docs `__ +on developing inside a container. + +Indeed, vscode offers a full support for docker, read the +`vscode docs `__ +for more details + + +Run the unit tests +-------------------- + +You might have noticed that the container is running in an isolated environment +with no access to your machine's files, but the `Dockerfile` already copied the +RocketPy repository to the container. +This means that you can run tests (and simulations!) as if you were running +RocketPy on your machine. + +As simple as that, you can run the unit tests: + +.. code-block:: console + + pytest + + +To access a list of all available execution options, see the +`pytest docs `__. + +Compose docker images +--------------------- + +We also made available a `docker-compose.yml` file that allows you to compose +multiple docker images at once. +Unfortunately, this file will not allow you to test the code on different +operational systems at once, since docker images inherits from the host +operational system. +However, it is still useful to run the unit tests on different python versions. + +Currently, the `docker-compose.yml` file is configured to run the unit tests +on python 3.8 and 3.12. + +To run the unit tests on both python versions, run the following command +**on your machine**: + +.. code-block:: console + + docker-compose up + +Also, you can check the logs of the containers by running: + +.. code-block:: console + + docker-compose logs + + +This command is especially useful for debugging if any issues occur during the +build process or when running the containers. + +After you're done testing, or if you wish to stop the containers and remove the +services, use the command: + +.. code-block:: console + + docker-compose down + + +This will stop the running containers and remove the networks, volumes, and +images created by up. + + +Changing to other operational systems +------------------------------------- + +The default image in the `Dockerfile` is based on a Linux distribution. +However, you can alter the base image to use different operating systems, though +the process may require additional steps depending on the OS's compatibility +with your project setup. +For instance, certain dependencies or scripts may behave differently or require +different installation procedures, so use it with caution. + +To change the base image, you will need to modify the `FROM` statement in the +`Dockerfile`. +For example, to use a Windows-based image, you might change: + +.. code-block:: Dockerfile + + FROM python:latest + + +to + +.. code-block:: Dockerfile + + FROM mcr.microsoft.com/windows/servercore:ltsc2019 + + +Please note, the above is just an example, and using a different OS may require +further adjustments in the `Dockerfile`. +We recommend you to see the official Python images on the Docker Hub for +different OS options: `Docker Hub Python Tags `__. + +Be aware that switching to a non-Linux image can lead to larger image sizes and +longer pull times. diff --git a/docs/development/index.rst b/docs/development/index.rst index b13769e56..767516c56 100644 --- a/docs/development/index.rst +++ b/docs/development/index.rst @@ -8,5 +8,6 @@ Contributing to RocketPy Running RocketPy as a Developer GitHub Workflow for RocketPy Hackathon 2022 Style Guide + RocketPy with Docker This section is still a work in progress. Here you will find information on how to contribute to our code base. \ No newline at end of file From cf6f9774280c6fce9dca5297c7bf260f0bf34304 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 9 Nov 2023 18:08:13 -0300 Subject: [PATCH 5/9] TST: Add .github/** to paths in test_pytest.yaml This is important because the github actions were not being activated after modifying the .yaml files --- .github/workflows/test_pytest.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index 8b7bf15b9..2d611f399 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -5,6 +5,7 @@ on: types: [opened, synchronize, reopened, ready_for_review] paths: - "**.py" + - ".github/**" jobs: fail_if_pr_is_draft: From 8b0800d0f242e7555b3dc26a9af8e725917e1c5a Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 9 Nov 2023 22:01:34 -0300 Subject: [PATCH 6/9] MNT: Add Codecov integration to test_pytest.yaml --- .github/workflows/test_pytest.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index 2d611f399..11e0380ee 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -48,3 +48,7 @@ jobs: pytest cd rocketpy pytest --doctest-modules + - name: Upload reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 3a46aede5c77dfa0232532fce31c2d2abdf3b115 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 9 Nov 2023 22:17:20 -0300 Subject: [PATCH 7/9] MNT: Add code coverage to pytest workflow --- .github/workflows/test_pytest.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index 11e0380ee..31500e8a9 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -45,10 +45,16 @@ jobs: pip install -r requirements-tests.txt - name: Test with pytest run: | - pytest + pytest --cov=rocketpy --cov-report=xml cd rocketpy - pytest --doctest-modules - - name: Upload reports to Codecov + pytest --doctest-modules --cov=rocketpy --cov-report=xml --cov-append + - name: Upload coverage report to Codecov uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + verbose: true env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From c848621613057174176120d1afa6778b5440e095 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 9 Nov 2023 23:03:01 -0300 Subject: [PATCH 8/9] MNT: environment variables with codecov --- .github/workflows/test_pytest.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index 31500e8a9..855cac949 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -25,6 +25,9 @@ jobs: python-version: - 3.8 - 3.12 + env: + OS: ${{ matrix.os }} + PYTHON: ${{ matrix.python-version }} steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -47,14 +50,15 @@ jobs: run: | pytest --cov=rocketpy --cov-report=xml cd rocketpy - pytest --doctest-modules --cov=rocketpy --cov-report=xml --cov-append + pytest --doctest-modules --cov=rocketpy --cov-report=xml - name: Upload coverage report to Codecov uses: codecov/codecov-action@v3 with: - file: ./coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage/reports/ + env_vars: OS,PYTHON + fail_ci_if_error: true + files: ./coverage.xml, ./rocketpy/coverage.xml flags: unittests name: codecov-umbrella - fail_ci_if_error: true verbose: true - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 7934beb5c907e7afe854afdf6c8a097f8a152fd0 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 9 Nov 2023 23:16:34 -0300 Subject: [PATCH 9/9] DOC: Add codecov badge to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3f1a1b989..ee089056b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RocketPy-Team/rocketpy/blob/master/docs/notebooks/getting_started_colab.ipynb) [![PyPI](https://img.shields.io/pypi/v/rocketpy?color=g)](https://pypi.org/project/rocketpy/) [![Documentation Status](https://readthedocs.org/projects/rocketpyalpha/badge/?version=latest)](https://docs.rocketpy.org/en/latest/?badge=latest) +[![codecov](https://codecov.io/gh/RocketPy-Team/RocketPy/graph/badge.svg?token=Ecc3bsHFeP)](https://codecov.io/gh/RocketPy-Team/RocketPy) [![Contributors](https://img.shields.io/github/contributors/RocketPy-Team/rocketpy)](https://github.com/RocketPy-Team/RocketPy/graphs/contributors) [![Chat on Discord](https://img.shields.io/discord/765037887016140840?logo=discord)](https://discord.gg/b6xYnNh) [![Sponsor RocketPy](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/RocketPy-Team)