Example #1
0
def test_rejects_illegal_characters_in_package_name():
    setup_cfg = """
[metadata]
name = test_4
"""
    with pytest.raises(RuntimeError) as exc:
        parse.parse_pkg_metadata(parse_cfg(setup_cfg), strict=True)
    assert str(exc.value) == ("Package name 'test_4' contains illegal "
                              "character(s); consider changing to 'test-4'")
Example #2
0
def test_rejects_illegal_characters_in_package_name():
    setup_cfg = """
[metadata]
name = test_4
"""
    with pytest.raises(RuntimeError) as exc:
        parse.parse_pkg_metadata(parse_cfg(setup_cfg), strict=True)
    assert str(exc.value) == ("Package name 'test_4' contains illegal "
                              "character(s); consider changing to 'test-4'")
Example #3
0
def test_rejects_illegal_characters_in_requires():
    setup_cfg = """
[metadata]
name = test4
install_requires =
    foo_bar
"""
    with pytest.raises(RuntimeError) as exc:
        parse.parse_pkg_metadata(parse_cfg(setup_cfg), strict=True)
    assert str(exc.value) == ("Invalid name 'foo_bar' in requirement 'foo_bar' "
                              "for 'install_requires' of 'test4'; "
                              "consider changing to 'foo-bar'")
Example #4
0
def test_rejects_illegal_characters_in_requires():
    setup_cfg = """
[metadata]
name = test4
install_requires =
    foo_bar
"""
    with pytest.raises(RuntimeError) as exc:
        parse.parse_pkg_metadata(parse_cfg(setup_cfg), strict=True)
    assert str(
        exc.value) == ("Invalid name 'foo_bar' in requirement 'foo_bar' "
                       "for 'install_requires' of 'test4'; "
                       "consider changing to 'foo-bar'")
Example #5
0
def test_parse_setup_cfg_install_requires():
    setup_cfg = """
[metadata]
name = test1
install_requires =
    foo
    bla ==  1.2,   <3
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata['name'] == "test1"
    assert metadata['extras_require'] == {}
    assert metadata['install_requires'] == ["foo", "bla ==  1.2,   <3"]
Example #6
0
def test_parse_setup_cfg_install_requires():
    setup_cfg = """
[metadata]
name = test1
install_requires =
    foo
    bla ==  1.2,   <3
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata['name'] == "test1"
    assert metadata['extras_require'] == {}
    assert metadata['install_requires'] == ["foo", "bla ==  1.2,   <3"]
Example #7
0
def test_parse_setup_cfg_extras_require():
    setup_cfg = """
[metadata]
name = test2
install_requires =
    foo
extras_require =
    Foo : Bla
    Ivan : Kremlin[Mausoleum, Lenin]==1.0, Putin
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata["name"] == "test2"
    expected = {"Foo": ["Bla"],
                "Ivan": ["Kremlin[Mausoleum, Lenin]==1.0", "Putin"]}
    assert metadata["extras_require"] == expected
Example #8
0
def test_parse_setup_cfg_extras_require():
    setup_cfg = """
[metadata]
name = test2
install_requires =
    foo
extras_require =
    Foo : Bla
    Ivan : Kremlin[Mausoleum, Lenin]==1.0, Putin
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata["name"] == "test2"
    expected = {
        "Foo": ["Bla"],
        "Ivan": ["Kremlin[Mausoleum, Lenin]==1.0", "Putin"]
    }
    assert metadata["extras_require"] == expected
Example #9
0
def test_parse_setup_cfg_entry_points():
    setup_cfg = """
[entry_points]
acme.foo =
    bar=baz:qux
console_scripts =
    one=two:three

[metadata]
name = test1
console_scripts =
    alpha=beta:gamma
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata['entry_points'] == {'acme.foo': ['bar=baz:qux'],
                                        'console_scripts': ['one=two:three',
                                                            'alpha=beta:gamma',
                                                            ],
                                        }
Example #10
0
def test_parse_setup_cfg_entry_points():
    setup_cfg = """
[entry_points]
acme.foo =
    bar=baz:qux
console_scripts =
    one=two:three

[metadata]
name = test1
console_scripts =
    alpha=beta:gamma
"""
    metadata = parse.parse_pkg_metadata(parse_cfg(setup_cfg))
    assert metadata['entry_points'] == {
        'acme.foo': ['bar=baz:qux'],
        'console_scripts': [
            'one=two:three',
            'alpha=beta:gamma',
        ],
    }
Example #11
0
def setup():
    """ Mirror pkglib's setup() method for each sub-package in this repository.
    """
    top_level_parser = parse.get_pkg_cfg_parser()
    cfg = parse.parse_section(top_level_parser, 'multipkg', ['pkg_dirs'])
    rc = [0]
    for dirname in cfg['pkg_dirs']:
        with cmdline.chdir(dirname):
            # Update sub-package setup.cfg with top-level version if it's specified
            if 'version' in cfg:
                sub_parser = parse.get_pkg_cfg_parser()
                sub_cfg = parse.parse_pkg_metadata(sub_parser)
                if sub_cfg['version'] != cfg['version']:
                    print ("Updating setup.cfg version for {0}: {1} -> {2}"
                           .format(dirname, sub_cfg['version'], cfg['version']))
                    sub_parser.set('metadata', 'version', cfg['version'])
                    with open('setup.cfg', 'w') as sub_cfg_file:
                        sub_parser.write(sub_cfg_file)

            cmd = [sys.executable, "setup.py"] + sys.argv[1:]
            print ("In directory {0}: Running '{1}'"
                   .format(dirname, ' '.join(cmd)))
            try:
                cmdline.run(cmd, capture_stdout=False, bufsize=0)
            except subprocess.CalledProcessError as e:
                # Here we exit straight away, unless this was a run as
                # 'python setup.py test'. Reason for this is that we want to
                # run all the packages' tests through and gather the results.
                # Exception: using the -x/--exitfirst option.
                # For any other setup.py command, a failure here is likely
                # some sort of build or config issue and it's best not to
                # plow on.
                print "Command failed with exit code {0}".format(e.returncode)
                if 'test' in cmd and not '-x' in ' '.join(cmd)  \
                                 and not '--exitfirst' in ' '.join(cmd):
                    rc[0] = e.returncode
                else:
                    sys.exit(e.returncode)
    sys.exit(rc[0])
Example #12
0
def setup():
    """ Mirror pkglib's setup() method for each sub-package in this repository.
    """
    top_level_parser = parse.get_pkg_cfg_parser()
    cfg = parse.parse_section(top_level_parser, 'multipkg', ['pkg_dirs'])
    rc = [0]
    for dirname in cfg['pkg_dirs']:
        with cmdline.chdir(dirname):
            # Update sub-package setup.cfg with top-level version if it's specified
            if 'version' in cfg:
                sub_parser = parse.get_pkg_cfg_parser()
                sub_cfg = parse.parse_pkg_metadata(sub_parser)
                if sub_cfg['version'] != cfg['version']:
                    print("Updating setup.cfg version for {0}: {1} -> {2}".
                          format(dirname, sub_cfg['version'], cfg['version']))
                    sub_parser.set('metadata', 'version', cfg['version'])
                    with open('setup.cfg', 'w') as sub_cfg_file:
                        sub_parser.write(sub_cfg_file)

            cmd = [sys.executable, "setup.py"] + sys.argv[1:]
            print("In directory {0}: Running '{1}'".format(
                dirname, ' '.join(cmd)))
            try:
                cmdline.run(cmd, capture_stdout=False, bufsize=0)
            except subprocess.CalledProcessError as e:
                # Here we exit straight away, unless this was a run as
                # 'python setup.py test'. Reason for this is that we want to
                # run all the packages' tests through and gather the results.
                # Exception: using the -x/--exitfirst option.
                # For any other setup.py command, a failure here is likely
                # some sort of build or config issue and it's best not to
                # plow on.
                print "Command failed with exit code {0}".format(e.returncode)
                if 'test' in cmd and not '-x' in ' '.join(cmd)  \
                                 and not '--exitfirst' in ' '.join(cmd):
                    rc[0] = e.returncode
                else:
                    sys.exit(e.returncode)
    sys.exit(rc[0])
Example #13
0
def setup(**kwargs):
    """
    Call the regular `setuptools.setup` function with data read from
    our setup.cfg file.

    Parameters
    ----------
    kwargs : arguments dictionary
        Override any of the default `setuptools.setup` keyword arguments.

    """
    org.setup_global_org_config()
    check_multiple_call()
    original_cwd = os.getcwd()
    set_working_dir()
    test.gather_trailing_args()
    # Base set of defaults
    call_args = dict(
        distclass=Distribution,
        name='',
        version='',
        description='',
        long_description='',
        keywords='',
        author='',
        author_email='',
        url='',
        setup_requires=[],
        install_requires=[],
        tests_require=[],
        license='Proprietary',
        classifiers=[],
        entry_points={},
        scripts=[],
        ext_modules=[],
        packages=find_packages(exclude=['test*']),
        include_package_data=True,
        zip_safe=True,
        namespace_packages=[],
        original_cwd=original_cwd,
        cmdclass=dict(DEFAULT_CMD_CLASS),
        options=dict(
             aliases=dict(ALIASES),
        ))

    # Get the package metadata from the setup.cfg file
    call_args.update(parse.parse_pkg_metadata(parse.get_pkg_cfg_parser()))

    # Overrides/updates attributes from call arguments.
    # Override for scalar, update for dictionaries.
    for k, v in kwargs.items():
        if type(v) is dict and k in call_args:
            call_args[k].update(v)
        else:
            call_args[k] = v

    check_distclass(call_args["distclass"])

    # Call base setup method, retrieve distribution
    dist = setuptools_setup(**call_args)

    # Check if we've set a failed flag this may be due to a failed upload.
    if hasattr(dist, '_failed') and dist._failed:
        raise SystemExit(1)
Example #14
0
def setup(**kwargs):
    """
    Call the regular `setuptools.setup` function with data read from
    our setup.cfg file.

    Parameters
    ----------
    kwargs : arguments dictionary
        Override any of the default `setuptools.setup` keyword arguments.

    """
    org.setup_global_org_config()
    check_multiple_call()
    original_cwd = os.getcwd()
    set_working_dir()
    test.gather_trailing_args()
    # Base set of defaults
    call_args = dict(distclass=Distribution,
                     name='',
                     version='',
                     description='',
                     long_description='',
                     keywords='',
                     author='',
                     author_email='',
                     url='',
                     setup_requires=[],
                     install_requires=[],
                     tests_require=[],
                     license='Proprietary',
                     classifiers=[],
                     entry_points={},
                     scripts=[],
                     ext_modules=[],
                     packages=find_packages(exclude=['test*']),
                     include_package_data=True,
                     zip_safe=True,
                     namespace_packages=[],
                     original_cwd=original_cwd,
                     cmdclass=dict(DEFAULT_CMD_CLASS),
                     options=dict(aliases=dict(ALIASES), ))

    # Get the package metadata from the setup.cfg file
    call_args.update(parse.parse_pkg_metadata(parse.get_pkg_cfg_parser()))

    # Overrides/updates attributes from call arguments.
    # Override for scalar, update for dictionaries.
    for k, v in kwargs.items():
        if type(v) is dict and k in call_args:
            call_args[k].update(v)
        else:
            call_args[k] = v

    check_distclass(call_args["distclass"])

    # Call base setup method, retrieve distribution
    dist = setuptools_setup(**call_args)

    # Check if we've set a failed flag this may be due to a failed upload.
    if hasattr(dist, '_failed') and dist._failed:
        raise SystemExit(1)