summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGökçen Nurlu <gnurlu1@bloomberg.net>2018-01-11 18:06:45 +0000
committerJürg Billeter <j@bitron.ch>2018-01-31 15:48:15 +0100
commit8890142147a6f3a460a0f7a0690996a9c6b48137 (patch)
treedac7d0f6c4673c02d132132f4e530162841ffab5
parent4304611452a9ba8f461e302d2852c54023356826 (diff)
downloadbuildstream-8890142147a6f3a460a0f7a0690996a9c6b48137.tar.gz
Get version number w/o pkg_resources
This removes most of the usages of pkg_resources from the codebase, helping the goal of getting rid of that completely. With this change, version number is generated during install and embedded into `__version__` which is then imported by root level `__init__`. From there, it is used by other parts of the codebase when needed. Generated `__version__` file is ignored and not tracked by git to prevent unnecessary 'changes' messages and accidental commits of that file.
-rw-r--r--.gitignore3
-rw-r--r--buildstream/__init__.py1
-rw-r--r--buildstream/_frontend/main.py5
-rw-r--r--buildstream/_frontend/widget.py5
-rw-r--r--buildstream/utils.py5
-rwxr-xr-xsetup.py11
6 files changed, 19 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index b99e24897..1bfb5c411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,6 @@ tmp
# Integration test results
/integration-tests/*results/
+
+# Generated version file
+buildstream/__version__.py \ No newline at end of file
diff --git a/buildstream/__init__.py b/buildstream/__init__.py
index cf13655fa..733350bdd 100644
--- a/buildstream/__init__.py
+++ b/buildstream/__init__.py
@@ -19,6 +19,7 @@
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
# Plugin author facing APIs
+from .__version__ import __version__
from .utils import UtilError, ProgramNotFoundError
from .sandbox import Sandbox, SandboxFlags
from .plugin import Plugin
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py
index 5944a49ac..b2bf493ff 100644
--- a/buildstream/_frontend/main.py
+++ b/buildstream/_frontend/main.py
@@ -20,7 +20,6 @@
import os
import sys
import click
-import pkg_resources # From setuptools
from contextlib import contextmanager
from blessings import Terminal
from click import UsageError
@@ -37,14 +36,12 @@ from .._pipeline import Pipeline, PipelineError
from .._scheduler import Scheduler
from .._profile import Topics, profile_start, profile_end
from .. import _yaml
+from .. import __version__ as build_stream_version
# Import frontend assets
from . import Profile, LogLine, Status
from .complete import main_bashcomplete, complete_path, CompleteUnhandled
-# Some globals resolved for default arguments in the cli
-build_stream_version = pkg_resources.require("buildstream")[0].version
-
# Intendation for all logging
INDENT = 4
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py
index 1dccd0059..d61f338df 100644
--- a/buildstream/_frontend/widget.py
+++ b/buildstream/_frontend/widget.py
@@ -24,12 +24,12 @@ from contextlib import ExitStack
from mmap import mmap
import click
-import pkg_resources
from ruamel import yaml
from . import Profile
from .. import Element, Scope, Consistency
from .. import _yaml
+from .. import __version__ as bst_version
from .._exceptions import ImplError
from .._message import MessageType
from ..plugin import _plugin_lookup
@@ -432,12 +432,11 @@ class LogLine(Widget):
context = pipeline.context
project = pipeline.project
starttime = datetime.datetime.now()
- bst = pkg_resources.require("buildstream")[0]
text = ''
# Main invocation context
text += '\n'
- text += self.content_profile.fmt("BuildStream Version {}\n".format(bst.version), bold=True)
+ text += self.content_profile.fmt("BuildStream Version {}\n".format(bst_version), bold=True)
values = OrderedDict()
values["Session Start"] = starttime.strftime('%A, %d-%m-%Y at %H:%M:%S')
values["Project"] = "{} ({})".format(project.name, project.directory)
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 3a13dea6c..da67f9c10 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -36,9 +36,9 @@ import tempfile
import itertools
from contextlib import contextmanager
-import pkg_resources
import psutil
+from . import __version__
from . import _signals
from ._exceptions import BstError, ErrorDomain
@@ -455,8 +455,7 @@ def get_bst_version():
(int): The major version
(int): The minor version
"""
- package = pkg_resources.require("buildstream")[0]
- versions = package.version.split('.')[:2]
+ versions = __version__.split('.')[:2]
return (int(versions[0]), int(versions[1]))
diff --git a/setup.py b/setup.py
index 3e9f88545..01b834bd9 100755
--- a/setup.py
+++ b/setup.py
@@ -133,6 +133,12 @@ if not os.environ.get('BST_ARTIFACTS_ONLY', ''):
'bst = buildstream._frontend:cli'
]
+_version_template = """\
+# coding: utf-8
+# file generated by setuptools_scm
+# don't change, don't track in version control
+__version__ = {version!r}
+"""
#####################################################
# Monkey-patching setuptools for performance #
@@ -176,7 +182,10 @@ ScriptWriter.get_args = get_args
setup(name='BuildStream',
description='A framework for modelling build pipelines in YAML',
license='LGPL',
- use_scm_version=True,
+ use_scm_version={
+ 'write_to': "buildstream/__version__.py",
+ 'write_to_template': _version_template,
+ },
packages=find_packages(),
package_data={'buildstream': ['plugins/*/*.py', 'plugins/*/*.yaml',
'data/*.yaml', 'data/*.sh.in']},