Commit fd7c21f2 authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

Merge branch 'aziz/imports' into 'dev'

remove unused and star imports

See merge request !249
Showing with 22 additions and 77 deletions
+22 -77
......@@ -3,7 +3,6 @@ from typing import List
import pymemri
from ..data.basic import read_file
from ..data.schema import CVUStoredDefinition
CVU_BASE_PATH = Path(pymemri.__file__).parent / "cvu" / "definitions"
......@@ -14,7 +13,7 @@ def get_default_cvu(name: str, base_path: Path = CVU_BASE_PATH) -> CVUStoredDefi
Get a CVU by name.
"""
path = Path(base_path) / name
cvu_str = read_file(path)
cvu_str = Path(path).read_text()
return CVUStoredDefinition(definition=cvu_str, name=name, externalId=name)
......
import json
import zipfile
from urllib.request import urlretrieve
import requests
from tqdm import tqdm
from ..imports import *
from pathlib import Path
Path.ls = lambda x: list(x.iterdir())
PYI_HOME = Path.cwd().parent
......@@ -15,10 +11,6 @@ MEMRI_S3 = "https://memri.s3-eu-west-1.amazonaws.com"
MODEL_DIR.mkdir(parents=True, exist_ok=True)
def read_file(path):
return open(path, "r").read()
def read_json(path):
with open(path) as json_file:
return json.load(json_file)
......
import os
import re
import sys
from datetime import datetime
from getpass import getpass
from pathlib import Path
import requests
from fastprogress.fastprogress import progress_bar
from git import Repo
from loguru import logger
from ..gitlab_api import (
ACCESS_TOKEN_PATH,
DEFAULT_PACKAGE_VERSION,
GITLAB_API_BASE_URL,
MEMRI_GITLAB_BASE_URL,
MEMRI_PATH,
PROJET_ID_PATTERN,
TIME_FORMAT_GITLAB,
GitlabAPI,
)
from ..gitlab_api import DEFAULT_PACKAGE_VERSION, GitlabAPI
DEFAULT_PLUGIN_MODEL_PACKAGE_NAME = "plugin-model-package"
DEFAULT_PYTORCH_MODEL_NAME = "pytorch_model.bin"
......
import json
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional
from typing import TYPE_CHECKING, Any, List
import pandas as pd
......
......@@ -2,7 +2,6 @@ import os
import re
import sys
import urllib
from datetime import datetime
from getpass import getpass
from pathlib import Path
......@@ -13,7 +12,6 @@ from loguru import logger
from pymemri.pod.client import PodClient
from .data.basic import *
from .template.formatter import _plugin_from_template, str_to_gitlab_identifier
MEMRI_PATH = Path.home() / ".memri"
......@@ -61,7 +59,7 @@ class GitlabAPI:
else:
if self.request_auth_if_needed:
print(
f"""
"""
The first time you are uploading a model you need to create an access_token
at https://gitlab.memri.io/-/profile/personal_access_tokens?name=Model+Access+token&scopes=api
Click at the blue button with 'Create personal access token'"
......@@ -131,7 +129,7 @@ class GitlabAPI:
url = f"{GITLAB_API_BASE_URL}/projects/{project_id}/pipeline?ref=main"
res = self.post(url, headers=self.auth_headers, params=self.auth_params)
if res.status_code not in [200, 201]:
logger.error(f"Failed to trigger pipeline")
logger.error("Failed to trigger pipeline")
def project_id_from_name(self, project_name):
iden = str_to_gitlab_identifier(project_name)
......@@ -230,7 +228,7 @@ class GitlabAPI:
actions = []
for file_in_path, file_out_path in path_in2out.items():
content = read_file(file_in_path)
content = Path(file_in_path).read_text()
action_payload = {
"action": "create",
"file_path": file_out_path,
......
import inspect
import json
import os
import random
import re
from collections import Counter
from copy import copy
from pathlib import *
from pathlib import Path
import numpy as np
import requests
......@@ -58,7 +58,7 @@ class OAuthAuthenticator(metaclass=abc.ABCMeta):
@abc.abstractmethod
def get_oauth_url(self):
raise NotImplemented()
raise NotImplementedError
@abc.abstractmethod
def get_tokens_from_code(self, code):
......@@ -69,7 +69,7 @@ class OAuthAuthenticator(metaclass=abc.ABCMeta):
'refresh_token': '...'
}
"""
raise NotImplemented()
raise NotImplementedError
@abc.abstractmethod
def refresh_tokens(self):
......@@ -82,11 +82,11 @@ class OAuthAuthenticator(metaclass=abc.ABCMeta):
"""
# use self.pluginRun.account[0].refreshToken
raise NotImplemented()
raise NotImplementedError
@abc.abstractmethod
def verify_access_token(self, token):
"""
Check if existing token is working. If this returns True, then user interaction will not be needed.
"""
raise NotImplemented()
raise NotImplementedError
......@@ -9,6 +9,7 @@ from ...cvu.utils import get_default_cvu
from ...pod.client import DEFAULT_POD_ADDRESS, PodClient
from ...pod.utils import read_pod_key
from ..states import RUN_USER_ACTION_COMPLETED, RUN_USER_ACTION_NEEDED
from .credentials import PLUGIN_DIR, read_json, read_username_password
class PasswordAuthenticator:
......@@ -91,14 +92,6 @@ def set_account_credentials(pod_client, run_id, username, password):
print(f"Setting username and password for {run_id}'s Account'")
from fastscript import Param, call_parse
from ...data.basic import *
from ...pod.client import DEFAULT_POD_ADDRESS, PodClient
from .credentials import *
from .credentials import PLUGIN_DIR
@call_parse
def simulate_enter_credentials(
run_id: Param("run id that requires the password", str) = None,
......@@ -131,5 +124,5 @@ def simulate_enter_credentials(
logger.info(f"Reading run id from {run_path}")
run_id = read_json(run_path)["id"]
except Exception as e:
logger.error(f"No run_id specified and could not read current run information")
logger.error("No run_id specified and could not read current run information")
set_account_credentials(client, run_id, username, password)
......@@ -144,7 +144,7 @@ def simulate_run_plugin_from_frontend(
owner_key = read_pod_key("owner_key")
params = [pod_full_address, database_key, owner_key]
if None in params:
raise ValueError(f"Missing Pod credentials")
raise ValueError("Missing Pod credentials")
client = PodClient(url=pod_full_address, database_key=database_key, owner_key=owner_key)
print(f"pod_full_address={pod_full_address}\nowner_key={owner_key}\n")
......@@ -171,5 +171,5 @@ def simulate_run_plugin_from_frontend(
plugin_dir = run.containerImage
write_run_info(plugin_dir, run.id)
print(f"*Check the pod log/console for debug output.*")
print("*Check the pod log/console for debug output.*")
return run
......@@ -40,7 +40,7 @@ class PluginRunStatusListener:
if run.status == self.status:
self.callback()
except Exception as e:
logger.error(f"Could not get run in status listener")
logger.error("Could not get run in status listener")
class PodHTTPStatusListener:
......@@ -95,7 +95,7 @@ class PodHTTPStatusListener:
if e.status == self.http_status:
self.callback()
except Exception as e:
logger.error(f"Could not get run in httpstatus listener")
logger.error("Could not get run in httpstatus listener")
def force_exit_callback():
......
......@@ -575,7 +575,7 @@ class PodClient:
self.api.send_trigger_status(item_id, trigger_id, status)
return True
except Exception as e:
logger.error(f"Failed to send trigger status to the POD")
logger.error("Failed to send trigger status to the POD")
return False
def get_oauth2_access_token(self, platform):
......
......@@ -2,7 +2,7 @@ from pathlib import Path
from loguru import logger
from ..data.basic import *
from ..data.basic import read_json
PYMEMRI_FOLDER = ".pymemri"
POD_KEYS_FOLDER = "pod_keys"
......
import importlib
import inspect
import json
import os
......
import re
import subprocess
import urllib
import zipfile
from pathlib import Path, PurePosixPath
from string import Template
......@@ -25,7 +24,7 @@ GITLAB_GROUPS = ["memri", "plugins"]
def get_remote_url():
path = Path(".")
url = subprocess.getoutput(f"git config --get remote.origin.url")
url = subprocess.getoutput("git config --get remote.origin.url")
if not url:
raise ValueError(
f"You can only run this from a initialized gitlab repository, and '{path}' is not an initialized git repository"
......@@ -176,7 +175,7 @@ def get_template_replace_dict(
try:
repo_owner, repo_name = infer_git_info(repo_url)
except ValueError:
url_inf, owner_inf, name_inf = None, None, None
url_inf = None
logger.error(
"Could not infer git information from current directory, no initialized repository found."
)
......
# hide
import os
from pathlib import Path
......@@ -10,9 +9,5 @@ def get_ci_variables(*varnames):
return {varname: os.environ.get(varname) for varname in varnames}
# hide
from pathlib import Path
def get_project_root():
return Path(__file__).parent.parent
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment