Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init():
"""Create a new config file for the project."""
success = False
config = load_config()
if config:
msg = "Configuration file already exists: {}".format(config.path)
common.show(msg, color='error')
else:
config = Config()
source = Source(
type='git',
name="sample_dependency",
repo="https://github.com/githubtraining/hellogitworld",
)
config.sources.append(source)
source = source.lock(rev="ebbbf773431ba07510251bb03f9525c7bab2b13a")
config.sources_locked.append(source)
config.datafile.save()
def edit(*, root=None):
"""Open the confuration file for a project.
Optional arguments:
- `root`: specifies the path to the root working tree
"""
log.info("Launching config...")
config = load_config(root)
if not config:
log.error("No config found")
return False
return system.launch(config.path)
script errors can be ignored
- `force_interactive`: indicates uncommitted changes can be interactively
overwritten and script errors can be ignored
- `fetch`: indicates the latest branches should always be fetched
- `clean`: indicates untracked files should be deleted from dependencies
- `skip_changes`: indicates dependencies with uncommitted changes
should be skipped
"""
log.info(
"%sInstalling dependencies: %s",
'force-' if force or force_interactive else '',
', '.join(names) if names else '',
)
count = None
config = load_config(root)
if config:
common.newline()
common.show("Installing dependencies...", color='message', log=False)
common.newline()
count = config.install_dependencies(
*names,
update=False,
depth=depth,
force=force,
force_interactive=force_interactive,
fetch=fetch,
clean=clean,
skip_changes=skip_changes,
)
def delete(*, root=None, force=False, keep_location=False):
"""Delete dependencies for a project.
Optional arguments:
- `root`: specifies the path to the root working tree
- `force`: indicates uncommitted changes can be overwritten
- `keep_location`: delete top level folder or keep the location
"""
log.info("Deleting dependencies...")
count = None
config = load_config(root)
if config:
common.newline()
common.show("Checking for uncommitted changes...", color='message', log=False)
common.newline()
count = len(list(config.get_dependencies(allow_dirty=force)))
common.dedent(level=0)
common.show("Deleting all dependencies...", color='message', log=False)
common.newline()
if keep_location:
config.clean_dependencies()
else:
config.uninstall_dependencies()
return _display_result("delete", "Deleted", count, allow_zero=True)
def show(*names, root=None):
"""Display the path of an installed dependency or internal file.
- `name`: dependency name or internal file keyword
- `root`: specifies the path to the root working tree
"""
log.info("Finding paths...")
config = load_config(root)
if not config:
log.error("No config found")
return False
for name in names or [None]:
common.show(config.get_path(name), color='path')
return True
def lock(*names, root=None):
"""Lock current dependency versions for a project.
Optional arguments:
- `*names`: optional list of dependency directory names to filter on
- `root`: specifies the path to the root working tree
"""
log.info("Locking dependencies...")
count = None
config = load_config(root)
if config:
common.newline()
common.show("Locking dependencies...", color='message', log=False)
common.newline()
count = config.lock_dependencies(*names, obey_existing=False)
common.dedent(level=0)
return _display_result("lock", "Locked", count)
def display(*, root=None, depth=None, allow_dirty=True):
"""Display installed dependencies for a project.
Optional arguments:
- `root`: specifies the path to the root working tree
- `depth`: number of levels of dependencies to traverse
- `allow_dirty`: causes uncommitted changes to be ignored
"""
log.info("Displaying dependencies...")
count = None
config = load_config(root)
if config:
common.newline()
common.show(
"Displaying current dependency versions...", color='message', log=False
)
common.newline()
config.log(datetime.datetime.now().strftime("%F %T"))
count = 0
for identity in config.get_dependencies(depth=depth, allow_dirty=allow_dirty):
count += 1
config.log("{}: {} @ {}", *identity)
config.log()
return _display_result("display", "Displayed", count)
- `force_interactive`: indicates uncommitted changes can be interactively
overwritten and script errors can be ignored
- `clean`: indicates untracked files should be deleted from dependencies
- `lock`: indicates updated dependency versions should be recorded
- `skip_changes`: indicates dependencies with uncommitted changes
should be skipped
"""
log.info(
"%s dependencies%s: %s",
'Force updating' if force or force_interactive else 'Updating',
', recursively' if recurse else '',
', '.join(names) if names else '',
)
count = None
config = load_config(root)
if config:
common.newline()
common.show("Updating dependencies...", color='message', log=False)
common.newline()
count = config.install_dependencies(
*names,
update=True,
depth=depth,
recurse=recurse,
force=force,
force_interactive=force_interactive,
fetch=True,
clean=clean,
skip_changes=skip_changes,
)