Skip to content

Commit

Permalink
black formatting and flake8/pylint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
craigcomstock committed Oct 20, 2021
1 parent ad8c8b1 commit fda2f01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
import os
import re
from collections import OrderedDict

from cfbs.utils import (
cfbs_dir,
Expand Down Expand Up @@ -37,6 +36,7 @@ def clear_definition():
global definition
definition = None


def get_definition() -> dict:
global definition
if not definition:
Expand Down Expand Up @@ -208,9 +208,10 @@ def local_module_copy(module, counter, max_length):
f"{counter:03d} {pad_right(name, max_length)} @ local (Copied)"
)


def _get_path_from_url(url):
if not url.startswith(("https://", "ssh://", "git://")):
if ("://" in url):
if "://" in url:
return user_error("Unsupported URL protocol in '%s'" % url)
else:
# It's a path already, just remove trailing slashes (if any).
Expand All @@ -221,12 +222,13 @@ def _get_path_from_url(url):
match = re.match(r"ssh://(\w+)@(.+)", url)
if match is not None:
path = match[2]
path = path or url[url.index("://") + 3:]
path = path or url[url.index("://") + 3 :]
path = strip_right(path, ".git")
path = path.strip("/")

return path


def _get_git_repo_commit_sha(repo_path):
assert os.path.isdir(os.path.join(repo_path, ".git"))

Expand All @@ -239,6 +241,7 @@ def _get_git_repo_commit_sha(repo_path):
with open(os.path.join(repo_path, ".git", head_ref)) as f:
return f.read().strip()


def _clone_index_repo(repo_url):
assert repo_url.startswith(("https://", "ssh://", "git://"))

Expand Down Expand Up @@ -273,7 +276,10 @@ def _clone_index_repo(repo_url):
if os.path.exists(index_path):
return (index_path, commit)
else:
user_error("Repository '%s' doesn't contain a valid cfbs.json index file" % repo_url)
user_error(
"Repository '%s' doesn't contain a valid cfbs.json index file" % repo_url
)


def add_command(to_add: list, added_by="cfbs add", index_path=None) -> int:
if not to_add:
Expand All @@ -294,7 +300,10 @@ def add_command(to_add: list, added_by="cfbs add", index_path=None) -> int:
# URL specified in to_add, but no specific modules => let's add all (with a prompt)
if len(to_add) == 0:
modules = index.get_modules()
answer = input("Do you want to add all %d modules from the repository? [y/N] " % len(modules))
answer = input(
"Do you want to add all %d modules from the repository? [y/N] "
% len(modules)
)
if answer.lower() not in ("y", "yes"):
return 0
to_add = modules.keys()
Expand Down
7 changes: 4 additions & 3 deletions cfbs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sh,
)

from cfbs.pretty import pretty_file, pretty


def _local_module_data_cf_file(module):
target = os.path.basename(module)
Expand All @@ -44,8 +44,8 @@ def _local_module_data_json_file(module):


def _local_module_data_subdir(module):
assert(module[0:2] == './')
dst = os.path.join("services","cfbs",module[2:])
assert module[0:2] == "./"
dst = os.path.join("services", "cfbs", module[2:])
return {
"description": "Local subdirectory added using cfbs command line",
"tags": ["local"],
Expand All @@ -66,6 +66,7 @@ def generate_index_for_local_module(module):
if module.endswith(".json"):
return _local_module_data_json_file(module)


class Index:
def __init__(self, path):
self.path = path
Expand Down

0 comments on commit fda2f01

Please sign in to comment.