From b62b27597dbb4edfde757683005ecb3af8b2255f Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:09:59 +0300 Subject: [PATCH 01/25] Reverted checking medperf updates via git branch as client would be installed not from git in the future --- cli/medperf/cli.py | 2 -- cli/medperf/utils.py | 36 ------------------------------------ cli/requirements.txt | 1 - 3 files changed, 39 deletions(-) diff --git a/cli/medperf/cli.py b/cli/medperf/cli.py index 078d37841..c6524a21a 100644 --- a/cli/medperf/cli.py +++ b/cli/medperf/cli.py @@ -17,7 +17,6 @@ import medperf.commands.association.association as association import medperf.commands.compatibility_test.compatibility_test as compatibility_test import medperf.commands.storage as storage -from medperf.utils import check_for_updates app = typer.Typer() app.add_typer(mlcube.app, name="mlcube", help="Manage mlcubes") @@ -100,6 +99,5 @@ def main( logging.info(f"Running MedPerf v{__version__} on {loglevel} logging level") logging.info(f"Executed command: {' '.join(sys.argv[1:])}") - check_for_updates() config.ui.print(f"MedPerf {__version__}") diff --git a/cli/medperf/utils.py b/cli/medperf/utils.py index c054d64c1..227bb3dca 100644 --- a/cli/medperf/utils.py +++ b/cli/medperf/utils.py @@ -19,7 +19,6 @@ from typing import List from colorama import Fore, Style from pexpect.exceptions import TIMEOUT -from git import Repo, GitCommandError import medperf.config as config from medperf.exceptions import ExecutionError, MedperfException, InvalidEntityError @@ -442,41 +441,6 @@ def filter_latest_associations(associations, entity_key): return latest_associations -def check_for_updates() -> None: - """Check if the current branch is up-to-date with its remote counterpart using GitPython.""" - repo = Repo(config.BASE_DIR) - if repo.bare: - logging.debug('Repo is bare') - return - - logging.debug(f'Current git commit: {repo.head.commit.hexsha}') - - try: - for remote in repo.remotes: - remote.fetch() - - if repo.head.is_detached: - logging.debug('Repo is in detached state') - return - - current_branch = repo.active_branch - tracking_branch = current_branch.tracking_branch() - - if tracking_branch is None: - logging.debug("Current branch does not track a remote branch.") - return - if current_branch.commit.hexsha == tracking_branch.commit.hexsha: - logging.debug('No git branch updates.') - return - - logging.debug(f'Git branch updates found: {current_branch.commit.hexsha} -> {tracking_branch.commit.hexsha}') - config.ui.print_warning('MedPerf client updates found. Please, update your MedPerf installation.') - except GitCommandError as e: - logging.debug('Exception raised during updates check. Maybe user checked out repo with git@ and private key' - 'or repo is in detached / non-tracked state?') - logging.debug(e) - - class spawn_and_kill: def __init__(self, cmd, timeout=None, *args, **kwargs): self.cmd = cmd diff --git a/cli/requirements.txt b/cli/requirements.txt index 5a5240ba6..4ddb37547 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -21,4 +21,3 @@ schema==0.7.5 setuptools<=66.1.1 email-validator==2.0.0 auth0-python==4.3.0 -GitPython==3.1.41 From bcf4292beecaf3f8a470fda7ca8f3dac0b3c79d8 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:10:31 +0300 Subject: [PATCH 02/25] Added __init__ to submodules --- cli/medperf/commands/__init__.py | 0 cli/medperf/commands/association/__init__.py | 0 cli/medperf/commands/auth/__init__.py | 0 cli/medperf/commands/benchmark/__init__.py | 0 cli/medperf/commands/compatibility_test/__init__.py | 0 cli/medperf/commands/dataset/__init__.py | 0 cli/medperf/commands/mlcube/__init__.py | 0 cli/medperf/commands/result/__init__.py | 0 cli/medperf/comms/__init__.py | 0 cli/medperf/entities/__init__.py | 0 cli/medperf/tests/commands/auth/__init__.py | 0 cli/medperf/tests/comms/__init__.py | 0 cli/medperf/tests/comms/entity_resources/__init__.py | 0 cli/medperf/tests/comms/entity_resources/sources/__init__.py | 0 cli/medperf/tests/entities/__init__.py | 0 cli/medperf/tests/ui/__init__.py | 0 cli/medperf/ui/__init__.py | 0 17 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cli/medperf/commands/__init__.py create mode 100644 cli/medperf/commands/association/__init__.py create mode 100644 cli/medperf/commands/auth/__init__.py create mode 100644 cli/medperf/commands/benchmark/__init__.py create mode 100644 cli/medperf/commands/compatibility_test/__init__.py create mode 100644 cli/medperf/commands/dataset/__init__.py create mode 100644 cli/medperf/commands/mlcube/__init__.py create mode 100644 cli/medperf/commands/result/__init__.py create mode 100644 cli/medperf/comms/__init__.py create mode 100644 cli/medperf/entities/__init__.py create mode 100644 cli/medperf/tests/commands/auth/__init__.py create mode 100644 cli/medperf/tests/comms/__init__.py create mode 100644 cli/medperf/tests/comms/entity_resources/__init__.py create mode 100644 cli/medperf/tests/comms/entity_resources/sources/__init__.py create mode 100644 cli/medperf/tests/entities/__init__.py create mode 100644 cli/medperf/tests/ui/__init__.py create mode 100644 cli/medperf/ui/__init__.py diff --git a/cli/medperf/commands/__init__.py b/cli/medperf/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/association/__init__.py b/cli/medperf/commands/association/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/auth/__init__.py b/cli/medperf/commands/auth/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/benchmark/__init__.py b/cli/medperf/commands/benchmark/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/compatibility_test/__init__.py b/cli/medperf/commands/compatibility_test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/dataset/__init__.py b/cli/medperf/commands/dataset/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/mlcube/__init__.py b/cli/medperf/commands/mlcube/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/commands/result/__init__.py b/cli/medperf/commands/result/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/comms/__init__.py b/cli/medperf/comms/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/entities/__init__.py b/cli/medperf/entities/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/commands/auth/__init__.py b/cli/medperf/tests/commands/auth/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/comms/__init__.py b/cli/medperf/tests/comms/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/comms/entity_resources/__init__.py b/cli/medperf/tests/comms/entity_resources/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/comms/entity_resources/sources/__init__.py b/cli/medperf/tests/comms/entity_resources/sources/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/entities/__init__.py b/cli/medperf/tests/entities/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/tests/ui/__init__.py b/cli/medperf/tests/ui/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/cli/medperf/ui/__init__.py b/cli/medperf/ui/__init__.py new file mode 100644 index 000000000..e69de29bb From 04251f680e95cdeaffc400df834bfc936c2d4f5c Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:11:27 +0300 Subject: [PATCH 03/25] Moved local server cert / token to ~/,medperf_config/ --- cli/medperf/config.py | 9 ++++----- cli/setup.py | 6 +++--- server/seed.py | 6 +++--- server/setup-dev-server.sh | 9 ++++++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cli/medperf/config.py b/cli/medperf/config.py index 0391e045e..c78d6b69c 100644 --- a/cli/medperf/config.py +++ b/cli/medperf/config.py @@ -1,8 +1,6 @@ from ._version import __version__ from pathlib import Path -BASE_DIR = Path(__file__).resolve().parent.parent.parent - major_version, minor_version, patch_version = __version__.split(".") # MedPerf server @@ -10,7 +8,6 @@ certificate = None local_server = "https://localhost:8000" -local_certificate = str(BASE_DIR / "server" / "cert.crt") comms = "REST" @@ -39,14 +36,16 @@ access_token_storage_id = "medperf_access_token" refresh_token_storage_id = "medperf_refresh_token" -local_tokens_path = BASE_DIR / "mock_tokens" / "tokens.json" - # Storage config config_storage = Path.home().resolve() / ".medperf_config" config_path = str(config_storage / "config.yaml") auth_jwks_file = str(config_storage / ".jwks") creds_folder = str(config_storage / ".tokens") +local_server_config_storage = config_storage / ".local_server" +local_tokens_path = local_server_config_storage / "tokens.json" +local_certificate = str(local_server_config_storage / "cert.crt") + images_folder = ".images" trash_folder = ".trash" logs_folder = "logs" diff --git a/cli/setup.py b/cli/setup.py index bd4362d15..383347ed9 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages from medperf._version import __version__ with open("requirements.txt", "r") as f: @@ -15,10 +15,10 @@ name="medperf", version=__version__, description="CLI Tool for federated benchmarking on medical private data", - url="https://github.com/aristizabal95/medperf", + url="https://github.com/mlcommons/medperf", author="MLCommons", license="Apache 2.0", - packages=["medperf"], + packages=find_packages(where="."), install_requires=requires, python_requires=">=3.6", entry_points=""" diff --git a/server/seed.py b/server/seed.py index be4d387f4..4da1d47a4 100644 --- a/server/seed.py +++ b/server/seed.py @@ -13,7 +13,7 @@ from pathlib import Path import json -REPO_BASE_DIR = Path(__file__).resolve().parent.parent +CONFIG_DIR = Path("~/.medperf_config/.local_server/") def seed(args): @@ -46,8 +46,8 @@ def seed(args): if __name__ == "__main__": - default_cert_file = str(REPO_BASE_DIR / "server" / "cert.crt") - default_tokens_file = str(REPO_BASE_DIR / "mock_tokens" / "tokens.json") + default_cert_file = str(CONFIG_DIR / "cert.crt") + default_tokens_file = str(CONFIG_DIR / "tokens.json") parser = argparse.ArgumentParser(description="Seed the db with demo entries") parser.add_argument( diff --git a/server/setup-dev-server.sh b/server/setup-dev-server.sh index c2694bf3f..5fddd43b3 100644 --- a/server/setup-dev-server.sh +++ b/server/setup-dev-server.sh @@ -9,19 +9,22 @@ do esac done +CONFIG_PATH=$HOME/.medperf_config/.local_server DEPLOY="${DEPLOY:-1}" CERT_GENERATE="${CERT_GENERATE:-1}" -CERT_FILE="${CERT_FILE:-$(realpath cert.crt)}" -KEY_FILE="${KEY_FILE:-$(realpath cert.key)}" +CERT_FILE="${CERT_FILE:-$CONFIG_PATH/cert.crt}" +KEY_FILE="${KEY_FILE:-$CONFIG_PATH/cert.key}" RESET_DB="${RESET_DB:-0}" echo $CERT_FILE echo $KEY_FILE echo $DEPLOY echo $CERT_GENERATE -echo $CERT_PATH echo $RESET_DB +echo $CONFIG_PATH +mkdir -p $CONFIG_PATH +cp ../mock_tokens/tokens.json $CONFIG_PATH/tokens.json if [ -z "$CERT_FILE" ] then From 41f1c9ccfb59e1e9d3ac540815001dc2e2d9e753 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:15:24 +0300 Subject: [PATCH 04/25] Fix cert locations for ci --- .github/workflows/auth-ci.yml | 2 +- .github/workflows/local-ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auth-ci.yml b/.github/workflows/auth-ci.yml index b41b695bc..6f29aca47 100644 --- a/.github/workflows/auth-ci.yml +++ b/.github/workflows/auth-ci.yml @@ -48,7 +48,7 @@ jobs: - name: Run django server in background with generated certs working-directory: ./server - run: sh setup-dev-server.sh & sleep 6 + run: sh setup-dev-server.sh -c cert.crt -k cert.key & sleep 6 - name: Run server integration tests working-directory: ./server diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index e48a4b0de..7cb10d963 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -49,7 +49,7 @@ jobs: - name: Run django server in background with generated certs working-directory: ./server - run: sh setup-dev-server.sh & sleep 6 + run: sh setup-dev-server.sh -c cert.crt -k cert.key & sleep 6 - name: Run server integration tests working-directory: ./server From a4490ff354ef7b8dd017f8f036d8a763aa330240 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:35:44 +0300 Subject: [PATCH 05/25] ci debug --- .github/workflows/auth-ci.yml | 4 +++- .github/workflows/docker-ci.yml | 8 +++++++- .github/workflows/local-ci.yml | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auth-ci.yml b/.github/workflows/auth-ci.yml index 6f29aca47..03cb51832 100644 --- a/.github/workflows/auth-ci.yml +++ b/.github/workflows/auth-ci.yml @@ -52,7 +52,9 @@ jobs: - name: Run server integration tests working-directory: ./server - run: python seed.py --cert cert.crt --auth online + run: | + ls | grep cert + python seed.py --cert cert.crt --auth online - name: Run client integration tests working-directory: . diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index b7d778782..2764c9ff2 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -51,6 +51,10 @@ jobs: working-directory: ./server run: sh setup-dev-server.sh -c cert.crt -k cert.key -d 0 + - name: [DEBUG] list certs + working-directory: ./server + run: ls | grep cert + - name: Build container image working-directory: ./server run: | @@ -59,7 +63,9 @@ jobs: - name: Run server in background working-directory: ./server - run: PORT=8080 && docker run --name medperf_api -d -p 8000:${PORT} -e PORT=${PORT} -e SSL_FLAGS="--certfile=cert.crt --keyfile=cert.key" ${{ env.IMAGE_NAME }} + run: | + ls | grep cert + PORT=8080 && docker run --name medperf_api -d -p 8000:${PORT} -e PORT=${PORT} -e SSL_FLAGS="--certfile=cert.crt --keyfile=cert.key" ${{ env.IMAGE_NAME }} - name: Run server integration tests working-directory: ./server diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 7cb10d963..99602321b 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -53,7 +53,9 @@ jobs: - name: Run server integration tests working-directory: ./server - run: python seed.py --cert cert.crt + run: | + ls | grep cert + python seed.py --cert cert.crt - name: Run chestxray demo working-directory: . From a0279d14ecd138d4e9a2386af2e05c6daa811f74 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 27 Feb 2024 21:51:02 +0300 Subject: [PATCH 06/25] debug ci --- .github/workflows/local-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 99602321b..063941896 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -55,6 +55,7 @@ jobs: working-directory: ./server run: | ls | grep cert + ls ~/.medperf_config/.local_server/ python seed.py --cert cert.crt - name: Run chestxray demo From 09db12419ce93eda45fd64a4854ba01cfbe16a08 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 16:42:33 +0300 Subject: [PATCH 07/25] Moved mock_tokens placement to seed.py --- .github/workflows/auth-ci.yml | 4 +--- .github/workflows/docker-ci.yml | 8 +------- server/seed.py | 9 ++++++--- server/setup-dev-server.sh | 1 - 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/auth-ci.yml b/.github/workflows/auth-ci.yml index 03cb51832..6f29aca47 100644 --- a/.github/workflows/auth-ci.yml +++ b/.github/workflows/auth-ci.yml @@ -52,9 +52,7 @@ jobs: - name: Run server integration tests working-directory: ./server - run: | - ls | grep cert - python seed.py --cert cert.crt --auth online + run: python seed.py --cert cert.crt --auth online - name: Run client integration tests working-directory: . diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 2764c9ff2..b7d778782 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -51,10 +51,6 @@ jobs: working-directory: ./server run: sh setup-dev-server.sh -c cert.crt -k cert.key -d 0 - - name: [DEBUG] list certs - working-directory: ./server - run: ls | grep cert - - name: Build container image working-directory: ./server run: | @@ -63,9 +59,7 @@ jobs: - name: Run server in background working-directory: ./server - run: | - ls | grep cert - PORT=8080 && docker run --name medperf_api -d -p 8000:${PORT} -e PORT=${PORT} -e SSL_FLAGS="--certfile=cert.crt --keyfile=cert.key" ${{ env.IMAGE_NAME }} + run: PORT=8080 && docker run --name medperf_api -d -p 8000:${PORT} -e PORT=${PORT} -e SSL_FLAGS="--certfile=cert.crt --keyfile=cert.key" ${{ env.IMAGE_NAME }} - name: Run server integration tests working-directory: ./server diff --git a/server/seed.py b/server/seed.py index 4da1d47a4..872866f52 100644 --- a/server/seed.py +++ b/server/seed.py @@ -11,10 +11,11 @@ from seed_utils import Server, set_user_as_admin, create_benchmark, create_model from auth_provider_token import auth_provider_token from pathlib import Path +import shutil import json CONFIG_DIR = Path("~/.medperf_config/.local_server/") - +REPO_BASE_DIR = Path(__file__).resolve().parent.parent def seed(args): api_server = Server(host=args.server, cert=args.cert) @@ -47,7 +48,8 @@ def seed(args): if __name__ == "__main__": default_cert_file = str(CONFIG_DIR / "cert.crt") - default_tokens_file = str(CONFIG_DIR / "tokens.json") + local_tokens_file = str(REPO_BASE_DIR / "mock_tokens" / "tokens.json") + dest_tokens_file = str(CONFIG_DIR / "tokens.json") parser = argparse.ArgumentParser(description="Seed the db with demo entries") parser.add_argument( @@ -78,9 +80,10 @@ def seed(args): "--tokens", type=str, help="Path to local tokens file", - default=default_tokens_file, + default=local_tokens_file, ) args = parser.parse_args() if args.cert.lower() == "none": args.cert = None + shutil.copy(args.tokens, dest_tokens_file) # for usage by medperf client seed(args) diff --git a/server/setup-dev-server.sh b/server/setup-dev-server.sh index 5fddd43b3..28824d8da 100644 --- a/server/setup-dev-server.sh +++ b/server/setup-dev-server.sh @@ -24,7 +24,6 @@ echo $RESET_DB echo $CONFIG_PATH mkdir -p $CONFIG_PATH -cp ../mock_tokens/tokens.json $CONFIG_PATH/tokens.json if [ -z "$CERT_FILE" ] then From 82889157a2ad5970c60900261b3752eee6b86a65 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 16:44:28 +0300 Subject: [PATCH 08/25] Linter fix --- server/seed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/seed.py b/server/seed.py index 872866f52..bbb1306b9 100644 --- a/server/seed.py +++ b/server/seed.py @@ -17,6 +17,7 @@ CONFIG_DIR = Path("~/.medperf_config/.local_server/") REPO_BASE_DIR = Path(__file__).resolve().parent.parent + def seed(args): api_server = Server(host=args.server, cert=args.cert) if args.version: From 85086495bf690e1022715cb80659594e93e5a217 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 16:56:13 +0300 Subject: [PATCH 09/25] bugfix --- server/seed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/seed.py b/server/seed.py index bbb1306b9..bad5abfd0 100644 --- a/server/seed.py +++ b/server/seed.py @@ -86,5 +86,6 @@ def seed(args): args = parser.parse_args() if args.cert.lower() == "none": args.cert = None + CONFIG_DIR.mkdir(parents=True, exist_ok=True) shutil.copy(args.tokens, dest_tokens_file) # for usage by medperf client seed(args) From e4ea29190f830dd7e98e1606021a387676d6a44e Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:05:33 +0300 Subject: [PATCH 10/25] ci debug --- .github/workflows/local-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 063941896..6474401fa 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -55,8 +55,8 @@ jobs: working-directory: ./server run: | ls | grep cert - ls ~/.medperf_config/.local_server/ python seed.py --cert cert.crt + ls ~/.medperf_config/.local_server/ - name: Run chestxray demo working-directory: . From e2fbdc16e7fcd5fc364d06f15e4f8933c1646065 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:12:18 +0300 Subject: [PATCH 11/25] ci debug --- .github/workflows/local-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 6474401fa..ef2ddf492 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -56,6 +56,7 @@ jobs: run: | ls | grep cert python seed.py --cert cert.crt + echo "local_server config folder:" ls ~/.medperf_config/.local_server/ - name: Run chestxray demo From 9dc2ead12e573abcc52475cd6c98a97380f4e4a0 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:19:28 +0300 Subject: [PATCH 12/25] ci debug --- server/seed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/seed.py b/server/seed.py index bad5abfd0..2832f1406 100644 --- a/server/seed.py +++ b/server/seed.py @@ -87,5 +87,6 @@ def seed(args): if args.cert.lower() == "none": args.cert = None CONFIG_DIR.mkdir(parents=True, exist_ok=True) + print('config folder:', CONFIG_DIR, CONFIG_DIR.exists()) shutil.copy(args.tokens, dest_tokens_file) # for usage by medperf client seed(args) From c0d439b10e9bf6975db070ec769bb300f6c47cdb Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:27:15 +0300 Subject: [PATCH 13/25] ci debug --- server/seed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/seed.py b/server/seed.py index 2832f1406..c6fc0e3d1 100644 --- a/server/seed.py +++ b/server/seed.py @@ -89,4 +89,5 @@ def seed(args): CONFIG_DIR.mkdir(parents=True, exist_ok=True) print('config folder:', CONFIG_DIR, CONFIG_DIR.exists()) shutil.copy(args.tokens, dest_tokens_file) # for usage by medperf client + print('token file:', dest_tokens_file, Path(dest_tokens_file).exists()) seed(args) From e26e0fd41cccd3256105a42cc259affc7b23dfb0 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:38:47 +0300 Subject: [PATCH 14/25] ci debug --- server/seed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/seed.py b/server/seed.py index c6fc0e3d1..0e416a846 100644 --- a/server/seed.py +++ b/server/seed.py @@ -14,7 +14,7 @@ import shutil import json -CONFIG_DIR = Path("~/.medperf_config/.local_server/") +CONFIG_DIR = Path.home() / ".medperf_config" / ".local_server" REPO_BASE_DIR = Path(__file__).resolve().parent.parent From 14b6877cf97ef08bbe0a8f000a4748511762a2a6 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:46:47 +0300 Subject: [PATCH 15/25] ci fix --- .github/workflows/local-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index ef2ddf492..6f5b73944 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -49,15 +49,15 @@ jobs: - name: Run django server in background with generated certs working-directory: ./server - run: sh setup-dev-server.sh -c cert.crt -k cert.key & sleep 6 + run: sh setup-dev-server.sh & sleep 6 - name: Run server integration tests working-directory: ./server run: | ls | grep cert - python seed.py --cert cert.crt + python seed.py echo "local_server config folder:" - ls ~/.medperf_config/.local_server/ + ls $HOME/.medperf_config/.local_server/ - name: Run chestxray demo working-directory: . From 7da4ecd76d7a47ff0b6135a56653bf259fd46c0b Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 17:53:13 +0300 Subject: [PATCH 16/25] ci fix --- .github/workflows/local-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 6f5b73944..11ba30937 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -57,7 +57,7 @@ jobs: ls | grep cert python seed.py echo "local_server config folder:" - ls $HOME/.medperf_config/.local_server/ + ls ~/.medperf_config/.local_server/ - name: Run chestxray demo working-directory: . From 99717d722f9f12253453e7eaf4a7e0c2caa1d94a Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 18:00:53 +0300 Subject: [PATCH 17/25] ci fix --- .github/workflows/local-ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 11ba30937..3c566b34a 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -53,11 +53,7 @@ jobs: - name: Run server integration tests working-directory: ./server - run: | - ls | grep cert - python seed.py - echo "local_server config folder:" - ls ~/.medperf_config/.local_server/ + run: python seed.py - name: Run chestxray demo working-directory: . From 90afd4e13cbd150018527ea27a95914b29886b5c Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 18:12:26 +0300 Subject: [PATCH 18/25] ci fix --- .github/workflows/docker-ci.yml | 8 +++++++- .github/workflows/local-ci.yml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index b7d778782..8123d97cb 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -38,7 +38,7 @@ jobs: working-directory: . run: | python -m pip install --upgrade pip - pip install -e cli/ + pip install cli/ pip install -r cli/test-requirements.txt pip install -r server/requirements.txt pip install -r server/test-requirements.txt @@ -57,6 +57,12 @@ jobs: cp ../mock_tokens/tokens.json tokens.json docker build -t ${{ env.IMAGE_NAME }} -f Dockerfile.gha . + - name: Copy configurations for MedPerf client + working-directory: ./server + run: | + cp tokens.json ~/.medperf_config/.local_server/tokens.json + cp cert.crt ~/.medperf_config/.local_server/cert.crt + - name: Run server in background working-directory: ./server run: PORT=8080 && docker run --name medperf_api -d -p 8000:${PORT} -e PORT=${PORT} -e SSL_FLAGS="--certfile=cert.crt --keyfile=cert.key" ${{ env.IMAGE_NAME }} diff --git a/.github/workflows/local-ci.yml b/.github/workflows/local-ci.yml index 3c566b34a..e6c9bdffb 100644 --- a/.github/workflows/local-ci.yml +++ b/.github/workflows/local-ci.yml @@ -38,7 +38,7 @@ jobs: working-directory: . run: | python -m pip install --upgrade pip - pip install -e cli/ + pip install cli/ pip install -r cli/test-requirements.txt pip install -r server/requirements.txt pip install -r server/test-requirements.txt From 9e4548a2a9bd78abde1d3c515ffc50d7d9d1240b Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 18:14:40 +0300 Subject: [PATCH 19/25] Removed -e (editable) mode for cli installation --- .github/workflows/auth-ci.yml | 2 +- .github/workflows/unittests.yml | 2 +- docs/getting_started/installation.md | 2 +- docs/mlcubes/shared/build.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auth-ci.yml b/.github/workflows/auth-ci.yml index 6f29aca47..c91665348 100644 --- a/.github/workflows/auth-ci.yml +++ b/.github/workflows/auth-ci.yml @@ -37,7 +37,7 @@ jobs: working-directory: . run: | python -m pip install --upgrade pip - pip install -e cli/ + pip install cli/ pip install -r cli/test-requirements.txt pip install -r server/requirements.txt pip install -r server/test-requirements.txt diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 11c570b73..a653291a9 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -21,7 +21,7 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - if [ -f cli/requirements.txt ]; then pip install -e cli; fi + if [ -f cli/requirements.txt ]; then pip install cli; fi pip install -r server/requirements.txt pip install -r server/test-requirements.txt - name: Lint with flake8 diff --git a/docs/getting_started/installation.md b/docs/getting_started/installation.md index ee54f8e98..0d857b6d7 100644 --- a/docs/getting_started/installation.md +++ b/docs/getting_started/installation.md @@ -62,7 +62,7 @@ If using Docker, make sure [you can run Docker as a non-root user.](https://docs 3. Install MedPerf from source: ```bash - pip install -e ./cli + pip install ./cli ``` 4. Verify the installation: diff --git a/docs/mlcubes/shared/build.md b/docs/mlcubes/shared/build.md index 33a3c18cf..f5f2af6b2 100644 --- a/docs/mlcubes/shared/build.md +++ b/docs/mlcubes/shared/build.md @@ -13,7 +13,7 @@ MedPerf provides some cookiecutter templates for all the related MLCubes. Additi 2. Install the MedPerf CLI: ```bash - pip install -e cli + pip install cli ``` 3. If you have not done so, create a folder for keeping all MLCubes created in this tutorial: From b68f40210c5fd2a1f6842935e1f1fd2ff6265ed6 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Thu, 29 Feb 2024 18:24:40 +0300 Subject: [PATCH 20/25] ci fix --- .github/workflows/auth-ci.yml | 2 +- .github/workflows/unittests.yml | 2 +- docs/mlcubes/shared/build.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auth-ci.yml b/.github/workflows/auth-ci.yml index c91665348..68439cd6c 100644 --- a/.github/workflows/auth-ci.yml +++ b/.github/workflows/auth-ci.yml @@ -37,7 +37,7 @@ jobs: working-directory: . run: | python -m pip install --upgrade pip - pip install cli/ + pip install ./cli pip install -r cli/test-requirements.txt pip install -r server/requirements.txt pip install -r server/test-requirements.txt diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index a653291a9..904a0657b 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -21,7 +21,7 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - if [ -f cli/requirements.txt ]; then pip install cli; fi + if [ -f cli/requirements.txt ]; then pip install ./cli; fi pip install -r server/requirements.txt pip install -r server/test-requirements.txt - name: Lint with flake8 diff --git a/docs/mlcubes/shared/build.md b/docs/mlcubes/shared/build.md index f5f2af6b2..9fccaf311 100644 --- a/docs/mlcubes/shared/build.md +++ b/docs/mlcubes/shared/build.md @@ -13,7 +13,7 @@ MedPerf provides some cookiecutter templates for all the related MLCubes. Additi 2. Install the MedPerf CLI: ```bash - pip install cli + pip install ./cli ``` 3. If you have not done so, create a folder for keeping all MLCubes created in this tutorial: From 4df80330247035384442a74f07cd89fbaf25d2d1 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Tue, 19 Mar 2024 17:48:37 +0300 Subject: [PATCH 21/25] Changed local dev cert folder to ~/.medperf_dev/ --- .github/workflows/docker-ci.yml | 4 ++-- cli/medperf/config.py | 2 +- server/seed.py | 10 +++++----- server/setup-dev-server.sh | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 8123d97cb..061573982 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -60,8 +60,8 @@ jobs: - name: Copy configurations for MedPerf client working-directory: ./server run: | - cp tokens.json ~/.medperf_config/.local_server/tokens.json - cp cert.crt ~/.medperf_config/.local_server/cert.crt + cp tokens.json ~/.medperf_dev/tokens.json + cp cert.crt ~/.medperf_dev/cert.crt - name: Run server in background working-directory: ./server diff --git a/cli/medperf/config.py b/cli/medperf/config.py index 3196f11d1..37f629296 100644 --- a/cli/medperf/config.py +++ b/cli/medperf/config.py @@ -42,7 +42,7 @@ auth_jwks_file = str(config_storage / ".jwks") creds_folder = str(config_storage / ".tokens") -local_server_config_storage = config_storage / ".local_server" +local_server_config_storage = Path.home().resolve() / ".medperf_dev" local_tokens_path = local_server_config_storage / "tokens.json" local_certificate = str(local_server_config_storage / "cert.crt") diff --git a/server/seed.py b/server/seed.py index 0e416a846..8fb2ba7ed 100644 --- a/server/seed.py +++ b/server/seed.py @@ -14,7 +14,7 @@ import shutil import json -CONFIG_DIR = Path.home() / ".medperf_config" / ".local_server" +DEV_CONFIG_DIR = Path.home() / ".medperf_dev" REPO_BASE_DIR = Path(__file__).resolve().parent.parent @@ -48,9 +48,9 @@ def seed(args): if __name__ == "__main__": - default_cert_file = str(CONFIG_DIR / "cert.crt") + default_cert_file = str(DEV_CONFIG_DIR / "cert.crt") local_tokens_file = str(REPO_BASE_DIR / "mock_tokens" / "tokens.json") - dest_tokens_file = str(CONFIG_DIR / "tokens.json") + dest_tokens_file = str(DEV_CONFIG_DIR / "tokens.json") parser = argparse.ArgumentParser(description="Seed the db with demo entries") parser.add_argument( @@ -86,8 +86,8 @@ def seed(args): args = parser.parse_args() if args.cert.lower() == "none": args.cert = None - CONFIG_DIR.mkdir(parents=True, exist_ok=True) - print('config folder:', CONFIG_DIR, CONFIG_DIR.exists()) + DEV_CONFIG_DIR.mkdir(parents=True, exist_ok=True) + print('config folder:', DEV_CONFIG_DIR, DEV_CONFIG_DIR.exists()) shutil.copy(args.tokens, dest_tokens_file) # for usage by medperf client print('token file:', dest_tokens_file, Path(dest_tokens_file).exists()) seed(args) diff --git a/server/setup-dev-server.sh b/server/setup-dev-server.sh index 28824d8da..fe950cd7e 100644 --- a/server/setup-dev-server.sh +++ b/server/setup-dev-server.sh @@ -9,7 +9,7 @@ do esac done -CONFIG_PATH=$HOME/.medperf_config/.local_server +CONFIG_PATH=$HOME/.medperf_dev DEPLOY="${DEPLOY:-1}" CERT_GENERATE="${CERT_GENERATE:-1}" CERT_FILE="${CERT_FILE:-$CONFIG_PATH/cert.crt}" From 044224fe207de80d202761d85c85c716160f5a13 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Mon, 1 Apr 2024 16:52:37 +0300 Subject: [PATCH 22/25] returned git-update-check back --- cli/medperf/cli.py | 2 ++ cli/medperf/utils.py | 49 +++++++++++++++++++++++++++++++++++++++++--- cli/requirements.txt | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/cli/medperf/cli.py b/cli/medperf/cli.py index 0a23ef879..4fc7102c4 100644 --- a/cli/medperf/cli.py +++ b/cli/medperf/cli.py @@ -17,6 +17,7 @@ import medperf.commands.association.association as association import medperf.commands.compatibility_test.compatibility_test as compatibility_test import medperf.commands.storage as storage +from medperf.utils import check_for_updates from medperf.logging.utils import log_machine_details app = typer.Typer() @@ -101,5 +102,6 @@ def main( logging.info(f"Running MedPerf v{__version__} on {loglevel} logging level") logging.info(f"Executed command: {' '.join(sys.argv[1:])}") log_machine_details() + check_for_updates() config.ui.print(f"MedPerf {__version__}") diff --git a/cli/medperf/utils.py b/cli/medperf/utils.py index ef0c4edb4..2636c6a9d 100644 --- a/cli/medperf/utils.py +++ b/cli/medperf/utils.py @@ -19,6 +19,7 @@ from typing import List from colorama import Fore, Style from pexpect.exceptions import TIMEOUT +from git import Repo, GitCommandError import medperf.config as config from medperf.exceptions import ExecutionError, MedperfException @@ -237,9 +238,9 @@ def check_line(self, line: str) -> bool: # if line matches conditions, it is just logged to debug; else, shown to user return ( - line_pid == self.proc_pid # hide only `mlcube` framework logs - and isinstance(matched_log_level, int) - and matched_log_level < logging.INFO + line_pid == self.proc_pid # hide only `mlcube` framework logs + and isinstance(matched_log_level, int) + and matched_log_level < logging.INFO ) # hide only debug logs return False @@ -427,6 +428,48 @@ def filter_latest_associations(associations, entity_key): return latest_associations +def check_for_updates() -> None: + """Check if the current branch is up-to-date with its remote counterpart using GitPython.""" + repo_root_dir = Path(__file__).resolve().parent.parent.parent + repo = Repo(repo_root_dir) + if repo.bare: + logging.debug("Repo is bare") + return + + logging.debug(f"Current git commit: {repo.head.commit.hexsha}") + + try: + for remote in repo.remotes: + remote.fetch() + + if repo.head.is_detached: + logging.debug("Repo is in detached state") + return + + current_branch = repo.active_branch + tracking_branch = current_branch.tracking_branch() + + if tracking_branch is None: + logging.debug("Current branch does not track a remote branch.") + return + if current_branch.commit.hexsha == tracking_branch.commit.hexsha: + logging.debug("No git branch updates.") + return + + logging.debug( + f"Git branch updates found: {current_branch.commit.hexsha} -> {tracking_branch.commit.hexsha}" + ) + config.ui.print_warning( + "MedPerf client updates found. Please, update your MedPerf installation." + ) + except GitCommandError as e: + logging.debug( + "Exception raised during updates check. Maybe user checked out repo with git@ and private key" + " or repo is in detached / non-tracked state?" + ) + logging.debug(e) + + class spawn_and_kill: def __init__(self, cmd, timeout=None, *args, **kwargs): self.cmd = cmd diff --git a/cli/requirements.txt b/cli/requirements.txt index da564010a..037126d1d 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -23,4 +23,5 @@ email-validator==2.0.0 auth0-python==4.3.0 pandas==2.1.0 watchdog==3.0.0 +GitPython==3.1.41 psutil==5.9.8 From dc136d1a407922a5b0e33e8b50fbf90a177676d1 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Wed, 10 Apr 2024 12:59:30 +0300 Subject: [PATCH 23/25] long_description is required for pypi --- cli/setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/setup.py b/cli/setup.py index 383347ed9..74e239b5f 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -15,6 +15,8 @@ name="medperf", version=__version__, description="CLI Tool for federated benchmarking on medical private data", + long_description=open('../README.md').read(), + long_description_content_type='text/markdown', url="https://github.com/mlcommons/medperf", author="MLCommons", license="Apache 2.0", From 6a83fffb5933f8277e45e7000b199391f62e34a9 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Wed, 10 Apr 2024 13:02:50 +0300 Subject: [PATCH 24/25] git-updates skipped if package not installed from repo with -e flag --- cli/medperf/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/medperf/utils.py b/cli/medperf/utils.py index 2636c6a9d..a930ffb1b 100644 --- a/cli/medperf/utils.py +++ b/cli/medperf/utils.py @@ -19,7 +19,7 @@ from typing import List from colorama import Fore, Style from pexpect.exceptions import TIMEOUT -from git import Repo, GitCommandError +from git import Repo, GitCommandError, InvalidGitRepositoryError import medperf.config as config from medperf.exceptions import ExecutionError, MedperfException @@ -431,7 +431,11 @@ def filter_latest_associations(associations, entity_key): def check_for_updates() -> None: """Check if the current branch is up-to-date with its remote counterpart using GitPython.""" repo_root_dir = Path(__file__).resolve().parent.parent.parent - repo = Repo(repo_root_dir) + try: + repo = Repo(repo_root_dir) + except InvalidGitRepositoryError: # package is installed not in -e mode from git repo + return + if repo.bare: logging.debug("Repo is bare") return From a2a8762f8aaf98f5c771617d457895daf98a64e8 Mon Sep 17 00:00:00 2001 From: Viacheslav Kukushkin Date: Wed, 10 Apr 2024 15:36:37 +0300 Subject: [PATCH 25/25] Linter fix --- cli/medperf/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/medperf/utils.py b/cli/medperf/utils.py index a930ffb1b..21a627aaf 100644 --- a/cli/medperf/utils.py +++ b/cli/medperf/utils.py @@ -238,9 +238,9 @@ def check_line(self, line: str) -> bool: # if line matches conditions, it is just logged to debug; else, shown to user return ( - line_pid == self.proc_pid # hide only `mlcube` framework logs - and isinstance(matched_log_level, int) - and matched_log_level < logging.INFO + line_pid == self.proc_pid # hide only `mlcube` framework logs + and isinstance(matched_log_level, int) + and matched_log_level < logging.INFO ) # hide only debug logs return False