Skip to content

Commit

Permalink
Merge branch 'main' into m-kovalsky/functionparametersdescriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Jun 6, 2024
2 parents ac10ff9 + e4c60dd commit 3d861d3
Show file tree
Hide file tree
Showing 51 changed files with 141 additions and 117 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Semantic Link Labs

on: [push]

permissions:
contents: write # This is required for actions/checkout@v1
security-events: write # To upload sarif files

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

- name: Get Date
id: get-date
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash

- name: Cache conda
uses: actions/cache@v2
env:
# Increase this value to reset cache if environment.yml has not changed
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ steps.get-date.outputs.today }}-${{ hashFiles('environment.yml') }}

- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
activate-environment: fabric
python-version: "3.10"
environment-file: environment.yml
channel-priority: strict

- name: Install package
shell: bash -el {0}
run: |
conda info
pip install -e .
# - name: Lint with flake8
# shell: bash -el {0}
# run: |
# flake8 sempy_labs tests --count --show-source --statistics
# continue-on-error: false

# - name: Lint with mypy
# shell: bash -el {0}
# run: |
# mypy sempy_labs tests
# continue-on-error: false

- name: Test with pytest
shell: bash -el {0}
run: |
pytest -s tests/
12 changes: 12 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: fabric
dependencies:
- flake8
- mypy
- pytest
- pytest-cov
- pytest-mock
- pip:
- semantic-link-sempy>=0.7.5
- azure-identity==1.7.1
- azure-storage-blob>=12.9.0
- pandas-stubs
113 changes: 0 additions & 113 deletions sempy/labs/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions sempy/labs/Shortcuts.py → sempy_labs/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sempy
import sempy_labs
import sempy.fabric as fabric
import pandas as pd
from .HelperFunctions import resolve_lakehouse_name, resolve_lakehouse_id
Expand Down Expand Up @@ -69,8 +69,8 @@ def create_shortcut_onelake(table_name: str, source_lakehouse: str, source_works
print(f"{green_dot} The shortcut '{shortcut_name}' was created in the '{destination_lakehouse}' lakehouse within the '{destination_workspace} workspace. It is based on the '{table_name}' table in the '{source_lakehouse}' lakehouse within the '{source_workspace}' workspace.")
else:
print(response.status_code)
except:
print(f"{red_dot} Failed to create a shortcut for the '{table_name}' table.")
except Exception as e:
print(f"{red_dot} Failed to create a shortcut for the '{table_name}' table: {e}")

def create_shortcut(shortcut_name: str, location: str, subpath: str, source: str, connection_id: str, lakehouse: Optional[str] = None, workspace: Optional[str] = None):

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
install_requires=[
'semantic-link>=0.7.5',
'semantic-link-sempy>=0.7.5',
'anytree',
'powerbiclient',
],
Expand Down
Empty file added tests/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions tests/test_shortcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pandas as pd
from json import loads
from sempy_labs.shortcuts import create_shortcut_onelake
from unittest.mock import MagicMock, PropertyMock, patch


@patch("sempy.fabric.list_items")
@patch("sempy.fabric.resolve_workspace_id")
@patch("sempy.fabric.FabricRestClient")
def test_create_shortcut_onelake(fabric_rest_client_mock, resolve_workspace_id_mock, list_items_mock):
# prepare mocks
def resolve_workspace_id_mock_side_effect(workspace_name):
if workspace_name == "source_workspace":
return "00000000-0000-0000-0000-000000000001"

if workspace_name == "destination_workspace":
return "00000000-0000-0000-0000-000000000002"

assert False, f"Unexpected workspace: {workspace_name}"

resolve_workspace_id_mock.side_effect = resolve_workspace_id_mock_side_effect

def list_items_side_effect(type, workspace):
assert type == "Lakehouse"

if workspace == "source_workspace":
return pd.DataFrame([{
"Display Name": "source_lakehouse",
"Id": "10000000-0000-0000-0000-000000000001"
}])

if workspace == "destination_workspace":
return pd.DataFrame([{
"Display Name": "destination_lakehouse",
"Id": "20000000-0000-0000-0000-000000000002"
}])

assert False, f"Unexpected workspace: {workspace}"

list_items_mock.side_effect = list_items_side_effect

def post_side_effect(url, json):
# TODO: we could validate the URL and JSON?

response = MagicMock()
type(response).status_code = PropertyMock(return_value=201)

return response

fabric_rest_client_mock.return_value.post.side_effect = post_side_effect

# execute
create_shortcut_onelake("table_name", "source_lakehouse", "source_workspace", "destination_lakehouse", "destination_workspace", "shortcut_name")

0 comments on commit 3d861d3

Please sign in to comment.