From 620cd63a44743e997f0096f19db8acfb1601829f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Fri, 12 Apr 2019 17:49:40 +0200 Subject: [PATCH] Allow to manage project version with git tags To avoid to manage textual version of a project allow poetry to retrieve those informations directly from git tags. To determine the current version number we currently retrieve the highest available tag number. If the version is not available in the pyproject.toml then poetry try to retrieve version from git so project can continue to manage these informations manually. If the version is not available in the pyproject.toml and if it's not a git repository then an exception is raised and we retrieve the previous behavior of poetry. --- poetry/poetry.py | 3 ++- poetry/vcs/git.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/poetry/poetry.py b/poetry/poetry.py index f9b93cad4a9..d0a748167f1 100644 --- a/poetry/poetry.py +++ b/poetry/poetry.py @@ -21,6 +21,7 @@ from .utils._compat import Path from .utils.helpers import get_http_basic_auth from .utils.toml_file import TomlFile +from .vcs.git import version_from_tags class Poetry: @@ -107,7 +108,7 @@ def create(cls, cwd): # type: (Path) -> Poetry # Load package name = local_config["name"] - version = local_config["version"] + version = local_config.get("version", version_from_tags()) package = ProjectPackage(name, version, version) package.root_dir = poetry_file.parent diff --git a/poetry/vcs/git.py b/poetry/vcs/git.py index c3b8b2285b3..a9c485323f3 100644 --- a/poetry/vcs/git.py +++ b/poetry/vcs/git.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import pkg_resources import re import subprocess @@ -44,6 +45,9 @@ def config(self): # type: () -> GitConfig def clone(self, repository, dest): # type: (...) -> str return self.run("clone", repository, str(dest)) + def tag(self): # type: (...) -> list + return self.run("tag").split("\n") + def checkout(self, rev, folder=None): # type: (...) -> str args = [] if folder is None and self._work_dir: @@ -100,3 +104,14 @@ def run(self, *args): # type: (...) -> str return decode( subprocess.check_output(["git"] + list(args), stderr=subprocess.STDOUT) ) + + +def version_from_tags(): + from poetry.semver import Version + + git = Git() + version = "0.0.0" + tags = git.tag() + if tags: + version = max(tags, key=pkg_resources.parse_version) + return Version.parse(version)