diff --git a/locallibs/__init__.py b/locallibs/__init__.py index e69de29..473ff8b 100644 --- a/locallibs/__init__.py +++ b/locallibs/__init__.py @@ -0,0 +1,44 @@ +# encoding: utf-8 +# +# Copyright 2018 Greg Neagle. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Misc Helper Functions""" + +def vararg_callback(option, opt_str, value, parser): + """Optparse callback to support a variable number of arguments. + This is example 6 from the official docs: + https://docs.python.org/3/library/optparse.html#callback-example-6-variable-arguments + """ + + assert value is None + value = [] + + def floatable(str): + try: + float(str) + return True + except ValueError: + return False + + for arg in parser.rargs: + # stop on --foo like options + if arg[:2] == "--" and len(arg) > 2: + break + # stop on -a, but not on -3 or -3.0 + if arg[:1] == "-" and len(arg) > 1 and not floatable(arg): + break + value.append(arg) + + del parser.rargs[:len(value)] + setattr(parser.values, option.dest, value) diff --git a/locallibs/install.py b/locallibs/install.py index e381db1..2bfc475 100644 --- a/locallibs/install.py +++ b/locallibs/install.py @@ -17,6 +17,7 @@ from __future__ import print_function +import itertools import os import subprocess import sys @@ -61,18 +62,53 @@ def upgrade_pip_install(framework_path, version): subprocess.check_call(cmd) -def install_requirements(requirements_file, framework_path, version): +def install_requirements( + requirements_file, framework_path, version, pip_platform, no_binary, only_binary): """Use pip to install a Python pkg into framework_path""" + + def multi_value_option(option, values, separator=None): + """Helper function supply the same option with multiple value + + Args: + option (str): the option name (e.g. --