Skip to content

Commit

Permalink
Added: Support for assets available in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Jun 13, 2024
1 parent d04155e commit 6f751e5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

## Types of Changes and How to Note Them

Added - For any new features that have been added since the last version was released
Changed - To note any changes to the software's existing functionality
Deprecated - To note any features that were once stable but are no longer and have thus been removed
Fixed - Any bugs or errors that have been fixed should be so noted
Removed - This notes any features that have been deleted and removed from the software
Security - This acts as an invitation to users who want to upgrade and avoid any software vulnerabilities

## 2 - unreleased

* Added: Support for assets available in Python


## 1 - 2014-03-15

Initial version
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ Example script: [`script.py`](src/framework/processing/py/port/script.py).

We recommend to use the example script as starting point for your own data donation study.

### Port Assets

Assets needed in the script can be copied to: `src/framework/processing/py/port/assets/`

In your script you can access these assets as follows:

#### Asset path

```Python
from port.api.assets import *

def process(sessionId):
path = asset_path("hello_world.txt")
file = open(path, "r")
txt = file.read()
```

#### Open asset

```Python
from port.api.assets import *

def process(sessionId):
file = open_asset("hello_world.txt")
txt = file.read()
```

#### Read asset

```Python
from port.api.assets import *

def process(sessionId):
txt = read_asset("hello_world.txt")
```

### Port API examples

Below some examples on how to use the Port API in your `script.py`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/framework/processing/py/port/api/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

def asset_path(asset):
return os.path.join(os.path.join(os.path.dirname(__file__), "../assets"), asset)


def open_asset(asset):
path = asset_path(asset)
return open(path, "r")


def read_asset(asset):
file = open_asset(asset)
return file.read()
1 change: 1 addition & 0 deletions src/framework/processing/py/port/assets/hello_world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!
3 changes: 3 additions & 0 deletions src/framework/processing/py/port/script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import port.api.props as props
from port.api.assets import *
from port.api.commands import (CommandSystemDonate, CommandSystemExit, CommandUIRender)

import pandas as pd
Expand All @@ -7,6 +8,8 @@


def process(sessionId):
print(read_asset("hello_world.txt"))

key = "zip-contents-example"
meta_data = []
meta_data.append(("debug", f"{key}: start"))
Expand Down
1 change: 1 addition & 0 deletions src/framework/processing/py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "port"
version = "0.0.0"
description = "Port package with Data Donation logic"
authors = ["Emiel van der Veen <[email protected]>"]
include = [{ path = "port/assets", format = ["sdist", "wheel"] }]

[tool.poetry.dependencies]
python = "^3.11"
Expand Down

0 comments on commit 6f751e5

Please sign in to comment.