Example #1
0
def _get_version() -> str:
    from pathlib import Path
    import versioningit
    import broadbean

    project_dir = Path(broadbean.__file__).parent.parent
    return versioningit.get_version(project_dir=project_dir)
Example #2
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
Example #3
0
def _get_version() -> str:
    from pathlib import Path

    import versioningit

    import plottr

    path = Path(plottr.__file__).parent
    return versioningit.get_version(project_dir=path.parent)
Example #4
0
def _get_version() -> str:
    from pathlib import Path

    import versioningit

    import qcodes

    qcodes_path = Path(qcodes.__file__).parent
    return versioningit.get_version(project_dir=qcodes_path.parent)
Example #5
0
def get_git_version(inst_path: Path | str) -> str:
    """Load the version from Git history."""
    import versioningit
    return versioningit.get_version(
        project_dir=inst_path,
        config={
            'vcs': {
                'method': 'git'
            },
            'default-version': '(dev)',
            'format': {
                # Ignore dirtyness, we generate the translation files every time.
                'distance': '{version}.dev+{rev}',
                'dirty': '{version}',
                'distance-dirty': '{version}.dev+{rev}',
            },
        },
    )
Example #6
0
def get_qcodes_version() -> str:
    """
    Get the version of the currently installed QCoDeS
    """
    import qcodes
    package_name = "qcodes"

    qcodes_path = Path(qcodes.__file__).parent
    if _has_pyproject_toml_and_is_git_repo(qcodes_path.parent):
        log.info(
            f"QCoDeS seems to be installed editably trying to look up version "
            f"from git repo in {qcodes_path}")

        import versioningit

        __version__ = versioningit.get_version(project_dir=qcodes_path.parent)
    else:
        __version__ = version(package_name)
    return __version__
Example #7
0
def _get_version() -> str:
    from pathlib import Path
    from versioningit import get_version
    import streamlink

    return get_version(project_dir=Path(streamlink.__file__).parents[2])