Exemplo n.º 1
0
def add_install(dependency):
    """Add a dependency to install_requires.  This will add an entry to the
    install_requires list.  It will not abide by any formatting standards, it
    simply adds a new item at the end.

    Usage: psh add-install setup.py mynewdependency

    If a specific version is required, use the same syntax as with pip, e.g.

    psh add-install setup.py foo>=0.4.5

    If the dependency exists in any form, no update is made.

    :param filename: The filename to update, if -n not specified.

    :param dependency: The dependency to add.
    """
    setupfile, encoding = _common.load_file(config.filename)
    try:
        tree = _common.parse_string(setupfile, python_grammar)
    except ParseError as pe:
        print(pe.context)
    else:
        try:
            _mutators.add_arg_to_install(tree, dependency)
        except _mutators.AlreadyExistsError as e:
            print("{}, not modifying".format(str(e)))
        else:
            write_output(tree, config.filename, encoding)
Exemplo n.º 2
0
def test_add_install_exists():
    """Arguments can be added to an existing list of > 1"""
    tree = _common.parse_string(IR_PRE, python_grammar)
    with pytest.raises(_mutators.AlreadyExistsError):
        _mutators.add_arg_to_install(tree, "buzz==0.3.4")
    assert IR_PRE == str(tree)
Exemplo n.º 3
0
def test_add_install_to_many():
    """Arguments can be added to an existing list of > 1"""
    tree = _common.parse_string(IR_PRE, python_grammar)
    _mutators.add_arg_to_install(tree, "foo")
    assert IR_POST == str(tree)
Exemplo n.º 4
0
def test_add_install_one_exists():
    """Arguments are successfully added to an install_requires list of one"""
    tree = _common.parse_string(ONE_IR_PRE, python_grammar)
    _mutators.add_arg_to_install(tree, "barg==0.7.8")
    assert ONE_IR_POST == str(tree), print(str(tree))
Exemplo n.º 5
0
def test_add_to_empty():
    """Adding to and empty install requires inserts an entry"""
    tree = _common.parse_string(EMPTY_IR_PRE, python_grammar)
    _mutators.add_arg_to_install(tree, "rugz")
    assert str(tree) == EMPTY_IR_POST
Exemplo n.º 6
0
def test_add_install_nothing():
    """If no install requires argument exists, one is added."""
    tree = _common.parse_string(NO_IR_PRE, python_grammar)
    _mutators.add_arg_to_install(tree, "baz")
    assert str(tree) == NO_IR_POST