commit b7901ec5382a9694394b9de6e7b433749e7aec1b Author: Peter Annabel Date: Mon Jun 15 16:01:46 2026 +0000 Initial commit diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6a830d5 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +EXAMPLEVARIABLE="string variable" \ No newline at end of file diff --git a/.gitea/workflows/build_deploy.yaml b/.gitea/workflows/build_deploy.yaml new file mode 100644 index 0000000..39bca2f --- /dev/null +++ b/.gitea/workflows/build_deploy.yaml @@ -0,0 +1,73 @@ +name: Build and Deploy + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.13' + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build hatch hatch-requirements-txt + + - name: Compute SemVer (X.Y.Z) for this run + id: version + shell: bash + run: | + set -euo pipefail + + BASE="${{ vars.VERSION_BASE }}" + + # Try a few common CI run number env vars; fall back to timestamp. + RUN_NO="${GITHUB_RUN_NUMBER:-${CI_PIPELINE_IID:-${CI_RUN_NUMBER:-}}}" + if [[ -z "${RUN_NO}" ]]; then + # UTC timestamp as integer to keep it numeric (SemVer patch must be numeric) + RUN_NO="$(date -u +%Y%m%d%H%M%S)" + fi + + VERSION="${BASE}.${RUN_NO}" + + echo "BASE=$BASE" + echo "RUN_NO=$RUN_NO" + echo "VERSION=$VERSION" + + echo "HATCH_VERSION=$VERSION" >> "$GITHUB_ENV" + + - name: Build package + run: | + python -m build + + - name: Set up Gitea package registry authentication + run: | + echo "[distutils]" > ~/.pypirc + echo "index-servers = gitea" >> ~/.pypirc + echo "[gitea]" >> ~/.pypirc + echo "repository = https://git.mydatapath.com/api/packages/datapath/pypi" >> ~/.pypirc + echo "username = ${{ secrets.DPGITEA_USERNAME }}" >> ~/.pypirc + echo "password = ${{ secrets.DPGITEA_TOKEN }}" >> ~/.pypirc + + - name: Upload package to Gitea repository + run: | + pip install twine + echo "Uploading package version ${{ steps.version.outputs.version }} to Gitea repository" + twine upload --repository gitea dist/* || { echo "Upload failed. Check credentials and repository settings."; exit 1; } + + - name: Verify upload + run: | + echo "Package version ${{ steps.version.outputs.version }} successfully uploaded to Gitea repository" diff --git a/.gitea/workflows/semgrep.yaml b/.gitea/workflows/semgrep.yaml new file mode 100644 index 0000000..ee0da0f --- /dev/null +++ b/.gitea/workflows/semgrep.yaml @@ -0,0 +1,30 @@ +name: Semgrep + +on: + push: + branches: + - main # Assuming $CI_DEFAULT_BRANCH is 'main', adjust if different + - development + pull_request: + workflow_dispatch: # Equivalent to $CI_PIPELINE_SOURCE == "web" + +permissions: + contents: read + +jobs: + semgrep: + name: semgrep/ci + runs-on: ubuntu-latest + container: + image: mydatapath/semgrep-gitea:latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Semgrep scan + run: semgrep ci + env: + SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} + # At this time, Gitea integration isn't supported with semgrep + # To configure PR comments on Gitea, see Semgrep documentation + # GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dbf2f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,170 @@ +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# 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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e2bf05 --- /dev/null +++ b/README.md @@ -0,0 +1,123 @@ +# Vision-App-Template + +A Template for developing a Django app for use with Datapath's Vision Dashboard. + +Read the following for a cursory guide to initial app development: +https://docs.djangoproject.com/en/5.2/intro/tutorial01/ + +You MUST then package your application following this: +https://docs.djangoproject.com/en/5.2/intro/reusable-apps/ + +This packaging process will need to be automated. + +You are expected to customize this readme to match the needs of your particular application. + +## How to setup your dev environment + +### 1. Copy this Git template into a new repo + +### 2. Clone your new repo + +### 3. Create and activate a virtual enviornment + +```bash +python3 -m venv .venv +source .venv/bin/activate +``` + +### 4. Install PIP requirements + +```bash +pip install -r requirements.txt +``` + +### 5. Create your app using Django's start app command + +``` +python manage.py startapp YOUR-APP-NAME +``` + +### 6. Configure your pyproject.toml + +Be sure to update it to include the name of your project and its repo + +## Tips on developing + +### Use logging! + +In your app, it is imperative that we have good logging. Utilize the python logging package and include the following in each of your python files that need to log. + +```python +import logging + +logger = logging.getLogger(__name__) +``` + + +# The Following must be in YOUR readme + +## Installation + +### 1. Install the package + +```bash +pip install YOUR-APP-HERE +``` + +Or add to your requirements.txt: + +``` +datapath-eval==x.y.z +``` + +### 2. Add required dependencies + +This package requires the following dependencies: + +``` +Django>=5.2.11 +``` + +### 3. Update your Django settings.py + +Add the following to your INSTALLED_APPS: + +```python +INSTALLED_APPS = [ + # ... your existing apps + 'YOUR-APP-HERE.apps.YOUR-APP-NAME', +] +``` + +### 4. Update your project urls.py + +Add the following to your project's urls.py: + +```python +from django.urls import path, include + +urlpatterns = [ + # ... your existing URL patterns + path('YOUR-APP/', include("YOUR-APP.urls")), +] +``` + +### 5. Run migrations + +```bash +python manage.py migrate +``` + +## Usage + +After installation, you can access the evaluation dashboard at: + +``` +http://your-domain/YOUR-APP/ +``` + +## Requirements + +- Python >= 3.11 +- Django >= 5.2 + diff --git a/djangoappdev/djangoappdev/__init__.py b/djangoappdev/djangoappdev/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoappdev/djangoappdev/asgi.py b/djangoappdev/djangoappdev/asgi.py new file mode 100644 index 0000000..770f220 --- /dev/null +++ b/djangoappdev/djangoappdev/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for djangoappdev project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoappdev.settings') + +application = get_asgi_application() diff --git a/djangoappdev/djangoappdev/settings.py b/djangoappdev/djangoappdev/settings.py new file mode 100644 index 0000000..faf3e53 --- /dev/null +++ b/djangoappdev/djangoappdev/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for djangoappdev project. + +Generated by 'django-admin startproject' using Django 5.2.11. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-=zye)gpofy)unsb9pbnglbkffkv&(_zdlyf3rm4rhq-m9cn+py' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'djangoappdev.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'djangoappdev.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/djangoappdev/djangoappdev/urls.py b/djangoappdev/djangoappdev/urls.py new file mode 100644 index 0000000..eb1fa91 --- /dev/null +++ b/djangoappdev/djangoappdev/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for djangoappdev project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/djangoappdev/djangoappdev/wsgi.py b/djangoappdev/djangoappdev/wsgi.py new file mode 100644 index 0000000..5c363fa --- /dev/null +++ b/djangoappdev/djangoappdev/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djangoappdev project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoappdev.settings') + +application = get_wsgi_application() diff --git a/djangoappdev/manage.py b/djangoappdev/manage.py new file mode 100755 index 0000000..be488f0 --- /dev/null +++ b/djangoappdev/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoappdev.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d81defd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[project] +name = "YOUR APP NAME" +authors = [ + { name = "Peter Annabel", email = "pannabel@mydatapath.com" }, +] +description = "Agent evaluation and regression testing Django app" +readme = "README.md" +requires-python = ">=3.11" +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries :: Python Modules", + "Programming Language :: Python :: 3.11", + "Framework :: Django", + "Framework :: Django :: 5.2", +] +keywords = [ + "eval", + "regression", + "agent", + "django", +] +license = "LicenseRef-Proprietary" +dynamic = ["dependencies", "version"] + +[project.urls] +Homepage = "https://git.mydatapath.com/datapath/YOUR-APP-REPO-HERE" +Issues = "https://git.mydatapath.com/datapath/YOUR-APP-REPO-HERE/issues" + +[build-system] +requires = ["hatchling >= 1.26", "hatch-requirements-txt", "hatch-vcs"] +build-backend = "hatchling.build" + +[tool.hatch.metadata.hooks.requirements_txt] +files = ["requirements.txt"] + +[tool.hatch.build.targets.wheel] +packages = ["djangoappdev/YOUR_APP_HERE"] + +[tool.hatch.version] +source = "env" +variable = "HATCH_VERSION" + +[tool.hatch.version.raw-options] +# Common scheme: v1.2.3 tags. Change to match your tags. +tag_regex = "^v(?P\\d+\\.\\d+\\.\\d+)$" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d921be6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +asgiref==3.11.1 +Django==5.2.11 +dotenv==0.9.9 +python-dotenv==1.2.2 +sqlparse==0.5.5