Skip to content

Commit 95b7832

Browse files
authored
Merge pull request #8 from b-long/develop
Update documentation & packaging
2 parents 06fad77 + 0780a20 commit 95b7832

File tree

8 files changed

+113
-22
lines changed

8 files changed

+113
-22
lines changed

.github/workflows/build-golang-macos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
- name: Test Python wheel
9898
run: |
9999
# Test wheel installation
100-
pip install dist/otdf_python-0.0.10-py3-none-any.whl
100+
pip install dist/otdf_python-0.0.11-py3-none-any.whl
101101
102102
# Test wheel functionality
103103
# python3 validate_otdf_python.py

.github/workflows/build-golang-ubuntu.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
- name: Test Python wheel
128128
run: |
129129
# Test wheel installation
130-
pip install dist/otdf_python-0.0.10-py3-none-any.whl
130+
pip install dist/otdf_python-0.0.11-py3-none-any.whl
131131
132132
# DISABLED: Need to figure out Ubuntu nested VM
133133
# Test wheel functionality

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ repos:
3737
hooks:
3838
- id: codespell
3939
args: ["--ignore-words-list", "b-long, otdf_python", "--skip=go.sum,otdf_python/"]
40+
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
# Ruff version.
43+
rev: v0.6.7
44+
hooks:
45+
# Run the linter.
46+
- id: ruff
47+
# Run the formatter.
48+
- id: ruff-format

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,60 @@ pip install otdf_python
1515

1616
## Usage
1717

18-
See `validate_otdf_python.py` for usage examples.
18+
Simple usage examples are given below. In addition, see the content of `validate_otdf_python.py` .
19+
20+
### Example: Encrypt a string
21+
22+
```python
23+
from otdf_python.gotdf_python import EncryptString
24+
25+
config: EncryptionConfig = _get_configuration()
26+
27+
tdf_manifest_json = EncryptString(inputText="Hello from Python", config=config)
28+
29+
```
30+
31+
### Example: Encrypt a file
32+
33+
```python
34+
from otdf_python.gotdf_python import EncryptFile
35+
from otdf_python.go import Slice_string
36+
37+
with tempfile.TemporaryDirectory() as tmpDir:
38+
print("Created temporary directory", tmpDir)
39+
40+
da = Slice_string(["https://example.com/attr/attr1/value/value1", "https://example.com/attr/attr1/value/value2"])
41+
42+
config: EncryptionConfig = EncryptionConfig(
43+
ClientId="opentdf-sdk",
44+
ClientSecret="secret",
45+
PlatformEndpoint=platformEndpoint,
46+
TokenEndpoint="http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token",
47+
KasUrl=f"http://{platformEndpoint}/kas",
48+
# FIXME: Be careful with binding the 'DataAttributes' field on this struct.
49+
#
50+
# In golang, this is initialized as []string , but passing
51+
# DataAttributes=None, or DataAttributes=[] from Python will fail.
52+
# DataAttributes=...
53+
DataAttributes=da,
54+
)
55+
56+
encrypted_file = Path(tmpDir) / "some-file.tdf"
57+
58+
if encrypted_file.exists():
59+
encrypted_file.unlink()
60+
61+
if encrypted_file.exists():
62+
raise ValueError(
63+
"The output path should not exist before calling 'EncryptFile()'."
64+
)
65+
66+
outputFilePath = EncryptFile(
67+
inputFilePath=str(SOME_PLAINTEXT_FILE),
68+
outputFilePath=str(encrypted_file),
69+
config=config,
70+
)
71+
72+
print(f"The output file was written to destination path: {outputFilePath}")
73+
74+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "otdf-python"
33
# Should match 'setup.py' version number (used for gopy/pybindgen)
4-
version = "0.0.10"
4+
version = "0.0.11"
55
description = ""
66
authors = ["b-long <[email protected]>"]
77
readme = "README.md"

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import setuptools
22

3-
with open("README.md", "r") as fh:
4-
long_description = fh.read()
3+
4+
from pathlib import Path
5+
6+
"""
7+
NOTE: This project uses more than one version of a 'setup.py' file:
8+
* 'setup.py', and
9+
* 'setup_ci.py'
10+
11+
Based on:
12+
https://github.com/popatam/gopy_build_wheel_example/blob/main/setup_ci.py
13+
"""
14+
15+
this_directory = Path(__file__).parent
16+
long_description = (this_directory / "README.md").read_text()
517

618
setuptools.setup(
719
name="otdf_python",
@@ -12,7 +24,7 @@
1224
url="https://github.com/b-long/opentdf-python-sdk",
1325
package_data={"otdf_python": ["*.so"]},
1426
# Should match 'pyproject.toml' version number
15-
version="0.0.10",
27+
version="0.0.11",
1628
author_email="[email protected]",
1729
include_package_data=True,
1830
)

setup_ci.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,39 @@
44
import sys
55
import re
66
from distutils.core import Extension
7+
from pathlib import Path
78

89
import setuptools
910
from setuptools.command.build_ext import build_ext
1011

1112
"""
13+
NOTE: This project uses more than one version of a 'setup.py' file:
14+
* 'setup.py', and
15+
* 'setup_ci.py'
16+
1217
Based on:
1318
https://github.com/popatam/gopy_build_wheel_example/blob/main/setup_ci.py
1419
"""
1520

21+
1622
def normalize(name): # https://peps.python.org/pep-0503/#normalized-names
1723
return re.sub(r"[-_.]+", "-", name).lower()
1824

19-
# PACKAGE_PATH="simple_go_timer"
20-
# PACKAGE_NAME=PACKAGE_PATH.split("/")[-1]
2125

22-
PACKAGE_PATH="gotdf_python"
23-
PACKAGE_NAME="otdf_python"
26+
PACKAGE_PATH = "gotdf_python"
27+
PACKAGE_NAME = "otdf_python"
2428

25-
if sys.platform == 'darwin':
29+
if sys.platform == "darwin":
2630
# PYTHON_BINARY_PATH is setting explicitly for 310 and 311, see build_wheel.yml
2731
# on macos PYTHON_BINARY_PATH must be python bin installed from python.org or from brew
2832
PYTHON_BINARY = os.getenv("PYTHON_BINARY_PATH", sys.executable)
2933
if PYTHON_BINARY == sys.executable:
30-
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pybindgen'])
34+
subprocess.check_call([sys.executable, "-m", "pip", "install", "pybindgen"])
3135
else:
3236
# linux & windows
3337
PYTHON_BINARY = sys.executable
34-
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pybindgen'])
38+
subprocess.check_call([sys.executable, "-m", "pip", "install", "pybindgen"])
39+
3540

3641
def _generate_path_with_gopath() -> str:
3742
go_path = subprocess.check_output(["go", "env", "GOPATH"]).decode("utf-8").strip()
@@ -42,9 +47,14 @@ def _generate_path_with_gopath() -> str:
4247
class CustomBuildExt(build_ext):
4348
def build_extension(self, ext: Extension):
4449
bin_path = _generate_path_with_gopath()
45-
go_env = json.loads(subprocess.check_output(["go", "env", "-json"]).decode("utf-8").strip())
50+
go_env = json.loads(
51+
subprocess.check_output(["go", "env", "-json"]).decode("utf-8").strip()
52+
)
4653

47-
destination = os.path.dirname(os.path.abspath(self.get_ext_fullpath(ext.name))) + f"/{PACKAGE_NAME}"
54+
destination = (
55+
os.path.dirname(os.path.abspath(self.get_ext_fullpath(ext.name)))
56+
+ f"/{PACKAGE_NAME}"
57+
)
4858

4959
subprocess.check_call(
5060
[
@@ -65,15 +75,17 @@ def build_extension(self, ext: Extension):
6575
with open(f"{destination}/__init__.py", "w") as f:
6676
f.write(f"from .{PACKAGE_PATH} import *")
6777

68-
with open("README.md", "r") as fh:
69-
long_description = fh.read()
78+
79+
this_directory = Path(__file__).parent
80+
long_description = (this_directory / "README.md").read_text()
7081

7182
setuptools.setup(
7283
name="otdf_python",
73-
version="0.0.10",
84+
version="0.0.11",
7485
author="b-long",
75-
long_description=long_description,
7686
description="Unofficial OpenTDF SDK for Python.",
87+
long_description_content_type="text/markdown",
88+
long_description=long_description,
7789
url="https://github.com/b-long/opentdf-python-sdk",
7890
classifiers=[
7991
"Programming Language :: Python :: 3",
@@ -85,6 +97,9 @@ def build_extension(self, ext: Extension):
8597
"build_ext": CustomBuildExt,
8698
},
8799
ext_modules=[
88-
Extension(PACKAGE_NAME, [PACKAGE_PATH],)
100+
Extension(
101+
PACKAGE_NAME,
102+
[PACKAGE_PATH],
103+
)
89104
],
90105
)

validate_otdf_python.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def verify_hello():
1919

2020

2121
def _get_configuration() -> EncryptionConfig:
22-
2322
platformEndpoint = "localhost:8080"
2423

2524
config: EncryptionConfig = EncryptionConfig(

0 commit comments

Comments
 (0)