Skip to content

Commit

Permalink
Mainly path updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-O committed Sep 1, 2023
1 parent 8756cd2 commit de697f0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 58 deletions.
54 changes: 28 additions & 26 deletions buildozer/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run(args):
elif arg in ("-p", "--profile"):
profile = args.pop(0)

config = _load_spec()
config = _load_spec(profile)

if not log_level_set_by_command_line:
_set_log_level_from_config(config)
Expand All @@ -97,7 +97,7 @@ def run(args):

# Generic commands don't need a target.
if command in GENERIC_COMMANDS:
action = GENERIC_COMMANDS[command][2]
action = GENERIC_COMMANDS[command][1]
action(config, paths, args)
return

Expand All @@ -111,15 +111,15 @@ def run(args):
# We have a target.

if not args:
logger.error('Missing target command')
logger.error("Missing target command")
_usage()
exit(1)

_run_target_command(
config=config,
paths=paths,
target_cls=available_targets[command],
args=args[1:],
args=args,
)


Expand Down Expand Up @@ -148,7 +148,10 @@ def _run_target_command(config, paths, target_cls, args):
# on the line should be passed to the command (even if they don't start
# with "--")

valid_command_names = set(target_cls.get_custom_commands() + GENERIC_COMMANDS)
valid_command_names = (
set(command[0] for command in target_cls.get_custom_commands())
| GENERIC_COMMANDS.keys()
)

# Commands that have been parsed.
complete_commands = []
Expand All @@ -158,20 +161,20 @@ def _run_target_command(config, paths, target_cls, args):

while args:
arg = args.pop(0)
if arg == '--':
if arg == "--":
if partial_command:
# Rest of arguments are part of the current command.
partial_command += args
break
else:
logger.error('-- arguments passed without a command')
logger.error("-- arguments passed without a command")
_usage()
exit(1)

if not arg.startswith('--'):
if not arg.startswith("--"):
# New command starting.
if arg.lower() not in valid_command_names:
logger.error('Unrecognised command: {}'.format(arg))
logger.error("Unrecognised command: {}".format(arg))
_usage()
exit(1)

Expand All @@ -183,15 +186,15 @@ def _run_target_command(config, paths, target_cls, args):
partial_command.append(arg.lower())
else:
if not partial_command:
logger.error('Argument passed without a command')
logger.error("Argument passed without a command")
_usage()
exit(1)
partial_command.append(arg)
if partial_command:
complete_commands.append(partial_command)

if not complete_commands:
logger.error('No command for target provided')
logger.error("No command for target provided")
_usage()
exit(1)

Expand Down Expand Up @@ -327,18 +330,18 @@ def _targets():
return result


def _usage():
def _usage(*_):
print("Usage:")
print(" buildozer [--profile <name>] [--verbose] <global command>...")
print(" buildozer [--profile <name>] [--verbose] <global command> [opts]")
print(
" buildozer [--profile <name>] [--verbose] [target] <target command>..."
" buildozer [--profile <name>] [--verbose] <target> <target command> [opts]"
)
print(" buildozer --version")
print("")

print("Global commands:")
for name in sorted(GENERIC_COMMANDS.keys()):
print(" {0:<18} {1}".format(name, GENERIC_COMMANDS[name][0]))
print(" {0:<14} {1}".format(name, GENERIC_COMMANDS[name][0]))
print("")

print("Available targets:")
Expand All @@ -355,19 +358,18 @@ def _usage():
doc = "<no description>"
except Exception as e:
doc = "<no description>" + str(e)
print(" {0:<18} {1}".format(target_name, doc))
print("")
print(" {0:<14} {1}".format(target_name, doc))

if available_targets:
print("")
print("Target commands:")
print(" clean Clean the target environment")
print(" update Update the target dependencies")
print(" debug Build the application in debug mode")
print(" release Build the application in release mode")
print(" deploy Deploy the application on the device")
print(" run Run the application on the device")
print(" serve Serve the bin directory via SimpleHTTPServer")
print(" clean Clean the target environment")
print(" update Update the target dependencies")
print(" debug Build the application in debug mode")
print(" release Build the application in release mode")
print(" deploy Deploy the application on the device")
print(" run Run the application on the device")
print(" serve Serve the bin directory via SimpleHTTPServer")

for target_name, target_cls in available_targets:
commands = target_cls.get_custom_commands()
Expand All @@ -379,9 +381,9 @@ def _usage():
if not doc:
continue
doc = textwrap.fill(
textwrap.dedent(doc).strip(), 59, subsequent_indent=" " * 21
textwrap.dedent(doc).strip(), 59, subsequent_indent=" " * 17
)
print(" {0:<18} {1}".format(command, doc))
print(" {0:<14} {1}".format(command, doc))

print("")

Expand Down
2 changes: 1 addition & 1 deletion buildozer/pathatlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ def __init__(self, generic_paths, target_name):
)

self.global_packages_path = (
generic_paths.global_platform_path / target_name / "packages"
self.global_platform_path / target_name / "packages"
)
13 changes: 9 additions & 4 deletions buildozer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import buildozer.buildops as buildops
from buildozer.logger import Logger
from buildozer.buildsupport import TargetedBuildSupporter


def no_config(f):
Expand All @@ -17,13 +18,17 @@ class Target:
standard_cmds = ('distclean', 'update', 'debug', 'release',
'deploy', 'run', 'serve')

def __init__(self, buildsupporter):
def __init__(self, buildsupporter: TargetedBuildSupporter):
self.buildsupporter = buildsupporter
self.build_mode = 'debug'
self.artifact_format = 'apk'
self.platform_update = False
self.logger = Logger()

self.generic_paths = buildsupporter.paths
self.target_paths = buildsupporter.target_paths


def check_requirements(self):
pass

Expand Down Expand Up @@ -199,7 +204,7 @@ def path_or_git_url(self, repo, owner='kivy', branch='master',
path = config.getdefault('app', '{}_dir'.format(key), None)

if path is not None:
path = join(self.buildsupporter.root_dir, path)
path = join(self.generic_paths.root_dir, path)
url = None
branch = None
else:
Expand All @@ -223,7 +228,7 @@ def install_or_update_repo(self, repo, **kwargs):
:Returns:
fully qualified path to updated git repo
"""
install_dir = join(self.buildsupporter.platform_dir, repo)
install_dir = join(self.target_paths.platform_dir, repo)
custom_dir, clone_url, clone_branch = self.path_or_git_url(repo, **kwargs)
if not buildops.file_exists(install_dir):
if custom_dir:
Expand All @@ -232,7 +237,7 @@ def install_or_update_repo(self, repo, **kwargs):
else:
buildops.cmd(
["git", "clone", "--branch", clone_branch, clone_url],
cwd=self.buildsupporter.platform_dir,
cwd=self.target_paths.platform_dir,
env=self.buildsupporter.environ)
elif self.platform_update:
if custom_dir:
Expand Down
Loading

0 comments on commit de697f0

Please sign in to comment.