How to use the flit.inifile.ConfigError function in flit

To help you get started, we’ve selected a few flit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github takluyver / flit / flit / __init__.py View on Github external
elif args.subcmd == 'publish':
        if args.deprecated_repository:
            log.warning("Passing --repository before the 'upload' subcommand is deprecated: pass it after")
        repository = args.repository or args.deprecated_repository
        from .upload import main
        main(args.ini_file, repository, formats=set(args.format or []),
                gen_setup_py=args.setup_py)

    elif args.subcmd == 'install':
        from .install import Installer
        try:
            python = find_python_executable(args.python)
            Installer.from_ini_path(args.ini_file, user=args.user, python=python,
                      symlink=args.symlink, deps=args.deps, extras=args.extras,
                      pth=args.pth_file).install()
        except (ConfigError, PythonNotFoundError, common.NoDocstringError, common.NoVersionError) as e:
            sys.exit(e.args[0])

    elif args.subcmd == 'init':
        from .init import TerminalIniter
        TerminalIniter().initialise()
    else:
        ap.print_help()
        sys.exit(1)
github takluyver / flit / flit / inifile.py View on Github external
def _verify_classifiers_cached(classifiers):
    with (get_cache_dir() / 'classifiers.lst').open() as f:
        valid_classifiers = set(l.strip() for l in f)

    invalid = classifiers - valid_classifiers
    if invalid:
        raise ConfigError("Invalid classifiers:\n" +
                          "\n".join(invalid))
github takluyver / flit / flit / inifile.py View on Github external
def verify_classifiers(classifiers):
    classifiers = set(classifiers)
    try:
        _verify_classifiers_cached(classifiers)
    except (FileNotFoundError, ConfigError) as e1:
        # FileNotFoundError: We haven't yet got the classifiers cached
        # ConfigError: At least one is invalid, but it may have been added since
        #   last time we fetched them.
        try:
            _download_classifiers()
        except requests.ConnectionError:
            # The error you get on a train, going through Oregon, without wifi
            if isinstance(e1, ConfigError):
                raise e1
            else:
                log.warn("Couldn't get list of valid classifiers to check against")
        else:
            _verify_classifiers_cached(classifiers)
github takluyver / flit / flit / inifile.py View on Github external
def _validate_config(cp, path):
    """
    Validate a config and return a dict containing `module`,`metadata`,`script`,`entry_point` keys.
    """
    unknown_sections = set(cp.sections()) - {'metadata', 'scripts'}
    if unknown_sections:
        log.info('Extra config sections: ' + ', '.join(unknown_sections))

    if not cp.has_section('metadata'):
        raise ConfigError('[metadata] section is required')

    md_sect = cp['metadata']
    if not set(md_sect).issuperset(metadata_required_fields):
        missing = metadata_required_fields - set(md_sect)
        raise ConfigError("Required fields missing: " + '\n'.join(missing))

    module = md_sect.get('module')
    if not module.isidentifier():
        raise ConfigError("Module name %r is not a valid identifier" % module)

    md_dict = {}

    if 'description-file' in md_sect:
        description_file = path.parent / md_sect.get('description-file')
        with description_file.open() as f:
            raw_desc =  f.read()
        if description_file.suffix == '.md':
            try:
                import pypandoc
                log.debug('will convert %s to rst', description_file)
                raw_desc = pypandoc.convert(raw_desc, 'rst', format='markdown')
github takluyver / flit / flit / inifile.py View on Github external
raise FileNotFoundError(entry_points_file)
    else:
        entry_points_file = path.parent / 'entry_points.txt'
        if not entry_points_file.is_file():
            entry_points_file = None

    for key, value in md_sect.items():
        if key in {'description-file', 'module', 'entry-points-file'}:
            continue
        if key not in metadata_allowed_fields:
            closest = difflib.get_close_matches(key, metadata_allowed_fields,
                                                n=1, cutoff=0.7)
            msg = "Unrecognised metadata key: {}".format(key)
            if closest:
                msg += " (did you mean {!r}?)".format(closest[0])
            raise ConfigError(msg)

        k2 = key.replace('-', '_')
        if key in metadata_list_fields:
            md_dict[k2] = value.splitlines()
        else:
            md_dict[k2] = value

    # What we call requires in the ini file is technically requires_dist in
    # the metadata.
    if 'requires' in md_dict:
        md_dict['requires_dist'] = md_dict.pop('requires')

    # And what we call dist-name is name in the metadata
    if 'dist_name' in md_dict:
        md_dict['name'] = md_dict.pop('dist_name')
github takluyver / flit / flit / inifile.py View on Github external
def _validate_config(cp, path):
    """
    Validate a config and return a dict containing `module`,`metadata`,`script`,`entry_point` keys.
    """
    unknown_sections = set(cp.sections()) - {'metadata', 'scripts'}
    if unknown_sections:
        log.info('Extra config sections: ' + ', '.join(unknown_sections))

    if not cp.has_section('metadata'):
        raise ConfigError('[metadata] section is required')

    md_sect = cp['metadata']
    if not set(md_sect).issuperset(metadata_required_fields):
        missing = metadata_required_fields - set(md_sect)
        raise ConfigError("Required fields missing: " + '\n'.join(missing))

    module = md_sect.get('module')
    if not module.isidentifier():
        raise ConfigError("Module name %r is not a valid identifier" % module)

    md_dict = {}

    if 'description-file' in md_sect:
        description_file = path.parent / md_sect.get('description-file')
        with description_file.open() as f:
            raw_desc =  f.read()