示例#1
0
文件: test.py 项目: agiledata/pkglib
    def get_test_roots(self):
        """ Find test directories, skipping nested dirs and anything marked
            to skip under [pytest]:norecursedirs
        """
        res = []
        no_recurse = []
        cfg = parse.get_pkg_cfg_parser()
        if cfg.has_section('pytest') and \
           cfg.has_option('pytest', 'norecursedirs'):
            [no_recurse.extend(glob.glob(os.path.join(os.getcwd(), i)))
             for i in cfg.get('pytest', 'norecursedirs').split()]
            no_recurse = [os.path.abspath(i) for i in no_recurse]

        test_dirs = []
        for (dirpath, dirnames, _) in os.walk(os.getcwd()):
            if CONFIG.test_dirname in dirnames:
                test_dirs.append(os.path.join(dirpath, CONFIG.test_dirname))
        test_dirs.sort(key=len)
        for i in test_dirs:
            try:
                for j in res + no_recurse:
                    if i.startswith(j):
                        raise ValueError
            except ValueError:
                pass
            else:
                res.append(i)
        log.debug("Test roots: {0}".format(res))
        return res
示例#2
0
    def get_test_roots(self):
        """ Find test directories, skipping nested dirs and anything marked
            to skip under [pytest]:norecursedirs
        """
        res = []
        no_recurse = []
        cfg = parse.get_pkg_cfg_parser()
        if cfg.has_section('pytest') and \
           cfg.has_option('pytest', 'norecursedirs'):
            [
                no_recurse.extend(glob.glob(os.path.join(os.getcwd(), i)))
                for i in cfg.get('pytest', 'norecursedirs').split()
            ]
            no_recurse = [os.path.abspath(i) for i in no_recurse]

        test_dirs = []
        for (dirpath, dirnames, _) in os.walk(os.getcwd()):
            if CONFIG.test_dirname in dirnames:
                test_dirs.append(os.path.join(dirpath, CONFIG.test_dirname))
        test_dirs.sort(key=len)
        for i in test_dirs:
            try:
                for j in res + no_recurse:
                    if i.startswith(j):
                        raise ValueError
            except ValueError:
                pass
            else:
                res.append(i)
        log.debug("Test roots: {0}".format(res))
        return res
示例#3
0
文件: test_egg.py 项目: manahl/pkglib
 def create_pytest_config(self, filename):
     """
     Extracts the pytest specific sections from setup.cfg and puts them
     into a separate config file in the build dir
     """
     parser = parse.get_pkg_cfg_parser()
     [parser.remove_section(s) for s in parser.sections() if s != "pytest"]
     if parser.has_section("pytest"):
         with open(filename, "wt") as f:
             parser.write(f)
示例#4
0
 def create_pytest_config(self, filename):
     """
     Extracts the pytest specific sections from setup.cfg and puts them
     into a separate config file in the build dir
     """
     parser = parse.get_pkg_cfg_parser()
     [parser.remove_section(s) for s in parser.sections() if s != 'pytest']
     if parser.has_section('pytest'):
         with open(filename, 'wt') as f:
             parser.write(f)
示例#5
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])
示例#6
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])
示例#7
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)
示例#8
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)