def export(selected): if args.copy_resources and not args.yes: cli.out( "WARNING: you have specified --copy-resources, which will " "copy resources used by each run!" "" ) if not cli.confirm("Really copy resources exported runs?"): return util.ensure_dir(args.location) util.touch(os.path.join(args.location, ".guild-nocopy")) exported = 0 for run in selected: dest = os.path.join(args.location, run.id) if os.path.exists(dest): log.warning("%s exists, skipping", dest) continue if args.move: cli.out("Moving {}".format(run.id)) if args.copy_resources: shutil.copytree(run.path, dest) shutil.rmtree(run.path) else: shutil.move(run.path, dest) else: cli.out("Copying {}".format(run.id)) symlinks = not args.copy_resources shutil.copytree(run.path, dest, symlinks) exported += 1 cli.out("Exported %i run(s)" % exported)
def init_guild_dir(path, local_resource_cache=False): util.ensure_dir(path) util.touch(os.path.join(path, ".guild-nocopy")) util.ensure_dir(os.path.join(path, "runs")) util.ensure_dir(os.path.join(path, "trash")) util.ensure_dir(os.path.join(path, "cache", "runs")) _init_resource_cache(path, local_resource_cache)
def _init_export_dir(dir): util.ensure_dir(dir) try: util.touch(os.path.join(dir, ".guild-nocopy")) except IOError as e: if e.errno == errno.ENOTDIR: cli.error("'%s' is not a directory" % dir) else: cli.error("error initializing export directory '%s': %s" % (dir, e))
def _init_published_run(state): """Ensure empty target directory for published run. As a side effect, lazily creates `state.dest_home` and creates `.guild-nocopy` to ensure that the published runs home is not considered by Guild for source snapshots. """ util.ensure_dir(state.dest_home) util.touch(os.path.join(state.dest_home, ".guild-nocopy")) if os.path.exists(state.run_dest): util.safe_rmtree(state.run_dest) os.mkdir(state.run_dest)
def post_process(source, cwd, use_cache=True): if not source.post_process: return cmd_in = source.post_process.strip().replace("\n", " ") cmd = _apply_source_script_functions(cmd_in, source) if use_cache: cmd_digest = hashlib.sha1(cmd.encode()).hexdigest() process_marker = os.path.join(cwd, ".guild-cache-{}.post".format(cmd_digest)) if os.path.exists(process_marker): return log.info("Post processing %s resource in %s: %r", source.resdef.name, cwd, cmd) try: subprocess.check_call(cmd, shell=True, cwd=cwd) except subprocess.CalledProcessError as e: raise ResolutionError( "error post processing %s resource: %s" % (source.resdef.name, e) ) else: util.touch(process_marker)
def _install_external(name, dist_spec): with util.TempDir(prefix="pip-", suffix="-download") as tmp: wheel_path = _pip_wheel(name, dist_spec, tmp) _install_external_wheel(wheel_path) util.touch(_external_marker(name))
def _install_external(name, dist_spec): tmp = util.TempDir(prefix="pip-", suffix="-download") wheel_path = _pip_wheel(name, dist_spec, tmp.path) _install_external_wheel(wheel_path) util.touch(_external_marker(name)) tmp.delete()
from os import mkdir from os import symlink from os.path import join as path from guild.util import touch touch("a") touch("b") mkdir("c") touch(path("c", "d.txt")) touch(path("c", "e.txt")) touch(path("c", "f.bin")) symlink("c", "l") touch(path(".guild", "attrs", "exit_status")) touch(path(".guild", "some-guild-file"))