예제 #1
0
 def __init__(self,
              challenge_id,
              username,
              project_slug,
              ssh_private_key=None,
              personal_access_token=None,
              **kwargs):
     # if no gitlab project available tell the user to create one by
     # redirecting him to this page https://gitlab.aicrowd.com/projects/new
     self.challenge_id = challenge_id
     self.git_username = username
     self.git_project_slug = project_slug
     print(ssh_private_key, personal_access_token, project_slug, username)
     self.git_repo_username = self.git_username
     if (ssh_private_key):
         self.command_git_url = 'git@%s:%s/%s.git' % (
             GITLAB_URL, self.git_repo_username, self.git_project_slug)
         self.git = Git(ssh_private_key=ssh_private_key)
         self.git.remote('add ssh-submission %s' % (self.command_git_url))
     elif personal_access_token:
         self.command_git_url = 'https://*****:*****@%s/%s/%s.git' % (
             personal_access_token, GITLAB_URL, self.git_repo_username,
             self.git_project_slug)
         self.git = Git()
         self.git.remote('add http-submission %s' % (self.command_git_url))
예제 #2
0
    def helm_validate(self, grader_url, repo_tag='master'):

        # Clone necessary repositories
        os.mkdir('.validate')
        os.chdir('.validate')
        Git().clone(f"{grader_url} evaluator-repository")
        os.chdir('evaluator-repository')
        subprocess.run(f"git checkout {repo_tag}".split(),
                       stdout=subprocess.DEVNULL)
        Git().clone(
            f"{self.config.settings['templates_url']} evaluator-templates")

        # Get the template name from aicrowd.yaml
        with open('aicrowd.yaml', 'r') as infile:
            proc = subprocess.Popen('yq -r .challenge.template'.split(),
                                    stdin=infile,
                                    stdout=subprocess.PIPE)
        template = proc.stdout.read().decode('utf-8').strip()
        print(f"Detected template name as: {template}")

        # Copy the helm template to the directory having grader
        os.mkdir('.aicrowd')
        subprocess.run(
            f'cp -r evaluator-templates/{template} .aicrowd'.split())
        subprocess.run(
            f'mv .aicrowd/{template}/aicrowd.yaml .aicrowd/{template}/values.yaml'
            .split())
        subprocess.run(
            f'cd .aicrowd/{template} && chmod +x ./pre-start.sh && ./pre-start.sh && cd -'
            .split(),
            stdout=subprocess.DEVNULL,
            shell=True)
        subprocess.run(
            f'ls | xargs -n1 -I{{}} rm -rf .aicrowd/{template}/{{}}'.split(),
            shell=True,
            stdout=subprocess.DEVNULL)
        subprocess.run(f'cp -r * .aicrowd/{template}', shell=True)

        # Expand helm templates
        proc = subprocess.run(
            f'helm template --values aicrowd.yaml .aicrowd/{template} -f aicrowd.yaml > desired-fs.yaml',
            shell=True)
        os.chdir('../..')
        shutil.rmtree('./.validate')
        if proc.returncode is 0:
            return True

        return False
예제 #3
0
 def list_examples(self):
     if not os.path.exists(self.examples_dir):
         Git().clone(
             f"{self.config.settings['examples_url']} {self.examples_dir}")
         #subprocess.run(f"git clone {self.config.settings['examples_url']} {self.examples_dir}".split())
     examples = [
         f.name for f in os.scandir(self.examples_dir)
         if f.is_dir() and f.name[0] is not '.'
     ]
     return examples
예제 #4
0
 def clone_template(self, template):
     Git().clone('--progress ' + template['git_addr'])
예제 #5
0
 def clone_baseline(self, baseline):
     if '.git' in baseline['git_addr']:
         Git().clone('--progress ' + baseline['git_addr'])
     else:
         wget.download(baseline['git_addr'])
예제 #6
0
 def get_challenge_project(self):
     response = aicrowd_api.get_challenge(self.challenge_id)
     git_addr = response['git_addr']
     Git().clone('--progress ' + git_addr)
     return self.challenge_id
예제 #7
0
class Submission:
    def __init__(self,
                 challenge_id,
                 username,
                 project_slug,
                 ssh_private_key=None,
                 personal_access_token=None,
                 **kwargs):
        # if no gitlab project available tell the user to create one by
        # redirecting him to this page https://gitlab.aicrowd.com/projects/new
        self.challenge_id = challenge_id
        self.git_username = username
        self.git_project_slug = project_slug
        print(ssh_private_key, personal_access_token, project_slug, username)
        self.git_repo_username = self.git_username
        if (ssh_private_key):
            self.command_git_url = 'git@%s:%s/%s.git' % (
                GITLAB_URL, self.git_repo_username, self.git_project_slug)
            self.git = Git(ssh_private_key=ssh_private_key)
            self.git.remote('add ssh-submission %s' % (self.command_git_url))
        elif personal_access_token:
            self.command_git_url = 'https://*****:*****@%s/%s/%s.git' % (
                personal_access_token, GITLAB_URL, self.git_repo_username,
                self.git_project_slug)
            self.git = Git()
            self.git.remote('add http-submission %s' % (self.command_git_url))

        # Add remote "submission" for the project using these details

    def submit_current_project(self, version_number, http, dummy):
        current_directory = os.getcwd()
        self.git.add('.')
        self.git.commit("-m 'updated submission'")
        self.git.tag("-am 'submission-v%s' submission-v%s" %
                     (version_number, version_number))
        if (http):
            self.git.push("-f ssh-submission master")
            self.git.push("-f ssh-submission submission-v%s" %
                          (version_number))
        else:
            self.git.push("-f http-submission master")
            self.git.push("-f http-submission submission-v%s" %
                          (version_number))

        click.echo("Now you can check details of your submission at: "
                   "https://gitlab.aicrowd.com/%s/%s/issues" %
                   (self.git_repo_username, self.git_project_slug))