Ejemplo n.º 1
0
 def test_dir_meta(self):
     test_meta = {'test': 'meta'}
     pkg = Package()
     pkg.set('asdf/jkl', LOCAL_MANIFEST)
     pkg.set('asdf/qwer', LOCAL_MANIFEST)
     pkg.set('qwer/asdf', LOCAL_MANIFEST)
     pkg.set('qwer/as/df', LOCAL_MANIFEST)
     pkg.build('Quilt/Test')
     assert pkg['asdf'].meta == {}
     assert pkg.meta == {}
     assert pkg['qwer']['as'].meta == {}
     pkg['asdf'].set_meta(test_meta)
     assert pkg['asdf'].meta == test_meta
     pkg['qwer']['as'].set_meta(test_meta)
     assert pkg['qwer']['as'].meta == test_meta
     pkg.set_meta(test_meta)
     assert pkg.meta == test_meta
     dump_path = 'test_meta'
     with open(dump_path, 'w') as f:
         pkg.dump(f)
     with open(dump_path) as f:
         pkg2 = Package.load(f)
     assert pkg2['asdf'].meta == test_meta
     assert pkg2['qwer']['as'].meta == test_meta
     assert pkg2.meta == test_meta
Ejemplo n.º 2
0
def upload_test_resources(args: Args):
    # Try running the download pipeline
    try:
        # Get test resources dir
        resources_dir = (Path(__file__).parent.parent / "aicsimageio" /
                         "tests" / "resources").resolve(strict=True)

        # Report with directory will be used for upload
        log.info(f"Using contents of directory: {resources_dir}")

        # Create quilt package
        package = Package()
        package.set_dir("resources", resources_dir)

        # Report package contents
        log.info(f"Package contents: {package}")

        # Construct package name
        package_name = "aicsimageio/test_resources"

        # Check for dry run
        if args.dry_run:
            # Attempt to build the package
            built = package.build(package_name)

            # Get resolved save path
            manifest_save_path = Path("upload_manifest.jsonl").resolve()
            with open(manifest_save_path, "w") as manifest_write:
                package.dump(manifest_write)

            # Report where manifest was saved
            log.info(
                f"Dry run generated manifest stored to: {manifest_save_path}")
            log.info(
                f"Completed package dry run. Result hash: {built.top_hash}")

        # Upload
        else:
            # Check pre-approved push
            if args.preapproved:
                confirmation = True
            else:
                # Get upload confirmation
                confirmation = None
                while confirmation is None:
                    # Get user input
                    user_input = input("Upload [y]/n? ")

                    # If the user simply pressed enter assume yes
                    if len(user_input) == 0:
                        user_input = "y"
                    # Get first character and lowercase
                    else:
                        user_input = user_input[0].lower()

                        # Set confirmation from None to a value
                        if user_input == "y":
                            confirmation = True
                        elif user_input == "n":
                            confirmation = False

            # Check confirmation
            if confirmation:
                pushed = package.push(
                    package_name,
                    "s3://aics-modeling-packages-test-resources",
                    message=
                    f"Test resources for `aicsimageio` version: {__version__}.",
                )

                log.info(
                    f"Completed package push. Result hash: {pushed.top_hash}")
            else:
                log.info(f"Upload canceled.")

    # Catch any exception
    except Exception as e:
        log.error("=============================================")
        if args.debug:
            log.error("\n\n" + traceback.format_exc())
            log.error("=============================================")
        log.error("\n\n" + str(e) + "\n")
        log.error("=============================================")
        sys.exit(1)