Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing dab #20

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-orchestrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
uses: ./.github/workflows/ci-electrical-heating.yml
with:
image_tag: ${{ needs.ci_docker.outputs.image_tag }}

ci_test_dab:
needs: [changes, ci_docker]
uses: ./.github/workflows/ci-test-dab.yml
with:
image_tag: ${{ needs.ci_docker.outputs.image_tag }}
#
# Branch policy status check
#
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/ci-test-dab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI Test DAB

on:
workflow_call:
inputs:
image_tag:
type: string
default: latest

jobs:
databricks_asset_brundles:
name: Validate Databricks asset bundles
runs-on: ubuntu-latest

env:
RELEASE_FOLDER_PATH: ./source/test_python_wheels
RELEASE_VERSION: test_${{ github.event.pull_request.number }}
RELEASE_ZIP_FILENAME: test_${{ github.event.pull_request.number }}.zip

steps:
# Check out this repo, so that this workflow can access it.
- uses: actions/checkout@v3

# Download the Databricks CLI.
# See https://github.com/databricks/setup-cli
- uses: databricks/setup-cli@main

# Validate the Databricks asset bundles.
# - run: |
# cd ./source/test_python_wheels
# databricks bundle validate

- name: Zip files for prerelease
uses: thedoctor0/[email protected]
with:
type: zip
filename: ${{ env.RELEASE_ZIP_FILENAME }}
directory: ${{ env.RELEASE_FOLDER_PATH }}

- name: Create prerelease
uses: Energinet-Datahub/.github/.github/actions/github-create-release@v14
with:
repo_token: ${{ github.token }}
automatic_release_tag: ${{ env.RELEASE_VERSION }}
prerelease: true
title: ${{ env.RELEASE_VERSION }}
files: |
${{ env.RELEASE_FOLDER_PATH }}/${{ env.RELEASE_ZIP_FILENAME }}

mypy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Run pip install and mypy check of files in package
shell: bash
run: |
pip install --upgrade pip
pip install mypy types-python-dateutil
mypy ./source/electrical_heating --disallow-untyped-defs --ignore-missing-imports

black_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: --check --diff
src: ./source/electrical_heating
8 changes: 8 additions & 0 deletions source/test_python_wheels/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.databricks/
build/
dist/
__pycache__/
*.egg-info
.venv/
scratch/**
!scratch/README.md
3 changes: 3 additions & 0 deletions source/test_python_wheels/.vscode/__builtins__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Typings for Pylance in Visual Studio Code
# see https://github.com/microsoft/pyright/blob/main/docs/builtins.md
from databricks.sdk.runtime import *
7 changes: 7 additions & 0 deletions source/test_python_wheels/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"databricks.databricks",
"ms-python.vscode-pylance",
"redhat.vscode-yaml"
]
}
17 changes: 17 additions & 0 deletions source/test_python_wheels/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"python.analysis.stubPath": ".vscode",
"databricks.python.envFile": "${workspaceFolder}/.env",
"jupyter.interactiveWindow.cellMarker.codeRegex": "^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
"jupyter.interactiveWindow.cellMarker.default": "# COMMAND ----------",
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.extraPaths": ["src"],
"files.exclude": {
"**/*.egg-info": true,
"**/__pycache__": true,
".pytest_cache": true,
},
}
47 changes: 47 additions & 0 deletions source/test_python_wheels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# test_python_wheels

The 'test_python_wheels' project was generated by using the default-python template.

## Getting started

1. Install the Databricks CLI from https://docs.databricks.com/dev-tools/cli/databricks-cli.html

2. Authenticate to your Databricks workspace, if you have not done so already:
```
$ databricks configure
```

3. To deploy a development copy of this project, type:
```
$ databricks bundle deploy --target dev
```
(Note that "dev" is the default target, so the `--target` parameter
is optional here.)

This deploys everything that's defined for this project.
For example, the default template would deploy a job called
`[dev yourname] test_python_wheels_job` to your workspace.
You can find that job by opening your workpace and clicking on **Workflows**.

4. Similarly, to deploy a production copy, type:
```
$ databricks bundle deploy --target prod
```

Note that the default job from the template has a schedule that runs every day
(defined in resources/test_python_wheels.job.yml). The schedule
is paused when deploying in development mode (see
https://docs.databricks.com/dev-tools/bundles/deployment-modes.html).

5. To run a job or pipeline, use the "run" command:
```
$ databricks bundle run
```

6. Optionally, install developer tools such as the Databricks extension for Visual Studio Code from
https://docs.databricks.com/dev-tools/vscode-ext.html. Or read the "getting started" documentation for
**Databricks Connect** for instructions on running the included Python code from a different IDE.

7. For documentation on the Databricks asset bundles format used
for this project, and for CI/CD configuration, see
https://docs.databricks.com/dev-tools/bundles/index.html.
24 changes: 24 additions & 0 deletions source/test_python_wheels/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This is a Databricks asset bundle definition for test_python_wheels.
# See https://docs.databricks.com/dev-tools/bundles/index.html for documentation.
bundle:
name: test_python_wheels

include:
- resources/*.yml

targets:
dev:
# The default target uses 'mode: development' to create a development copy.
# - Deployed resources get prefixed with '[dev my_user_name]'
# - Any job schedules and triggers are paused by default.
# See also https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.
mode: development
default: true

prod:
mode: production
workspace:
root_path: /Shared/Bundles/.bundle/${bundle.name}/${bundle.target}
permissions:
- group_name: A_GROUP
level: CAN_MANAGE
22 changes: 22 additions & 0 deletions source/test_python_wheels/fixtures/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Fixtures

This folder is reserved for fixtures, such as CSV files.

Below is an example of how to load fixtures as a data frame:

```
import pandas as pd
import os

def get_absolute_path(*relative_parts):
if 'dbutils' in globals():
base_dir = os.path.dirname(dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()) # type: ignore
path = os.path.normpath(os.path.join(base_dir, *relative_parts))
return path if path.startswith("/Workspace") else "/Workspace" + path
else:
return os.path.join(*relative_parts)

csv_file = get_absolute_path("..", "fixtures", "mycsv.csv")
df = pd.read_csv(csv_file)
display(df)
```
3 changes: 3 additions & 0 deletions source/test_python_wheels/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
testpaths = tests
pythonpath = src
29 changes: 29 additions & 0 deletions source/test_python_wheels/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## requirements-dev.txt: dependencies for local development.
##
## For defining dependencies used by jobs in Databricks Workflows, see
## https://docs.databricks.com/dev-tools/bundles/library-dependencies.html

## Add code completion support for DLT
databricks-dlt

## pytest is the default package used for testing
pytest

## Dependencies for building wheel files
setuptools
wheel

## databricks-connect can be used to run parts of this project locally.
## See https://docs.databricks.com/dev-tools/databricks-connect.html.
##
## databricks-connect is automatically installed if you're using Databricks
## extension for Visual Studio Code
## (https://docs.databricks.com/dev-tools/vscode-ext/dev-tasks/databricks-connect.html).
##
## To manually install databricks-connect, either follow the instructions
## at https://docs.databricks.com/dev-tools/databricks-connect.html
## to install the package system-wide. Or uncomment the line below to install a
## version of db-connect that corresponds to the Databricks Runtime version used
## for this project.
#
# databricks-connect>=15.4,<15.5
40 changes: 40 additions & 0 deletions source/test_python_wheels/resources/test_python_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The main job for test_python_wheels.
resources:
jobs:
test_python_wheels_job:
name: test_python_wheels_job

trigger:
# Run this job every day, exactly one day from the last run; see https://docs.databricks.com/api/workspace/jobs/create#trigger
periodic:
interval: 1
unit: DAYS

tasks:
- task_key: notebook_task
job_cluster_key: job_cluster
notebook_task:
notebook_path: ../src/notebook.ipynb

- task_key: main_task
depends_on:
- task_key: notebook_task

job_cluster_key: job_cluster
python_wheel_task:
package_name: test_python_wheels
entry_point: main
libraries:
# By default we just include the .whl file generated for the test_python_wheels package.
# See https://docs.databricks.com/dev-tools/bundles/library-dependencies.html
# for more information on how to add other libraries.
- whl: ../dist/*.whl

job_clusters:
- job_cluster_key: job_cluster
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: Standard_D3_v2
autoscale:
min_workers: 1
max_workers: 4
4 changes: 4 additions & 0 deletions source/test_python_wheels/scratch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# scratch

This folder is reserved for personal, exploratory notebooks.
By default these are not committed to Git, as 'scratch' is listed in .gitignore.
37 changes: 37 additions & 0 deletions source/test_python_wheels/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
setup.py configuration script describing how to build and package this project.

This file is primarily used by the setuptools library and typically should not
be executed directly. See README.md for how to deploy, test, and run
the test_python_wheels project.
"""
from setuptools import setup, find_packages

import sys
sys.path.append('./src')

import datetime
import test_python_wheels

setup(
name="test_python_wheels",
# We use timestamp as Local version identifier (https://peps.python.org/pep-0440/#local-version-identifiers.)
# to ensure that changes to wheel package are picked up when used on all-purpose clusters
version=test_python_wheels.__version__ + "+" + datetime.datetime.utcnow().strftime("%Y%m%d.%H%M%S"),
url="https://databricks.com",
author="test",
description="wheel file based on test_python_wheels/src",
packages=find_packages(where='./src'),
package_dir={'': 'src'},
entry_points={
"packages": [
"main=test_python_wheels.main:main"
]
},
install_requires=[
# Dependencies in case the output wheel file is used as a library dependency.
# For defining dependencies, when this package is used in Databricks, see:
# https://docs.databricks.com/dev-tools/bundles/library-dependencies.html
"setuptools"
],
)
Loading
Loading