Skip to content

Commit

Permalink
Added poetry for dependencies management. Changed postgres_name to po…
Browse files Browse the repository at this point in the history
…stgres_db env variable.
  • Loading branch information
itsjrsa committed Mar 9, 2024
1 parent eefecb7 commit f026c90
Show file tree
Hide file tree
Showing 7 changed files with 1,728 additions and 19 deletions.
93 changes: 93 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Git
.git
.gitignore

# CI
.codeclimate.yml
.travis.yml
.taskcluster.yml

# Docker
docker-compose.yml
.docker

# Byte-compiled / optimized / DLL files
__pycache__/
*/__pycache__/
*/*/__pycache__/
*/*/*/__pycache__/
*.py[cod]
*/*.py[cod]
*/*/*.py[cod]
*/*/*/*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Virtual environment
.env/
.venv/
venv/

# PyCharm
.idea

# Python mode for VIM
.ropeproject
*/.ropeproject
*/*/.ropeproject
*/*/*/.ropeproject

# Vim swap files
*.swp
*/*.swp
*/*/*.swp
*/*/*/*.swp
38 changes: 29 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
stages:
- test-market
- lint
- test

test-market:
image:
name: python:3.12
entrypoint: ["/usr/bin/env"]
stage: test-market
variables:
PYTHON_VERSION: "3.12"
POETRY_NO_INTERACTION: 1
POETRY_VIRTUALENVS_CREATE: 'false'
POETRY_CACHE_DIR: '/var/cache/pypoetry'
POETRY_HOME: '/usr/local'


lint:
stage: lint
image: python:${PYTHON_VERSION}
before_script:
# Configure git to use the token for your GitLab instance
- 'git config --global url."https://oauth2:$GITLAB_TOKEN@gitlab.inesctec.pt/".insteadOf "https://gitlab.inesctec.pt/"'
- git config --global url."https://oauth2:$GITLAB_TOKEN@gitlab.inesctec.pt/".insteadOf "https://gitlab.inesctec.pt/"
script:
- pip install -r requirements.txt
- python -m pip install --upgrade pip
- pip install poetry
- poetry install --with test
- flake8

test:
stage: test
image: python:${PYTHON_VERSION}
before_script:
# Configure git to use the token for your GitLab instance
- git config --global url."https://oauth2:$GITLAB_TOKEN@gitlab.inesctec.pt/".insteadOf "https://gitlab.inesctec.pt/"
script:
- python -m pip install --upgrade pip
- pip install poetry
- poetry install --with test
- cd src/market
- pytest --cov
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ FROM python:3.12-bookworm
WORKDIR /app

# set env variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
# Poetry's configuration:
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
POETRY_HOME='/usr/local'

# Accept GITLAB_TOKEN as a build-time argument
ARG GITLAB_TOKEN

# Use the argument to set the Git configuration for HTTPS cloning
RUN git config --global url."https://oauth2:${GITLAB_TOKEN}@gitlab.inesctec.pt/".insteadOf "https://gitlab.inesctec.pt/"
# copy requirements
COPY requirements.txt /app/requirements.txt

RUN apt-get update && apt-get install -y build-essential

# install required packages
RUN pip install -r requirements.txt
# copy requirements
COPY poetry.lock pyproject.toml /app/
RUN pip install poetry && poetry install

# copy project
COPY . /app
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,26 @@ To launch the docker containers stack:
If you prefer using your local python interpreter (instead of docker), you'll need to manually perform the installation steps.
Also, only 'simulation' functionalities (i.e., without integration with the data market REST / DB) will be available.

1. Install the python dependencies
1. Install poetry (if not already installed)

```shell
$ pip install poetry
```

2. Install the python dependencies
```shell
$ pip install -r requirements.txt
$ cd /api
$ poetry install
$ poetry shell
```

2. Run the 'run_menu.py' script to open the interactive market menu
3. Run the 'run_menu.py' script to open the interactive market menu
```shell
$ python run_menu.py
$ poetry run python run_menu.py
```

> **_NOTE:_** If you're already working in a virtual environment (e.g., conda or pyenv), you can skip the `poetry shell` command.

### Running the interactive menu:

Expand Down
2 changes: 1 addition & 1 deletion conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# Database configs:
DATABASES = {
'default': {
'NAME': os.environ.get("POSTGRES_NAME", default=''),
'NAME': os.environ.get("POSTGRES_DB", default=''),
'USER': os.environ.get("POSTGRES_USER", default=''),
'PASSWORD': os.environ.get("POSTGRES_PASSWORD", default=''),
'HOST': os.environ.get("POSTGRES_HOST", default=''),
Expand Down
Loading

0 comments on commit f026c90

Please sign in to comment.