Skip to content

Commit

Permalink
Allow to manage project version with git tags
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
4383 committed Apr 12, 2019
1 parent f2e2ed4 commit 3c322c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions poetry/vcs/git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import pkg_resources
import re
import subprocess

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -100,3 +104,15 @@ 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)
version = Version.parse(version)
return version

0 comments on commit 3c322c9

Please sign in to comment.