-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add complete python SDK and example
Problem: we will want to interact from Python Solution: add a complete python SDK and client example. I am also adding the gopher logo (branding). Signed-off-by: vsoch <[email protected]>
- Loading branch information
Showing
37 changed files
with
786 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,11 @@ RUN flux keygen | |
RUN git clone https://github.com/flux-framework/flux-sched.git /opt/flux-sched | ||
|
||
# Go dependencies for protobuf | ||
RUN apt -y update && apt -y upgrade && apt install --no-install-recommends -y protobuf-compiler curl && \ | ||
go install google.golang.org/protobuf/cmd/[email protected] && \ | ||
go install google.golang.org/grpc/cmd/[email protected] | ||
RUN apt -y update && apt -y upgrade && apt install --no-install-recommends -y protobuf-compiler python3-pip python3-venv curl && \ | ||
go install google.golang.org/protobuf/cmd/[email protected] && \ | ||
go install google.golang.org/grpc/cmd/[email protected] && \ | ||
ln -s /usr/bin/python3 /usr/bin/python && \ | ||
python3 -m pip install grpcio-tools | ||
|
||
# These need to be on the LD_LIBRARY_PATH for the server to find at runtime | ||
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib:/usr/lib/flux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
} | ||
}, | ||
"postStartCommand": "git config --global --add safe.directory /workspaces/fluxion" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: test rainbow | ||
|
||
on: | ||
pull_request: [] | ||
|
||
jobs: | ||
formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup black linter | ||
run: conda create --quiet --name black pyflakes | ||
|
||
- name: Check Spelling | ||
uses: crate-ci/typos@7ad296c72fa8265059cc03d1eda562fbdfcd6df2 # v1.9.0 | ||
with: | ||
files: ./README.md | ||
|
||
- name: Lint and format Python code | ||
run: | | ||
export PATH="/usr/share/miniconda/bin:$PATH" | ||
source activate black | ||
pip install -r .github/dev-requirements.txt | ||
cd python/v1 | ||
pre-commit run --all-files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
vendor | ||
bin | ||
.eggs | ||
__pycache__ | ||
env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ RUN git clone https://github.com/flux-framework/flux-sched.git /opt/flux-sched | |
|
||
# Go dependencies for protobuf | ||
RUN apt -y update && apt -y upgrade && apt install --no-install-recommends -y protobuf-compiler curl && \ | ||
go install google.golang.org/protobuf/cmd/[email protected] && \ | ||
go install google.golang.org/protobuf/cmd/[email protected] && \ | ||
go install google.golang.org/grpc/cmd/[email protected] | ||
|
||
# These need to be on the LD_LIBRARY_PATH for the server to find at runtime | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,28 @@ $(LOCALBIN): | |
mkdir -p $(LOCALBIN) | ||
|
||
.PHONY: build | ||
build: | ||
build: | ||
docker build --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(REGISTRY)/$(IMAGE) . | ||
|
||
.PHONY: server | ||
server: | ||
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o bin/server cmd/main.go | ||
server: | ||
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o bin/server cmd/server/server.go | ||
|
||
.PHONY: protoc | ||
protoc: $(LOCALBIN) | ||
GOBIN=$(LOCALBIN) go install google.golang.org/protobuf/cmd/[email protected] | ||
GOBIN=$(LOCALBIN) go install google.golang.org/grpc/cmd/[email protected] | ||
|
||
# You can use make protoc to download proto | ||
.PHONY: proto | ||
proto: protoc | ||
PATH=$(LOCALBIN):${PATH} protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/fluxion-grpc/fluxion.proto | ||
|
||
.PHONY: python | ||
python: python ## Generate python proto files in python | ||
# pip install grpcio-tools | ||
# pip freeze | grep grpcio-tools | ||
mkdir -p python/v1/fluxion/protos | ||
cd python/v1/fluxion/protos | ||
python -m grpc_tools.protoc -I./pkg/fluxion-grpc --python_out=./python/v1/fluxion/protos --pyi_out=./python/v1/fluxion/protos --grpc_python_out=./python/v1/fluxion/protos ./pkg/fluxion-grpc/fluxion.proto | ||
sed -i 's/import fluxion_pb2 as fluxion__pb2/from . import fluxion_pb2 as fluxion__pb2/' ./python/v1/fluxion/protos/fluxion_pb2_grpc.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import argparse | ||
import os | ||
import sys | ||
|
||
from fluxion.protos import fluxion_pb2 | ||
from fluxion.client import FluxionClient | ||
import fluxion.utils as utils | ||
import time | ||
|
||
# Config file from a few directories up | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
root = here | ||
|
||
# examples directory | ||
root = os.path.dirname(root) | ||
|
||
|
||
def get_parser(): | ||
parser = argparse.ArgumentParser(description="🦩️ Fluxion Python client example") | ||
parser.add_argument( | ||
"--host", help="host of fluxion graph database", default="localhost:4242" | ||
) | ||
parser.add_argument( | ||
"--jobspec", | ||
help="Path to example jobspec to use", | ||
default=os.path.join(root, "go", "jobspec.yaml"), | ||
) | ||
parser.add_argument( | ||
"--cluster-nodes", | ||
help="Nodes to provide to initialize graph", | ||
default=os.path.join(root, "go", "cluster-nodes.json"), | ||
) | ||
return parser | ||
|
||
|
||
def main(): | ||
parser = get_parser() | ||
args, _ = parser.parse_known_args() | ||
cli = FluxionClient(host=args.host) | ||
|
||
# Read in the jobspec and nodes to raw text | ||
jobspec = utils.read_file(args.jobspec) | ||
nodes_jgf = utils.read_file(args.cluster_nodes) | ||
|
||
# Step 1: Init the fluxion graph | ||
response = cli.init(nodes_jgf) | ||
if response.status == fluxion_pb2.InitResponse.ResultType.INIT_SUCCESS: | ||
print("✅️ Init of Fluxion resource graph success!") | ||
else: | ||
sys.exit(f"Issue with init, return code {response.status}") | ||
|
||
# Step 2: Do a match | ||
response = cli.match(jobspec) | ||
if response.status == fluxion_pb2.MatchResponse.ResultType.MATCH_SUCCESS: | ||
print("✅️ Match of jobspec to Fluxion graph success!") | ||
else: | ||
sys.exit(f"Issue with match, return code {response.status}") | ||
|
||
print("😴️ Sleeping for 3 seconds before cancel...") | ||
time.sleep(3) | ||
|
||
# Step 3: cancel the job | ||
jobid = response.jobid | ||
response = cli.cancel(jobid=jobid) | ||
if response.status == fluxion_pb2.CancelResponse.ResultType.CANCEL_SUCCESS: | ||
print(f"✅️ Cancel of jobid {jobid} success!") | ||
else: | ||
sys.exit(f"Issue with cancel, return code {response.status}") | ||
|
||
print("👋️ That's all folks!") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.