2 changed files with 92 additions and 16 deletions
@ -1,29 +1,105 @@ |
|||||
import json |
import json |
||||
import sys |
from urllib import request |
||||
from urllib import request |
from pkg_resources import parse_version |
||||
from pkg_resources import parse_version |
from os import environ, path |
||||
|
from alice.runners.pyutils import PackageManager |
||||
|
from alice.exceptions import ConfigException |
||||
|
|
||||
from alice.exceptions import NonZeroRetcode, RunnerError, ConfigException |
|
||||
|
def grab_from(target): |
||||
|
if "from_env" in target: |
||||
|
return environ[target["from_env"]] |
||||
|
else: |
||||
|
raise ConfigException(f"Unsupported grabber: {target.keys()}") |
||||
|
|
||||
|
|
||||
|
def get_uri(config, default): |
||||
|
if "repo" in config: |
||||
|
return config["repo"].get("uri", default) |
||||
|
return default |
||||
|
|
||||
|
|
||||
|
def get_user(config, default): |
||||
|
if "repo" in config: |
||||
|
if "username" in config["repo"]: |
||||
|
data = config["repo"]["username"] |
||||
|
if isinstance(data, str): |
||||
|
return data |
||||
|
else: |
||||
|
return grab_from(data) |
||||
|
return default |
||||
|
|
||||
|
|
||||
|
def get_pass(config, default): |
||||
|
if "repo" in config: |
||||
|
if "password" in config["repo"]: |
||||
|
data = config["repo"]["password"] |
||||
|
if isinstance(data, str): |
||||
|
return data |
||||
|
else: |
||||
|
return grab_from(data) |
||||
|
return default |
||||
|
|
||||
|
|
||||
|
# Parses and stores the config from yaml |
||||
|
class PypiConfig: |
||||
|
def __init__(self, config={}) -> None: |
||||
|
self.workdir = config.get("workdir", None) |
||||
|
self.repo_uri = get_uri(config, "https://pypi.python.org/pypi") |
||||
|
self.repo_user = get_user(config, None) |
||||
|
self.repo_pass = get_pass(config, None) |
||||
|
self.packages = config.get("packages", set()) |
||||
|
self.upload = config.get("upload", False) |
||||
|
print(self.packages) |
||||
|
|
||||
|
# returns a PyPiConfig with merged values |
||||
|
def copy(self, job_config={}): |
||||
|
p = PypiConfig() |
||||
|
p.workdir = job_config.get("workdir", self.workdir) |
||||
|
p.repo_uri = get_uri(job_config, self.repo_uri) |
||||
|
p.repo_user = get_user(job_config, self.repo_user) |
||||
|
p.repo_pass = get_pass(job_config, self.repo_pass) |
||||
|
p.packages = set(job_config.get("packages", [])).update(self.packages) |
||||
|
p.upload = job_config.get("upload", self.upload) |
||||
|
return p |
||||
|
|
||||
|
|
||||
class PyPiRunner(): |
class PyPiRunner(): |
||||
def __init__(self, params, user_defaults) -> None: |
def __init__(self, params, config) -> None: |
||||
self.verbose = params["verbose"] |
self.verbose = params["verbose"] |
||||
if self.verbose: |
if self.verbose: |
||||
print("[PyPiRunner] Initializing") |
print("[PyPiRunner] Initializing") |
||||
self.workdir = user_defaults["workdir"] |
self.workdir = config["workdir"] |
||||
# config only contains env and workdir |
self.config = PypiConfig(config) |
||||
self.config = user_defaults |
|
||||
self.default_repo = "https://pypi.python.org/pypi" |
|
||||
|
|
||||
def __versions(self, pkg_name): |
def __versions(self, pkg_name): |
||||
# TODO: Error handling |
# TODO: Error handling |
||||
url = f'{self.default_repo}/{pkg_name}/json' |
url = f'{self.config.repo_uri}/{pkg_name}/json' |
||||
releases = json.loads(request.urlopen(url).read())['releases'] |
releases = json.loads(request.urlopen(url).read())['releases'] |
||||
return sorted(releases, key=parse_version, reverse=True) |
return sorted(releases, key=parse_version, reverse=True) |
||||
|
|
||||
|
def build(self, path): |
||||
|
# TODO: Actual build - silent, unless failure! |
||||
|
pass |
||||
|
|
||||
def update_config(self, config): |
def upload(self, path, repo_uri, repo_pass, repo_user): |
||||
print(config) |
# TODO: Implement |
||||
|
pass |
||||
|
|
||||
def run(self, job_spec): |
def run(self, job_spec): |
||||
print(self.__versions("alice-ci")) |
print(self.__versions("alice-ci")) |
||||
|
job_config = self.config.copy(job_spec) |
||||
|
# TODO: This prints out None !!!!!!!!!!!!! |
||||
|
print(job_config.packages) |
||||
|
return |
||||
|
|
||||
|
PackageManager.getInstance().ensure("build") |
||||
|
for package in job_config.packages: |
||||
|
self.build(path.join(job_config.workdir, package)) |
||||
|
if job_config.upload: |
||||
|
PackageManager.getInstance().ensure("twine") |
||||
|
for package in job_config.packages: |
||||
|
self.build(path.join(job_config.workdir, package), |
||||
|
job_config.repo_uri, |
||||
|
job_config.repo_pass, |
||||
|
job_config.repo_user) |
||||
|
Loading…
Reference in new issue