diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 62b3f49..8282264 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -17,7 +17,7 @@ jobs: - name: "Checkout code" uses: actions/checkout@v3 - name: "Generate protobuf files to be included in the distribution" - run: ./bin/gen_proto_files.py + run: ./faasmctl/bin/gen_proto_files.py - name: "Set up Python" uses: actions/setup-python@v4 with: diff --git a/README.md b/README.md index 9fb2599..d618acc 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ running [Faasm](https://github.com/faasm/faasm) cluster. To install `faasmctl` you need a working `pip` (virtual-)environment. Then: ```bash -pip install faasmctl==0.34.0 +pip install faasmctl==0.35.0 ``` ## Usage diff --git a/bin/create_venv.sh b/bin/create_venv.sh index 8279b1d..8e45d9c 100755 --- a/bin/create_venv.sh +++ b/bin/create_venv.sh @@ -21,6 +21,6 @@ pip_cmd install -U pip pip_cmd install -r ${PROJ_ROOT}/dev_requirements.txt # Generate the protobuf files if necessary -${PROJ_ROOT}/bin/gen_proto_files.py +${PROJ_ROOT}/faasmctl/bin/gen_proto_files.py popd >> /dev/null diff --git a/bin/gen_proto_files.py b/faasmctl/bin/gen_proto_files.py similarity index 67% rename from bin/gen_proto_files.py rename to faasmctl/bin/gen_proto_files.py index 0452491..e797f92 100755 --- a/bin/gen_proto_files.py +++ b/faasmctl/bin/gen_proto_files.py @@ -1,14 +1,18 @@ #!/usr/bin/env python3 -from os import listdir, makedirs -from os.path import exists, join +from os import environ, listdir, makedirs +from os.path import dirname, exists, join, realpath +from shutil import rmtree +from sys import argv from subprocess import run +FAASMCTL_ROOT = dirname(dirname(realpath(__file__))) + # Unfortunately, we need to duplicate this constants here as we need to be # able to run this file in standalone mode, as if the proto files are not # generated, some imports in `faasmctl` will fail -GEN_PROTO_DIR = "./faasmctl/util/gen_proto" -FAASM_CLI_IMAGE = "faasm.azurecr.io/cli:0.17.0" +GEN_PROTO_DIR = join(FAASMCTL_ROOT, "util", "gen_proto") +FAASM_CLI_IMAGE = "faasm.azurecr.io/cli" PROTO_FILES = [ "faabric_pb2.py", @@ -16,10 +20,26 @@ ] -def gen_proto_files(): +# We can not import faasmctl here +def get_faasm_version(): + ver_file = join(FAASMCTL_ROOT, "util", "faasm.py") + cmd = "cat {} | grep 'FAASM_VERSION =' | cut -d' ' -f3".format(ver_file) + version = ( + run(cmd, shell=True, check=True, capture_output=True) + .stdout.decode("utf-8") + .strip()[1:-1] + ) + + return version + + +def gen_proto_files(clean=False): """ Generate python proto files to interact with the Faasm cluster """ + if clean: + rmtree(GEN_PROTO_DIR) + if not exists(GEN_PROTO_DIR): makedirs(GEN_PROTO_DIR) @@ -29,9 +49,16 @@ def gen_proto_files(): if pb_files == PROTO_FILES: return - print("Generating Faasm protobuf files...") + if "FAASM_VERSION" in environ: + faasm_ver = environ["FAASM_VERSION"] + else: + faasm_ver = get_faasm_version() + + print("Generating Faasm (v{}) protobuf files...".format(faasm_ver)) tmp_ctr_name = "faasm_gen_proto" - cm = "docker run -d -i --name {} {}".format(tmp_ctr_name, FAASM_CLI_IMAGE) + cm = "docker run -d -i --name {} {}:{}".format( + tmp_ctr_name, FAASM_CLI_IMAGE, faasm_ver + ) run(cm, shell=True, check=True) # Find the right protoc binary @@ -79,4 +106,5 @@ def gen_proto_files(): if __name__ == "__main__": - gen_proto_files() + clean = len(argv) == 2 and argv[1] == "--clean" + gen_proto_files(clean) diff --git a/faasmctl/tasks/__init__.py b/faasmctl/tasks/__init__.py index 0a6e8d9..20e3085 100644 --- a/faasmctl/tasks/__init__.py +++ b/faasmctl/tasks/__init__.py @@ -4,6 +4,7 @@ from . import delete from . import deploy from . import flush +from . import generate from . import invoke from . import logs from . import monitor @@ -15,6 +16,7 @@ cli, delete, deploy, + generate, flush, invoke, logs, diff --git a/faasmctl/tasks/generate.py b/faasmctl/tasks/generate.py new file mode 100644 index 0000000..3588bd3 --- /dev/null +++ b/faasmctl/tasks/generate.py @@ -0,0 +1,14 @@ +from invoke import task +from os.path import join +from subprocess import run +from faasmctl.util.env import PROJ_ROOT + + +@task +def proto(ctx): + """ + (Re)generate the Python protobuf files necessary to interact with Faasm + """ + gen_proto_bin = join(PROJ_ROOT, "bin", "gen_proto_files.py") + gen_cmd = "python3 {} --clean".format(gen_proto_bin) + run(gen_cmd, shell=True, check=True) diff --git a/faasmctl/util/version.py b/faasmctl/util/version.py index 3044b4e..2c7d1c0 100644 --- a/faasmctl/util/version.py +++ b/faasmctl/util/version.py @@ -1,4 +1,4 @@ -FAASMCTL_VERSION = "0.34.0" +FAASMCTL_VERSION = "0.35.0" def get_version(): diff --git a/pyproject.toml b/pyproject.toml index 504bb60..0105231 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "faasmctl" -version = "0.34.0" +version = "0.35.0" authors = [ { name="Faasm Team", email="foo@bar.com" }, ] diff --git a/tasks/git.py b/tasks/git.py index a807090..0a9b7d8 100644 --- a/tasks/git.py +++ b/tasks/git.py @@ -78,7 +78,6 @@ def bump_dep(ctx, faasm=None): files_to_check = [ join(DEV_PROJ_ROOT, "faasmctl", "util", "faasm.py"), - join(DEV_PROJ_ROOT, "bin", "gen_proto_files.py"), ] for f in files_to_check: