Exemple #1
0
def prepare_ci_env(c):
    """
    Prepare CI environment
    """
    title("Creating virtual env", "=")
    c.run("python -m venv --clear dist_venv")
    activate_venv(c, "dist_venv")

    c.run("dist_venv/bin/python -m pip install -U setuptools wheel pip")

    title("Building wheel", "=")
    c.run("dist_venv/bin/python setup.py build bdist_wheel")

    title("Installing wheel", "=")
    package_version = read_configuration("./setup.cfg")["metadata"]["version"]
    dist = next(Path("dist").glob(f"aiohttp_pydantic-{package_version}-*.whl"))
    c.run(f"dist_venv/bin/python -m pip install {dist}")

    # We verify that aiohttp-pydantic module is importable before installing CI tools.
    package_names = read_configuration("./setup.cfg")["options"]["packages"]
    for package_name in package_names:
        c.run(f"dist_venv/bin/python -I -c 'import {package_name}'")

    title("Installing CI tools", "=")
    c.run("dist_venv/bin/python -m pip install -r requirements/ci.txt")
Exemple #2
0
    def test_ignore_errors(self, tmpdir):
        _, config = fake_env(
            tmpdir,
            '[metadata]\n' 'version = attr: none.VERSION\n' 'keywords = one, two\n',
        )
        with pytest.raises(ImportError):
            read_configuration('%s' % config)

        config_dict = read_configuration('%s' % config, ignore_option_errors=True)

        assert config_dict['metadata']['keywords'] == ['one', 'two']
        assert 'version' not in config_dict['metadata']

        config.remove()
Exemple #3
0
    def run(self):

        dist = self.distribution
        #homepage = dist.get_url()
        #appname = self._parser.prog
        appname = 'datalad'

        cfg = read_configuration(opj(dirname(dirname(__file__)),
                                     'setup.cfg'))['metadata']

        sections = {
            'Authors':
            """{0} is developed by {1} <{2}>.""".format(
                appname, cfg['author'], cfg['author_email']),
        }

        for cls, opath, ext in ((fmt.ManPageFormatter, self.manpath, '1'),
                                (fmt.RSTManPageFormatter, self.rstpath,
                                 'rst')):
            if not os.path.exists(opath):
                os.makedirs(opath)
            for cmdname in getattr(self, 'cmdline_names', list(self._parser)):
                if hasattr(self, 'cmdlist') and cmdname not in self.cmdlist:
                    continue
                p = self._parser[cmdname]
                cmdname = "{0}{1}".format(
                    'datalad ' if cmdname != 'datalad' else '', cmdname)
                format = cls(cmdname,
                             ext_sections=sections,
                             version=versioneer.get_version())
                formatted = format.format_man_page(p)
                with open(
                        opj(opath, '{0}.{1}'.format(cmdname.replace(' ', '-'),
                                                    ext)), 'w') as f:
                    f.write(formatted)
Exemple #4
0
def requirements_from_setup_cfg(
    package_root: pathlib.Path,
    options: Dict,
    env: sphinx.environment.BuildEnvironment,
    extra: str,
) -> List[str]:
    """
	Load requirements from a ``setup.cfg`` file in the root of the repository.

	:param package_root: The path to the package root.
	:param options:
	:param env:
	:param extra: The name of the "extra" that the requirements are for.

	:return: List of requirements.
	"""

    setup_cfg_file = PathPlus(env.srcdir).parent / "setup.cfg"
    assert setup_cfg_file.is_file()

    setup_cfg = read_configuration(setup_cfg_file)

    if "options" in setup_cfg and "extras_require" in setup_cfg["options"]:
        if extra in setup_cfg["options"]["extras_require"]:
            return setup_cfg["options"]["extras_require"][extra]
        else:
            raise ValueError(
                f"'{extra}' not found in '[options.extras_require]'")
    else:
        raise ValueError(
            "'options.extras_require' section not found in 'setup.cfg")
Exemple #5
0
    def _get_setup_cfg(source_path: str) -> dict:
        """Method responsible to extract the setup.cfg metadata

        :param source_path: Path to the folder where is located the sdist
         files unpacked
        :return: Metadata of setup.cfg
        """
        from setuptools.config import read_configuration

        log.debug(f"Started setup.cfg from {source_path}")
        print_msg("Recovering metadata from setup.cfg")
        path_setup_cfg = list(Path(source_path).rglob("setup.cfg"))
        if not path_setup_cfg:
            return {}
        path_setup_cfg = path_setup_cfg[0]

        setup_cfg = read_configuration(str(path_setup_cfg))
        setup_cfg = dict(setup_cfg)
        if setup_cfg.get("options", {}).get("python_requires"):
            setup_cfg["options"]["python_requires"] = str(
                setup_cfg["options"]["python_requires"])
        result = {}
        result.update(setup_cfg.get("options", {}))
        result.update(setup_cfg.get("metadata", {}))
        if result.get("build_ext"):
            result["compilers"] = ["c"]
        log.debug(f"Data recovered from setup.cfg: {result}")
        return result
Exemple #6
0
def get_python_versions() -> List[str]:
    cfg = read_configuration("setup.cfg")
    python_versions = []
    for clsfr in cfg["metadata"]["classifiers"]:
        if m := re.fullmatch(r'Programming Language :: Python :: (\d+\.\d+)',
                             clsfr):
            python_versions.append(m[1])
Exemple #7
0
def _extract_version(package_name):
    try:
        return pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        _conf = read_configuration(
            path.join(path.dirname(path.dirname(__file__)), 'setup.cfg'))
        return _conf['metadata']['version']
def setup_command():
    cur_dir = '/'.join(dir_name.split(os.sep))

    command = 'pyinstaller -y '
    command += '--clean '
    command += '-F '  # onefile
    command += '-n "lncrawl" '
    command += '-i "%s/res/lncrawl.ico" ' % cur_dir

    config = read_configuration('setup.cfg')
    sep = ';' if platform.system() == 'Windows' else ':'
    for k, paths in config['options']['package_data'].items():
        for v in paths:
            src = os.path.normpath('/'.join([cur_dir, k, v]))
            src = '/'.join(src.split(os.sep))
            dst = os.path.normpath('/'.join([k, v]))
            dst = os.path.dirname(dst)
            dst = '/'.join(dst.split(os.sep))
            dst = (dst + '/') if dst else '.'
            command += '--add-data "%s%s%s" ' % (src, sep, dst)
        # end for
    # end for

    command += '"%s/__main__.py" ' % cur_dir

    print(command)
    print()

    extra = ['--distpath', os.path.join(dir_name, 'dist')]
    extra += ['--workpath', os.path.join(output, 'build')]
    extra += ['--specpath', output]

    sys.argv = shlex.split(command) + extra
Exemple #9
0
def setup(**kwargs):
    """
    A wrapper around setuptools' setup() function that automatically sets up
    custom commands, generates a version file, and customizes the setup process
    via the ``setup_package.py`` files.
    """

    # DEPRECATED: store the package name in a built-in variable so it's easy
    # to get from other parts of the setup infrastructure. We should phase this
    # out in packages that use it - the cookiecutter template should now be
    # able to put the right package name where needed.
    conf = read_configuration('setup.cfg')
    builtins._ASTROPY_PACKAGE_NAME_ = conf['metadata']['name']

    # Create a dictionary with setup command overrides. Note that this gets
    # information about the package (name and version) from the setup.cfg file.
    cmdclass = register_commands()

    # Freeze build information in version.py. Note that this gets information
    # about the package (name and version) from the setup.cfg file.
    version = generate_version_py()

    # Get configuration information from all of the various subpackages.
    # See the docstring for setup_helpers.update_package_files for more
    # details.
    package_info = get_package_info()
    package_info['cmdclass'] = cmdclass
    package_info['version'] = version

    # Override using any specified keyword arguments
    package_info.update(kwargs)

    setuptools_setup(**package_info)
 def get_setup_cfg(_, extracted_files: Iterable[str]) -> Any:
     setup_cfg_candidates = [
         filepath for filepath in extracted_files
         if os.path.basename(filepath) == "setup.cfg"
     ]
     if setup_cfg_candidates:
         return read_configuration(setup_cfg_candidates[0])
def setup(**kwargs):
    """
    A wrapper around setuptools' setup() function that automatically sets up
    custom commands, generates a version file, and customizes the setup process
    via the ``setup_package.py`` files.
    """

    # DEPRECATED: store the package name in a built-in variable so it's easy
    # to get from other parts of the setup infrastructure. We should phase this
    # out in packages that use it - the cookiecutter template should now be
    # able to put the right package name where needed.
    conf = read_configuration('setup.cfg')
    builtins._ASTROPY_PACKAGE_NAME_ = conf['metadata']['name']

    # Create a dictionary with setup command overrides. Note that this gets
    # information about the package (name and version) from the setup.cfg file.
    cmdclass = register_commands()

    # Freeze build information in version.py. Note that this gets information
    # about the package (name and version) from the setup.cfg file.
    version = generate_version_py()

    # Get configuration information from all of the various subpackages.
    # See the docstring for setup_helpers.update_package_files for more
    # details.
    package_info = get_package_info()
    package_info['cmdclass'] = cmdclass
    package_info['version'] = version

    # Override using any specified keyword arguments
    package_info.update(kwargs)

    setuptools_setup(**package_info)
Exemple #12
0
async def async_cli():
    parser = ArgumentParser(
        description='Generate requirements.nix from dependencies')
    parser.add_argument('--python-target',
                        '-V',
                        required=True,
                        help='Major python version')
    args = parser.parse_args()

    target = TargetDetails(args.python_target)

    requirements = set()
    configuration = read_configuration('setup.cfg')

    for dep in configuration['options'].get('setup_requires', []):
        requirements.add(RequirementWrapper.from_requirement(dep))

    for dep in configuration['options'].get('tests_require', []):
        requirements.add(RequirementWrapper.from_requirement(dep))

    for dep in configuration['options'].get('install_requires', []):
        requirements.add(RequirementWrapper.from_requirement(dep))

    for extra in configuration['options'].get('extras', {}).values():
        for dep in extra:
            requirements.add(RequirementWrapper.from_requirement(dep))

    solver = DependencySolver(requirements, target)
    await solver.run()

    write_requirements('requirements.nix', solver.candidates)
Exemple #13
0
def load_setup_py_data_basic(setup_file, work_dir=None):
    _setuptools_data = {}

    import setuptools

    cd_to_work = False
    path_backup = sys.path

    def _change_cwd(target_dir):
        cd_to_work = True
        try:
            cwd = os.getcwd()
        except OSError:
            cwd = recipe_dir or work_dir
        os.chdir(target_dir)
        # this is very important - or else if versioneer or otherwise is in the start folder,
        # things will pick up the wrong versioneer/whatever!
        sys.path.insert(0, target_dir)
        return cd_to_work, cwd

    setup_cfg_data = {}
    try:
        from setuptools.config import read_configuration
    except ImportError:
        pass  # setuptools <30.3.0 cannot read metadata / options from 'setup.cfg'
    else:
        setup_cfg = os.path.join(os.path.dirname(setup_file), 'setup.cfg')
        if os.path.isfile(setup_cfg):
            # read_configuration returns a dict of dicts. Each dict (keys: 'metadata',
            # 'options'), if present, provides keyword arguments for the setup function.
            for kwargs in read_configuration(setup_cfg).values():
                # explicit arguments to setup.cfg take priority over values in setup.py
                setup_cfg_data.update(kwargs)

    def setup(**kw):
        _setuptools_data.update(kw)
        # values in setup.cfg take priority over explicit arguments to setup.py
        _setuptools_data.update(setup_cfg_data)

    # Patch setuptools, distutils
    setuptools_setup = setuptools.setup

    setuptools.setup = setup
    ns = {
        '__name__': '__main__',
        '__doc__': None,
        '__file__': setup_file,
    }
    if os.path.isfile(setup_file):
        with open(setup_file) as f:
            code = compile(f.read(), setup_file, 'exec', dont_inherit=1)
            exec(code, ns, ns)

    setuptools.setup = setuptools_setup

    if cd_to_work: os.chdir(cwd)
    # remove our workdir from sys.path
    sys.path = path_backup
    return _setuptools_data
Exemple #14
0
def inspect_project(dirpath: Optional[Union[str, Path]] = None) -> dict:
    """Fetch various information about an already-initialized project"""
    if dirpath is None:
        directory = Path()
    else:
        directory = Path(dirpath)

    def exists(*fname: str) -> bool:
        return Path(directory, *fname).exists()

    if not exists("pyproject.toml"):
        raise InvalidProjectError("Project is missing pyproject.toml file")
    if not exists("setup.cfg"):
        raise InvalidProjectError("Project is missing setup.cfg file")
    if not exists("src"):
        raise InvalidProjectError("Project does not have src/ layout")

    cfg = read_configuration(str(directory / "setup.cfg"))
    env = {
        "name": cfg["metadata"]["name"],
        "short_description": cfg["metadata"]["description"],
        "author": cfg["metadata"]["author"],
        "author_email": cfg["metadata"]["author_email"],
        "python_requires": util.sort_specifier(cfg["options"]["python_requires"]),
        "install_requires": cfg["options"].get("install_requires", []),
        # Until <https://github.com/pypa/setuptools/issues/2575> is fixed, we
        # have to determine versions via read_version() instead of
        # read_configuration().
        # "version": cfg["metadata"].get("version"),
        "keywords": cfg["metadata"].get("keywords", []),
        "supports_pypy3": False,
        "default_branch": git.Git(dirpath=directory).get_default_branch(),
    }

    # if env["version"] is None:
    #    raise InvalidProjectError("Cannot determine project version")

    if cfg["options"].get("packages"):
        env["is_flat_module"] = False
        env["import_name"] = cfg["options"]["packages"][0]
        initfile = directory / "src" / env["import_name"] / "__init__.py"
    else:
        env["is_flat_module"] = True
        env["import_name"] = cfg["options"]["py_modules"][0]
        initfile = directory / "src" / (env["import_name"] + ".py")

    try:
        env["version"] = versioningit.get_version(directory)
        env["uses_versioningit"] = True
    except versioningit.NotVersioningitError:
        env["version"] = read_version(initfile.resolve())
        env["uses_versioningit"] = False

    env["python_versions"] = []
    for clsfr in cfg["metadata"]["classifiers"]:
        if m := re.fullmatch(r"Programming Language :: Python :: (\d+\.\d+)", clsfr):
            env["python_versions"].append(util.PyVersion.parse(m[1]))
        if clsfr == "Programming Language :: Python :: Implementation :: PyPy":
            env["supports_pypy3"] = True
Exemple #15
0
def check_setup_cfg():
    """Check setup.cfg"""
    check_path("setup.cfg")
    errors = 0

    setup_config = read_configuration(os.path.join(ROOT_DIR, "setup.cfg"))

    # parse data from setup.cfg
    classifiers = setup_config["metadata"]["classifiers"]
    install_requires = setup_config["options"]["install_requires"]

    # validate that we have the proper language/django classifiers
    pyver_cfs = [
        m.groups(0)[0] for m in filter(
            None,
            [re.search(r"Python :: (3\.[0-9]+)$", cf) for cf in classifiers])
    ]
    if pyver_cfs != CONFIG["python-major"]:
        errors += err(
            f'Wrong python classifiers: Have {pyver_cfs}, wanted {CONFIG["python-major"]}'
        )

    djver_cfs = [
        m.groups(0)[0] for m in filter(None, [
            re.search(r"Django :: ([0-9]\.[0-9]+)$", cf) for cf in classifiers
        ])
    ]
    if djver_cfs != CONFIG["django-major"]:
        errors += err(
            f'Wrong python classifiers: Have {djver_cfs}, wanted {CONFIG["django-major"]}'
        )

    for djver in CONFIG["django-map"]:
        if f"Framework :: Django :: {djver}" not in classifiers:
            errors += err(f"Django {djver} classifier not found.")

    expected_py_req = f">={CONFIG['python-major'][0]}"
    actual_py_req = setup_config["options"]["python_requires"]
    if actual_py_req != expected_py_req:
        errors += err(
            f"python_requires: Have {actual_py_req}, expected {expected_py_req}"
        )

    expected_django_req = f"Django>={CONFIG['django-major'][0]}"
    if expected_django_req not in install_requires:
        errors += err(
            f"{expected_django_req}: Expected Django requirement not found.")

    expected_cg_req = f"cryptography>={CONFIG['cryptography-major'][0]}"
    if expected_cg_req not in install_requires:
        errors += err(
            f"{expected_cg_req}: Expected cryptography requirement not found.")

    # Do not check setup.cfg minimum dependency, as actually any version works fine right now
    # expected_idna_req = f"idna>={CONFIG['idna-major'][0]}"
    # if expected_idna_req not in install_requires:
    #    errors += err(f"{expected_idna_req}: Expected idna requirement not found.")

    return errors
Exemple #16
0
    def major_minor_version(cls):
        """Find the major minor declared in the setup.cfg."""
        try:
            config = read_configuration("setup.cfg")
        except DistutilsFileError:
            raise FileNotFoundError("setup.cfg")

        return version.parse(config["metadata"]["version"])
Exemple #17
0
    def test_ignore_errors(self, tmpdir):
        _, config = fake_env(
            tmpdir,
            '[metadata]\n'
            'version = attr: none.VERSION\n'
            'keywords = one, two\n'
        )
        with pytest.raises(ImportError):
            read_configuration('%s' % config)

        config_dict = read_configuration(
            '%s' % config, ignore_option_errors=True)

        assert config_dict['metadata']['keywords'] == ['one', 'two']
        assert 'version' not in config_dict['metadata']

        config.remove()
def extractFromSetupCfg(setupCfgPath: Path) -> typing.Optional[str]:
    from setuptools.config import read_configuration

    setupCfg = read_configuration(setupCfgPath)
    try:
        return setupCfg["metadata"]["name"]
    except KeyError:
        return None
Exemple #19
0
def tag_eq_version(c):
    """
    Ensure that the last git tag matches the package version
    """
    git_tag = c.run("git describe --tags HEAD", hide=True).stdout.strip()
    package_version = read_configuration("./setup.cfg")["metadata"]["version"]
    if git_tag != f"v{package_version}":
        raise Exit(f"ERROR: The git tag {git_tag!r} does not matches"
                   f" the package version {package_version!r}")
Exemple #20
0
def get_configuration(setup_cfg):
    """
    Read the setup.cfg file.

    :param setup_cfg: The path of the setup.cfg file
    :returns: The configuration data
    :rtype: dict
    """
    return read_configuration(str(setup_cfg))
Exemple #21
0
def _extract_version(package_name):
    """
    Get package version from installed distribution or configuration file if not
    installed
    """
    try:
        return pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        _conf = read_configuration(os.path.join(PROJECT_DIR, "setup.cfg"))
    return _conf["metadata"]["version"]
Exemple #22
0
def _extract_version(package_name):
    try:
        import pkg_resources
        return pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        from setuptools.config import read_configuration
        from os import path as _p
        _conf = read_configuration(
            _p.join(_p.dirname(_p.dirname(__file__)), "setup.cfg"))
        return _conf["metadata"]["version"]
Exemple #23
0
 def __init__(
     self,
     setup_cfg_path: str,
     logger: Logger,
     requirement_parser: RequirementParser,
 ):
     self.setup_cfg_path = setup_cfg_path
     self.setup_cfg = read_configuration(setup_cfg_path)
     self.logger = logger
     self.requirement_parser = requirement_parser
Exemple #24
0
def _extract_version(package_name):
    """
    Get package version from installed distribution or configuration file if not
    installed
    """
    try:
        return pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        _conf = read_configuration(os.path.join(PROJECT_DIR, "setup.cfg"))
    return _conf["metadata"]["version"]
Exemple #25
0
def cli(sections, input, output, quiet):
    # Set YAML parameters
    yaml = YAML(typ="rt")  # Round-trip mode allows for comment insertion
    indent_offset = 2
    yaml.indent(offset=indent_offset)

    # Load environment file template
    with open(os.path.join("requirements", "environment.in")) as f:
        env_yml = yaml.load(f.read())

    # Extract dependency section contents
    if not quiet:
        print(f"Reading dependencies from {input}")

    setup_config = read_configuration(input)
    sections = [x.strip() for x in sections.split(",")]
    section_indices = dict()
    dep_list = (deepcopy(env_yml["dependencies"])
                if "dependencies" in env_yml else [])
    i = len(dep_list)

    for section in sections:
        section_indices[section] = i

        try:
            packages = (setup_config["options"]["install_requires"]
                        if section == "main" else
                        setup_config["options"]["extras_require"][section])
        except KeyError:
            raise RuntimeError(f"Cannot fetch dependencies from {input}")

        for package in packages:
            if package not in dep_list:  # Do not duplicate
                dep_list.append(package)
                i += 1

    # Format dependency list
    lst = CS(dep_list)

    for section, i in section_indices.items():
        lst.yaml_set_comment_before_after_key(i, section, indent_offset)

    env_yml["dependencies"] = lst

    # Output to terminal
    if not quiet:
        yaml.dump(env_yml, sys.stdout)

    # Output to file
    if output is not None:
        with open(output, "w") as outfile:
            if not quiet:
                print()
            print(f"Saving to {output}")
            yaml.dump(env_yml, outfile)
Exemple #26
0
def set_version():
    here = os.path.abspath(os.path.dirname(__file__))
    config = read_configuration(os.path.join(here, "setup.cfg"))
    version = config["metadata"]["version"]
    try:
        branch_name = os.environ["BRANCH_NAME"]
        if branch_name != "dev" and "dev" in version:
            version += "-" + branch_name
    except KeyError:
        pass
    return version
Exemple #27
0
def _extract_version(package_name):
    try:
        # if package is installed
        version = pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        # if not installed, so we must be in source, with ``setup.cfg`` available
        _conf = read_configuration(
            path.join(path.dirname(__file__), '..', 'setup.cfg'))
        version = _conf['metadata']['version']

    return version
def _extract_version(package_name):
    try:
        # if package is installed
        version = pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        # if not installed, so we must be in source, with ``setup.cfg`` available
	    _conf = read_configuration(path.join(
	        path.dirname(__file__), '..', 'setup.cfg')
	    )
	    version = _conf['metadata']['version']

    return version
Exemple #29
0
def _extract_version(package_name):
    """
    Extract fonzie version.

    Get package version from installed distribution or configuration file if not installed
    """
    try:
        return pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        _conf = read_configuration(
            path.join(path.dirname(path.dirname(__file__)), 'setup.cfg'))
    return _conf['metadata']['version']
 def test_basic(self, tmpdir):
     _, config = fake_env(
         tmpdir, '[metadata]\n'
         'version = 10.1.1\n'
         'keywords = one, two\n'
         '\n'
         '[options]\n'
         'scripts = bin/a.py, bin/b.py\n')
     config_dict = read_configuration('%s' % config)
     assert config_dict['metadata']['version'] == '10.1.1'
     assert config_dict['metadata']['keywords'] == ['one', 'two']
     assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py']
Exemple #31
0
def _extract_version(package_name):
    try:
        # if package is installed
        version = pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        # if not installed, so we must be in source, with ``setup.cfg`` available
        from setuptools.config import read_configuration
        _conf = read_configuration(
            path.join(path.dirname(__file__), 'setup.cfg'))
        version = _conf['metadata']['version']

    return tuple(int(part) for part in version.split('.') if part.isnumeric())
def _extract_version(package_name):
    try:
        # if package is installed
        version = pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        # if not installed, so we must be in source, with ``setup.cfg`` available
        from setuptools.config import read_configuration
        _conf = read_configuration(path.join(
            path.dirname(__file__), 'setup.cfg')
        )
        version = _conf['metadata']['version']

    return tuple(int(part) for part in version.split('.') if part.isnumeric())
Exemple #33
0
 def test_basic(self, tmpdir):
     _, config = fake_env(
         tmpdir,
         '[metadata]\n'
         'version = 10.1.1\n'
         'keywords = one, two\n'
         '\n'
         '[options]\n'
         'scripts = bin/a.py, bin/b.py\n'
     )
     config_dict = read_configuration('%s' % config)
     assert config_dict['metadata']['version'] == '10.1.1'
     assert config_dict['metadata']['keywords'] == ['one', 'two']
     assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py']
Exemple #34
0
def load_setup_py_data_basic(setup_file, work_dir=None):
    _setuptools_data = {}

    import setuptools

    cd_to_work = False
    path_backup = sys.path

    os.chdir(work_dir)
    setup_cfg_data = {}
    try:
        from setuptools.config import read_configuration
    except ImportError:
        pass  # setuptools <30.3.0 cannot read metadata / options from 'setup.cfg'
    else:
        setup_cfg = os.path.join(os.path.dirname(setup_file), "setup.cfg")
        if os.path.isfile(setup_cfg):
            # read_configuration returns a dict of dicts. Each dict (keys: 'metadata',
            # 'options'), if present, provides keyword arguments for the setup function.
            for kwargs in read_configuration(setup_cfg).values():
                # explicit arguments to setup.cfg take priority over values in setup.py
                setup_cfg_data.update(kwargs)

    def setup(**kw):
        _setuptools_data.update(kw)
        # values in setup.cfg take priority over explicit arguments to setup.py
        _setuptools_data.update(setup_cfg_data)

    # Patch setuptools, distutils
    setuptools_setup = setuptools.setup

    setuptools.setup = setup
    ns = {
        "__name__": "__main__",
        "__doc__": None,
        "__file__": setup_file,
    }
    if os.path.isfile(setup_file):
        with open(setup_file) as f:
            code = compile(f.read(), setup_file, "exec", dont_inherit=1)
            exec(code, ns, ns)

    setuptools.setup = setuptools_setup

    if cd_to_work:
        os.chdir(cwd)
    # remove our workdir from sys.path
    sys.path = path_backup
    return _setuptools_data
Exemple #35
0
def upload(c, pypi_user=None, pypi_password=None):
    """
    Upload on pypi
    """
    package_version = read_configuration("./setup.cfg")["metadata"]["version"]
    dist = next(Path("dist").glob(f"aiohttp_pydantic-{package_version}-*.whl"))
    if pypi_user is not None and pypi_password is not None:
        c.run(
            f"dist_venv/bin/twine upload --non-interactive"
            f" -u {pypi_user} -p {pypi_password} {dist}",
            hide=True,
        )
    else:
        c.run(
            f"dist_venv/bin/twine upload --repository aiohttp-pydantic {dist}")
def load_setup_py_data_basic(setup_file, work_dir=None):
    _setuptools_data = {}

    import setuptools

    cd_to_work = False
    path_backup = sys.path

    os.chdir(work_dir)
    setup_cfg_data = {}
    try:
        from setuptools.config import read_configuration
    except ImportError:
        pass  # setuptools <30.3.0 cannot read metadata / options from 'setup.cfg'
    else:
        setup_cfg = os.path.join(os.path.dirname(setup_file), 'setup.cfg')
        if os.path.isfile(setup_cfg):
            # read_configuration returns a dict of dicts. Each dict (keys: 'metadata',
            # 'options'), if present, provides keyword arguments for the setup function.
            for kwargs in read_configuration(setup_cfg).values():
                # explicit arguments to setup.cfg take priority over values in setup.py
                setup_cfg_data.update(kwargs)

    def setup(**kw):
        _setuptools_data.update(kw)
        # values in setup.cfg take priority over explicit arguments to setup.py
        _setuptools_data.update(setup_cfg_data)

    # Patch setuptools, distutils
    setuptools_setup = setuptools.setup

    setuptools.setup = setup
    ns = {
        '__name__': '__main__',
        '__doc__': None,
        '__file__': setup_file,
    }
    if os.path.isfile(setup_file):
        with open(setup_file) as f:
            code = compile(f.read(), setup_file, 'exec', dont_inherit=1)
            exec(code, ns, ns)

    setuptools.setup = setuptools_setup

    if cd_to_work: os.chdir(cwd)
    # remove our workdir from sys.path
    sys.path = path_backup
    return _setuptools_data
Exemple #37
0
def _find_plugins():
    subdirs = sorted(
        Path(x) for x in next(os.walk('.'))[1] if x[0] != '.' and x != '_meta'
        and os.path.exists(os.path.join(x, 'setup.cfg')))
    for subdir in subdirs:
        path = subdir / 'setup.cfg'
        metadata = read_configuration(path)['metadata']
        name = metadata['name']
        version = metadata['version']
        if name is None or version is None:
            click.secho(f'Could not extract name/version from {path}',
                        fg='red',
                        bold=True)
            continue
        minver = str(Version(version))
        yield name, minver
Exemple #38
0
def createInitFile(dist=None, version=None, sha=None):
    """Create psychopy/__init__.py

    :param:`dist` can be:
        None:
            writes __version__
        'sdist':
            for python setup.py sdist - writes git id (__git_sha__)
        'bdist':
            for python setup.py bdist - writes git id (__git_sha__)
            and __build_platform__
    """
    # get default values if None
    if version is None:
        with open(os.path.join(thisLoc,'version')) as f:
            version = f.read().strip()
    if sha is None:
        sha = _getGitShaString(dist)
    platformStr = _getPlatformString(dist)

    metadata = read_configuration('setup.cfg')['metadata']
    infoDict = {'version': version,
                'author': metadata['author'],
                'author_email': metadata['author_email'],
                'maintainer_email': metadata['maintainer_email'],
                'url': metadata['url'],
                'download_url': metadata['download_url'],
                'license': metadata['license'],
                'shaStr': sha,
                'platform': platformStr}

    # write it
    with open(os.path.join(thisLoc, 'psychopy','__init__.py'), 'w') as f:
        outStr = template.format(**infoDict)
        f.write(outStr)
    print('wrote init for ', version, sha)
    # and return it
    return outStr
Exemple #39
0
 def test_no_config(self, tmpdir):
     with pytest.raises(DistutilsFileError):
         read_configuration('%s' % tmpdir.join('setup.cfg'))
Exemple #40
0
import os
import sys

from setuptools import setup
from setuptools.config import read_configuration

from setuputils import find_version


def here(*paths):
    return os.path.join(os.path.dirname(__file__), *paths)

config = read_configuration(here('setup.cfg'))
config['metadata']['version'] = find_version(here('astor', '__init__.py'))
config['options'].update(config['metadata'])

setup(**config['options'])
Exemple #41
0
from astropy_helpers.setup_helpers import setup, register_commands # noqa

################################################################################
# Override the default Astropy Test Command
################################################################################
cmdclass = register_commands()
try:
    from sunpy.tests.setup_command import SunPyTest
    # Overwrite the Astropy Testing framework
    cmdclass['test'] = type('SunPyTest', (SunPyTest,),
                            {'package_name': 'sunpy'})
except Exception:
    # Catch everything, if it doesn't work, we still want SunPy to install.
    pass

################################################################################
# Programmatically generate some extras combos.
################################################################################
extras = read_configuration("setup.cfg")['options']['extras_require']

# Dev is everything
extras['dev'] = list(chain(*extras.values()))

# All is everything but tests and docs
exclude_keys = ("tests", "docs", "dev")
ex_extras = dict(filter(lambda i: i[0] not in exclude_keys, extras.items()))
# Concatenate all the values together for 'all'
extras['all'] = list(chain.from_iterable(ex_extras.values()))

setup(extras_require=extras, cmdclass=cmdclass)
Exemple #42
0
#!/usr/bin/env python3
from pathlib import Path
from setuptools import setup
from setuptools.config import read_configuration

cfg = read_configuration(Path(__file__).parent / 'setup.cfg')
#print(cfg)
cfg["options"].update(cfg["metadata"])
cfg=cfg["options"]
setup(use_scm_version = True, **cfg)
Exemple #43
0
# Copyright (c) 2019 Ian C. Good
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from setuptools import setup  # type: ignore
from setuptools.config import read_configuration  # type: ignore

conf_dict = read_configuration('setup.cfg')
setup(**conf_dict['metadata'], **conf_dict['options'])
Exemple #44
0
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import sys

from distutils.version import LooseVersion

# We require setuptools 30.3.0 or later for the configuration in setup.cfg to
# work properly.
import setuptools
if LooseVersion(setuptools.__version__) < LooseVersion('30.3.0'):
    sys.stderr.write("ERROR: Astropy requires setuptools 30.3.0 or later "
                     "(found {0})".format(setuptools.__version__))
    sys.exit(1)

from setuptools.config import read_configuration
conf = read_configuration('setup.cfg')

import os
import glob

import ah_bootstrap
from setuptools import setup

from astropy_helpers.setup_helpers import (
    register_commands, get_package_info, get_debug_option)
from astropy_helpers.distutils_helpers import is_distutils_display_option
from astropy_helpers.git_helpers import get_git_devstr
from astropy_helpers.version_helpers import generate_version_py

import astropy
Exemple #45
0
from setuptools import setup, find_packages
from setuptools.config import read_configuration
import os
from os.path import exists, join
from sys import platform, argv, version_info


PY3 = version_info >= (3, 0)
with open('version') as f:
    version = f.read().strip()

#
# Special handling for Anaconda / Miniconda
#

required = read_configuration('setup.cfg')['options']['install_requires']

# OpenCV
# Naming conflict with PyPI package.
# `opencv` package should be installed via conda instead
if 'CONDA_PREFIX' in os.environ:
    required.remove('opencv-python')

# PyQt
# Naming conflict with PyPI package.
# `pyqt` package should be installed via conda instead
# cf. https://github.com/ContinuumIO/anaconda-issues/issues/1554
if PY3 and 'CONDA_PREFIX' in os.environ:
    required.remove('pyqt5; python_version >= "3"')

# for dev you also want:
import os
from setuptools import setup
from setuptools.config import read_configuration

this_dir = os.path.dirname(__file__)
cfg = read_configuration(os.path.join(this_dir, 'setup.cfg'))
#print(cfg)
cfg["options"].update(cfg["metadata"])
cfg = cfg["options"]

setup(**cfg)
Exemple #47
0
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os


# Import asynctest source directory
sys.path.insert(0, os.path.abspath('..'))  # NOQA


try:
    from setuptools.config import read_configuration
    cfg_path = os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')
    setup_args = read_configuration(cfg_path)['metadata']
except ImportError:
    from setup import args as setup_args, read_version
    setup_args["author"] = "Martin Richard"
    setup_args["description"] = ""
    setup_args["version"] = read_version()

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
def get_package_info(srcdir='.', exclude=()):
    """
    Collates all of the information for building all subpackages
    and returns a dictionary of keyword arguments that can
    be passed directly to `distutils.setup`.

    The purpose of this function is to allow subpackages to update the
    arguments to the package's ``setup()`` function in its setup.py
    script, rather than having to specify all extensions/package data
    directly in the ``setup.py``.  See Astropy's own
    ``setup.py`` for example usage and the Astropy development docs
    for more details.

    This function obtains that information by iterating through all
    packages in ``srcdir`` and locating a ``setup_package.py`` module.
    This module can contain the following functions:
    ``get_extensions()``, ``get_package_data()``,
    ``get_build_options()``, and ``get_external_libraries()``.

    Each of those functions take no arguments.

    - ``get_extensions`` returns a list of
      `distutils.extension.Extension` objects.

    - ``get_package_data()`` returns a dict formatted as required by
      the ``package_data`` argument to ``setup()``.

    - ``get_build_options()`` returns a list of tuples describing the
      extra build options to add.

    - ``get_external_libraries()`` returns
      a list of libraries that can optionally be built using external
      dependencies.
    """
    ext_modules = []
    packages = []
    package_dir = {}

    # Read in existing package data, and add to it below
    setup_cfg = os.path.join(srcdir, 'setup.cfg')
    if os.path.exists(setup_cfg):
        conf = read_configuration(setup_cfg)
        if 'options' in conf and 'package_data' in conf['options']:
            package_data = conf['options']['package_data']
        else:
            package_data = {}
    else:
        package_data = {}

    if exclude:
        warnings.warn(
            "Use of the exclude parameter is no longer supported since it does "
            "not work as expected. Use add_exclude_packages instead. Note that "
            "it must be called prior to any other calls from setup helpers.",
            AstropyDeprecationWarning)

    # Use the find_packages tool to locate all packages and modules
    packages = find_packages(srcdir, exclude=exclude)

    # Update package_dir if the package lies in a subdirectory
    if srcdir != '.':
        package_dir[''] = srcdir

    # For each of the setup_package.py modules, extract any
    # information that is needed to install them.  The build options
    # are extracted first, so that their values will be available in
    # subsequent calls to `get_extensions`, etc.
    for setuppkg in iter_setup_packages(srcdir, packages):
        if hasattr(setuppkg, 'get_build_options'):
            options = setuppkg.get_build_options()
            for option in options:
                add_command_option('build', *option)
        if hasattr(setuppkg, 'get_external_libraries'):
            libraries = setuppkg.get_external_libraries()
            for library in libraries:
                add_external_library(library)

    for setuppkg in iter_setup_packages(srcdir, packages):
        # get_extensions must include any Cython extensions by their .pyx
        # filename.
        if hasattr(setuppkg, 'get_extensions'):
            ext_modules.extend(setuppkg.get_extensions())
        if hasattr(setuppkg, 'get_package_data'):
            package_data.update(setuppkg.get_package_data())

    # Locate any .pyx files not already specified, and add their extensions in.
    # The default include dirs include numpy to facilitate numerical work.
    ext_modules.extend(get_cython_extensions(srcdir, packages, ext_modules,
                                             ['numpy']))

    # Now remove extensions that have the special name 'skip_cython', as they
    # exist Only to indicate that the cython extensions shouldn't be built
    for i, ext in reversed(list(enumerate(ext_modules))):
        if ext.name == 'skip_cython':
            del ext_modules[i]

    # On Microsoft compilers, we need to pass the '/MANIFEST'
    # commandline argument.  This was the default on MSVC 9.0, but is
    # now required on MSVC 10.0, but it doesn't seem to hurt to add
    # it unconditionally.
    if get_compiler_option() == 'msvc':
        for ext in ext_modules:
            ext.extra_link_args.append('/MANIFEST')

    return {
        'ext_modules': ext_modules,
        'packages': packages,
        'package_dir': package_dir,
        'package_data': package_data,
        }
Exemple #49
0
def load_setup_py_data(config, setup_file='setup.py', from_recipe_dir=False, recipe_dir=None,
                       permit_undefined_jinja=True):
    _setuptools_data = {}
    log = get_logger(__name__)

    def setup(**kw):
        _setuptools_data.update(kw)

    import setuptools
    import distutils.core

    cd_to_work = False
    path_backup = sys.path

    if from_recipe_dir and recipe_dir:
        setup_file = os.path.abspath(os.path.join(recipe_dir, setup_file))
    elif os.path.exists(config.work_dir):
        cd_to_work = True
        cwd = os.getcwd()
        os.chdir(config.work_dir)
        if not os.path.isabs(setup_file):
            setup_file = os.path.join(config.work_dir, setup_file)
        # this is very important - or else if versioneer or otherwise is in the start folder,
        # things will pick up the wrong versioneer/whatever!
        sys.path.insert(0, config.work_dir)
    else:
        message = ("Did not find setup.py file in manually specified location, and source "
                  "not downloaded yet.")
        if permit_undefined_jinja:
            log.debug(message)
            return {}
        else:
            raise RuntimeError(message)

    # Patch setuptools, distutils
    setuptools_setup = setuptools.setup
    distutils_setup = distutils.core.setup
    numpy_setup = None

    versioneer = None
    if 'versioneer' in sys.modules:
        versioneer = sys.modules['versioneer']
        del sys.modules['versioneer']

    try:
        import numpy.distutils.core
        numpy_setup = numpy.distutils.core.setup
        numpy.distutils.core.setup = setup
    except ImportError:
        log.debug("Failed to import numpy for setup patch.  Is numpy installed?")

    setuptools.setup = distutils.core.setup = setup
    ns = {
        '__name__': '__main__',
        '__doc__': None,
        '__file__': setup_file,
    }
    if os.path.isfile(setup_file):
        try:
            from setuptools.config import read_configuration
        except ImportError:
            pass  # setuptools <30.3.0 cannot read metadata / options from 'setup.cfg'
        else:
            setup_cfg = os.path.join(os.path.dirname(setup_file), 'setup.cfg')
            if os.path.isfile(setup_cfg):
                # read_configuration returns a dict of dicts. Each dict (keys: 'metadata',
                # 'options'), if present, provides keyword arguments for the setup function.
                for kwargs in read_configuration(setup_cfg).values():
                    _setuptools_data.update(kwargs)
        code = compile(open(setup_file).read(), setup_file, 'exec', dont_inherit=1)
        exec(code, ns, ns)
    else:
        if not permit_undefined_jinja:
            raise TypeError('{} is not a file that can be read'.format(setup_file))

    sys.modules['versioneer'] = versioneer

    distutils.core.setup = distutils_setup
    setuptools.setup = setuptools_setup
    if numpy_setup:
        numpy.distutils.core.setup = numpy_setup
    if cd_to_work:
        os.chdir(cwd)
    # remove our workdir from sys.path
    sys.path = path_backup
    return _setuptools_data if _setuptools_data else None
Exemple #50
0

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("requirements", nargs="*")
    parser.add_argument("--extras", default=[])

    args = parser.parse_args()
    if args.extras:
        args.extras = set(args.extras.split(','))
    options = {}

    print('# AUTOGENERATED by {}\n# DO NOT EDIT\n#\n'.format(sys.argv[0]))

    if os.path.exists('setup.cfg'):
        options = read_configuration('setup.cfg').get('options', {})

    install_requires = options.get('install_requires', [])
    extras_require = options.get('extras_require', {})

    if install_requires:
        fname = 'setup.cfg:options.install_requires'
        print_file(
            fname,
            (Requirement.parse(l) for l in sorted(install_requires)),
        )

    for extra, requires in sorted(extras_require.items()):
        if extra in args.extras:
            fname = 'setup.cfg:options.extras_require:' + extra
            print_file(
Exemple #51
0
        except NoSectionError:
            pass
        opt['package_data'] = {}
        for k, v in opt_package_data.items():
            opt['package_data'][k] = cfg_val_to_list(v)
        cur_pkgs = opt.get('packages', '').strip()
        if '\n' in cur_pkgs:
            opt['packages'] = cfg_val_to_list(opt['packages'])
        elif cur_pkgs.startswith('find:'):
            opt_packages_find = dict(cfg.items('options.packages.find'))
            opt['packages'] = setuptools.find_packages(**opt_packages_find)
        return {'metadata': md, 'options': opt}


setup_params = {}
declarative_setup_params = read_configuration('setup.cfg')

# Patch incorrectly decoded package_dir option
# ``egg_info`` demands native strings failing with unicode under Python 2
# Ref https://github.com/pypa/setuptools/issues/1136
if 'package_dir' in declarative_setup_params['options']:
    declarative_setup_params['options']['package_dir'] = {
        str(k): str(v)
        for k, v in declarative_setup_params['options']['package_dir'].items()
    }

setup_params = dict(setup_params, **declarative_setup_params['metadata'])
setup_params = dict(setup_params, **declarative_setup_params['options'])


__name__ == '__main__' and setuptools.setup(**setup_params)
Exemple #52
0
# setup_requires and install_requires since these are determined
# programmatically.

import os
import builtins

import ah_bootstrap  # noqa

from astropy_helpers.distutils_helpers import is_distutils_display_option
from astropy_helpers.setup_helpers import setup

from setuptools.config import read_configuration

# We set up the following variable because we then use this in astropy/__init__.py
# to make sure that we aren't importing astropy during the setup process (we used
# to do this)
builtins._ASTROPY_CORE_SETUP_ = True

if is_distutils_display_option():
    # Avoid installing setup_requires dependencies if the user just
    # queries for information
    setup_requires = []
else:
    setup_requires = read_configuration('setup.cfg')['options']['setup_requires']
    # Make sure we have the packages needed for building astropy, but do not
    # require them when installing from an sdist as the c files are included.
    if not os.path.exists(os.path.join(os.path.dirname(__file__), 'PKG-INFO')):
        setup_requires.extend(['cython>=0.21', 'jinja2>=2.7'])

setup(setup_requires=setup_requires)