WSL/SLF GitLab Repository

Commit 93966258 authored by Rebecca Kurup Buchholz's avatar Rebecca Kurup Buchholz
Browse files

Merge branch 'main' of https://gitlabext.wsl.ch/EnviDat/opendataswiss into main

parents ff3826d6 9667481d
......@@ -3,6 +3,6 @@
# Allow files and directories
!*.py
!utils/**/*.py
!pyproject.toml
!.pdm.toml
!pdm.lock
!__pypackages__/
......@@ -8,22 +8,31 @@ Code to make EnviDat data accessible via OpenDataSwiss scrapers.
## Development
- Build the debug image:
`docker compose build`
1. Create .env.secret:
```env
LOG_LEVEL=DEBUG
AWS_ENDPOINT=xxx
AWS_REGION=xxx
AWS_ACCESS_KEY=xxx
AWS_SECRET_KEY=xxx
AWS_BUCKET_NAME=xxx
BACKEND_PACKAGE_URL=xxx
```
- Create .app.secret:
2a. Local Debug
```env
LOG_LEVEL=DEBUG
AWS_ENDPOINT=xxx
AWS_REGION=xxx
AWS_ACCESS_KEY=xxx
AWS_SECRET_KEY=xxx
AWS_BUCKET_NAME=xxx
BACKEND_PACKAGE_URL=xxx
```
- Install `pdm` and enable pep582 support `pdm --pep582`.
- Install project dependencies `pdm install`
- Run with IDE debugger
- Run via VSCode debug menu.
2b. Remote Debug
- Build the debug image:
`docker compose build`
- Start the container:
`docker compose up -d`
- Run remote debugging via IDE (VSCode) debug menu.
## Production
......
......@@ -20,7 +20,7 @@ services:
volumes:
- .:/opt/app:ro
env_file:
- .app.secret
- .env.secret
networks:
- traefik-proxy
restart: unless-stopped
......@@ -5,6 +5,7 @@ import requests
from io import BytesIO
from textwrap import dedent
from pathlib import Path
# from utils.s3 import (
# get_s3_connection,
......@@ -17,6 +18,23 @@ from textwrap import dedent
log = logging.getLogger(__name__)
def debugger_is_active() -> bool:
"Check to see if running in debug mode."
gettrace = getattr(sys, "gettrace", lambda: None)
return gettrace() is not None
def _load_debug_dotenv():
"Load .env.secret variables from repo for debugging."
from dotenv import load_dotenv
secret_env = Path(".env.secret")
if secret_env.is_file():
load_dotenv(secret_env)
def _get_url(url: str) -> requests.Response:
"Helper wrapper to get a URL with additional error handling."
......@@ -42,7 +60,7 @@ def _get_url(url: str) -> requests.Response:
return None
def get_logger() -> logging.basicConfig:
def _get_logger() -> logging.basicConfig:
"Set logger parameters with log level from environment."
logging.basicConfig(
......@@ -140,7 +158,9 @@ def generate_index_html(package_names: list) -> BytesIO:
def main():
"Main script logic."
get_logger()
if debugger_is_active():
_load_debug_dotenv()
_get_logger()
# s3_client = get_s3_connection()
# bucket = create_s3_bucket(s3_client, public=True)
......
......@@ -9,9 +9,10 @@ authors = [
dependencies = [
"s3-bucket>=1.4.0",
"requests==2.27.1",
]
"xmltodict>=0.13.0"]
requires-python = ">=3.9"
license = {text = "MIT"}
[project.optional-dependencies]
[tool.pdm]
[[tool.pdm.source]]
......@@ -19,7 +20,9 @@ name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[tool.pdm.dev-dependencies]
dev = []
dev = [
"python-dotenv>=0.20.0",
]
[build-system]
requires = ["pdm-pep517"]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment