Skip to content

[WIP] Fix crashes when using other commands than 'apk' #1809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ def project_has_setup_py(project_dir):
return False


def run_pymodules_install(ctx, modules, project_dir, ignore_setup_py=False):
def run_pymodules_install(ctx, modules, project_dir=None,
ignore_setup_py=False):
""" This function will take care of all non-recipe things, by:

1. Processing them from --requirements (the modules argument)
Expand All @@ -610,6 +611,7 @@ def run_pymodules_install(ctx, modules, project_dir, ignore_setup_py=False):
# Bail out if no python deps and no setup.py to process:
if not modules and (
ignore_setup_py or
project_dir is None or
not project_has_setup_py(project_dir)
):
info('No Python modules and no setup.py to process, skipping')
Expand All @@ -621,7 +623,8 @@ def run_pymodules_install(ctx, modules, project_dir, ignore_setup_py=False):
'install them with pip'.format(', '.join(modules)))
info('If this fails, it may mean that the module has compiled '
'components and needs a recipe.')
if project_has_setup_py(project_dir) and not ignore_setup_py:
if project_dir is not None and \
project_has_setup_py(project_dir) and not ignore_setup_py:
info('Will process project install, if it fails then the '
'project may not be compatible for Android install.')

Expand Down Expand Up @@ -694,7 +697,9 @@ def run_pymodules_install(ctx, modules, project_dir, ignore_setup_py=False):
_env=copy.copy(env))

# Afterwards, run setup.py if present:
if project_has_setup_py(project_dir) and not ignore_setup_py:
if project_dir is not None and (
project_has_setup_py(project_dir) and not ignore_setup_py
):
with current_directory(project_dir):
info('got setup.py or similar, running project install. ' +
'(disable this behavior with --ignore-setup-py)')
Expand Down
11 changes: 7 additions & 4 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ def build_dist_from_args(ctx, dist, args):
if dist.needs_build:
ctx.prepare_dist(ctx.dist_name)

build_recipes(build_order, python_modules, ctx, args.private,
ignore_project_setup_py=args.ignore_setup_py,
build_recipes(build_order, python_modules, ctx,
getattr(args, "private", None),
ignore_project_setup_py=getattr(
args, "ignore_setup_py", False
),
)

ctx.bootstrap.run_distribute()
Expand Down Expand Up @@ -568,7 +571,7 @@ def add_parser(subparsers, *args, **kwargs):
if hasattr(args, "private") and args.private is not None:
# Pass this value on to the internal bootstrap build.py:
args.unknown_args += ["--private", args.private]
if args.ignore_setup_py:
if hasattr(args, "ignore_setup_py") and args.ignore_setup_py:
args.use_setup_py = False

self.args = args
Expand All @@ -583,7 +586,7 @@ def add_parser(subparsers, *args, **kwargs):
logger.setLevel(logging.DEBUG)

self.ctx = Context()
self.ctx.use_setup_py = args.use_setup_py
self.ctx.use_setup_py = getattr(args, "use_setup_py", True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be neater to move the --use-setup-py etc. arguments to generic_parser so that they're always in the args object, instead of using getattr in different places. It isn't a great api to have to stick non-generic stuff in generic_parser like this, but I think it's a failure of the way the abstraction is set up rather than something specific to this particular argument. There are plenty of other things in generic_parser for the same reason.

Copy link
Author

@ghost ghost Apr 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, I think it shouldn't be in the generic_parser if it's not for the other commands. I'd rather have the special case/getattr handling that is admittedly ugly, but still allows me to understand to which commands the arguments belong, BOTH as a coder and a user. (generated parser help texts would list all options even for other commands, right?) Therefore, moving it into generic_parser seems like a cheap hack to me

However, as usual if you really think that's how it should be I will change it accordingly, so your call 👍


have_setup_py_or_similar = False
if getattr(args, "private", None) is not None:
Expand Down