remapping handling pushed to pype publish command

This commit is contained in:
Ondrej Samohel 2020-01-15 15:30:00 +01:00
parent 1a6462d358
commit 408c220df8
No known key found for this signature in database
GPG key ID: 8A29C663C672C2B7

View file

@ -26,7 +26,6 @@ error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}"
def __main__():
parser = argparse.ArgumentParser()
parser.add_argument("--paths",
nargs="*",
@ -46,27 +45,11 @@ def __main__():
print("Running pype ...")
auto_pype_root = os.path.dirname(os.path.abspath(__file__))
auto_pype_root = os.path.abspath(auto_pype_root + "../../../../..")
# we need to use `auto_pype_root` to be able to remap locations.
# This is egg and chicken case: we need to know our storage locations
# to be able to remap them on different platforms but if we got `PYPE_ROOT`
# variable, we cannot be sure it originated on different platform and is
# therefor invalid.
# So we use auto_pype_root to get to `PypeLauncher.path_remapper()`. This
# will load Storage environments and is able to remap environment to
# correct paths.
sys.path.append(auto_pype_root)
try:
from pypeapp import PypeLauncher
except ImportError:
print("!!! Error: cannot determine Pype location.")
print("--- we are looking at {}, but this is not Pype.".format(
auto_pype_root))
remapped_env = PypeLauncher.path_remapper()
auto_pype_root = remapped_env.get('PYPE_ROOT') or auto_pype_root
if remapped_env.get('PYPE_ROOT'):
auto_pype_root = os.environ.get('PYPE_ROOT') or auto_pype_root
if os.environ.get('PYPE_ROOT'):
print("Got Pype location from environment: {}".format(
remapped_env.get('PYPE_ROOT')))
os.environ.get('PYPE_ROOT')))
pype_command = "pype.ps1"
if platform.system().lower() == "linux":
@ -92,7 +75,7 @@ def __main__():
print("Set pype root to: {}".format(pype_root))
print("Paths: {}".format(kwargs.paths or [os.getcwd()]))
paths = kwargs.paths or [os.getcwd()]
paths = kwargs.paths or [os.environ.get("PYPE_METADATA_FILE")] or [os.getcwd()] # noqa
args = [
os.path.join(pype_root, pype_command),
@ -104,7 +87,7 @@ def __main__():
# Forcing forwaring the environment because environment inheritance does
# not always work.
# Cast all values in environment to str to be safe
env = {k: str(v) for k, v in remapped_env.items()}
env = {k: str(v) for k, v in os.environ.items()}
exit_code = subprocess.call(args, env=env)
if exit_code != 0:
raise RuntimeError("Publishing failed.")