Skip to content

Source package version from git #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wrappers/python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ wirepas_messaging/gateway/*pb2*.py

Pipfile
Pipfile.lock
version.py
35 changes: 34 additions & 1 deletion wrappers/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
long_description = f.read()


def custom_scheme():
def custom_version(version):
tag = str(version.tag)
if version.exact:
return tag

# split on rc and compute a pre-release tag for the next patch
tag_components = tag.rsplit("rc")
major, minor, patch = tag_components[0].split(".")
patch = int(patch) + 1
distance = version.distance
tag = f"{major}.{minor}.{patch}.dev{distance}"

return tag

return {
"root": "../..",
"version_scheme": custom_version,
"local_scheme": "no-local-version",
"write_to": "wrappers/python/version.py",
"fallback_version": str(fallback_version["version"]),
}


def get_list_files(root, flist=None):
if flist is None:
flist = list()
Expand Down Expand Up @@ -56,9 +80,18 @@ def get_requirements(*args):
with open(get_absolute_path("./wirepas_messaging/__about__.py")) as f:
exec(f.read(), about)

fallback_version = {}
try:
with open(get_absolute_path("./version.py")) as f:
exec(f.read(), fallback_version)
except FileNotFoundError:
fallback_version["version"] = "0.1.0"


setup(
name=about["__pkg_name__"],
version=about["__version__"],
use_scm_version=custom_scheme,
setup_requires=["setuptools_scm"],
description=about["__description__"],
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
9 changes: 8 additions & 1 deletion wrappers/python/wirepas_messaging/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
See file LICENSE for full license details.
"""

from pkg_resources import get_distribution, DistributionNotFound

__author__ = "Wirepas Ltd"
__author_email__ = "[email protected]"
__classifiers__ = [
Expand All @@ -20,7 +22,6 @@
__pkg_name__ = "wirepas_messaging"
__title__ = "Wirepas Messaging Wrappers"
__url__ = "https://github.com/wirepas/backend-apis/tree/master/wrappers/python"
__version__ = "1.4.0"
__warning_msg__ = """
***********************************************************************
* WARNING:
Expand All @@ -30,3 +31,9 @@
* https://github.com/protocolbuffers/protobuf/tree/master/python
***********************************************************************
"""

try:
__version__ = get_distribution(__pkg_name__).version
except DistributionNotFound:
# package is not installed
pass