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..fa35da4a932 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,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