From ec301695e1dabcff6f2b724c4ba5613059df749a Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 25 Nov 2018 16:15:27 +0100 Subject: [PATCH] Get version using an arbitraty executable --- poetry/packages/project_package.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/poetry/packages/project_package.py b/poetry/packages/project_package.py index 2af30f8b175..ba8d4bd26f1 100644 --- a/poetry/packages/project_package.py +++ b/poetry/packages/project_package.py @@ -8,6 +8,23 @@ class ProjectPackage(Package): def __init__(self, name, version, pretty_version=None): + if isinstance(version, str) and version.startswith('attr:'): + version_pkg, _, version_attr = ( + version[6:].strip().rpartition('.') + ) + if not version_pkg: + version_pkg = 'builtins' + version_getter = getattr( + __import__(version_pkg, fromlist=(version_pkg, )), + version_attr, + ) + version = version_getter() + if version is None: + raise RuntimeError( + 'The version getter callable must return a string ' + 'or a Version instance' + ) + super(ProjectPackage, self).__init__(name, version, pretty_version) self.build = None