leandron commented on a change in pull request #6757:
URL: https://github.com/apache/incubator-tvm/pull/6757#discussion_r511804150
##########
File path: version.py
##########
@@ -27,14 +27,69 @@
"""
import os
import re
+import argparse
+import logging
+import subprocess
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.8.dev0"
+# most recent tag, used for git describe validation
+__most_recent_tag__ = "v0.7.0"
+
+
+def py_str(cstr):
+ return cstr.decode("utf-8")
+
+
+def git_describe_version():
+ """Get the suffix by git describe.
+
+ Returns
+ -------
+ pub_ver: str
+ Public version.
+
+ local_ver: str
+ Local version(with additional label).
+ """
Review comment:
I suggest this docstring to be expanded a bit, with an example of what
is the expected tag format and how the version increment is made, so that
people know how to tag versions before generating packages.
##########
File path: version.py
##########
@@ -27,14 +27,69 @@
"""
import os
import re
+import argparse
+import logging
+import subprocess
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.8.dev0"
+# most recent tag, used for git describe validation
+__most_recent_tag__ = "v0.7.0"
+
+
+def py_str(cstr):
+ return cstr.decode("utf-8")
+
+
+def git_describe_version():
+ """Get the suffix by git describe.
+
+ Returns
+ -------
+ pub_ver: str
+ Public version.
+
+ local_ver: str
+ Local version(with additional label).
+ """
+ cmd = ["git", "describe", "--tags"]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+ (out, _) = proc.communicate()
+
+ if proc.returncode != 0:
+ msg = py_str(out)
+ if msg.find("not a git repository") != -1:
+ return __version__, __version__
+ logging.warning("git describ error: %", msg)
+ return __version__, __version__
+ describe = py_str(out).strip()
+ arr_info = describe.split("-")
+
+ if not arr_info[0].endswith(__most_recent_tag__):
+ logging.warning("%s does not match most recent tag %s", describe,
__most_recent_tag__)
+ return __version__, __version__
+
+ if arr_info[0].startswith("v"):
+ arr_info[0] = arr_info[0][1:]
Review comment:
Given the previous validation on line 70, I think this checking here
will always be true and maybe could be removed?
##########
File path: version.py
##########
@@ -46,41 +101,79 @@ def update(file_name, pattern, repl):
if result[0] != repl:
l = re.sub(pattern, repl, l)
need_update = True
- print("%s: %s->%s" % (file_name, result[0], repl))
+ print("%s: %s -> %s" % (file_name, result[0], repl))
else:
print("%s: version is already %s" % (file_name, repl))
update.append(l)
if hit_counter != 1:
raise RuntimeError("Cannot find version in %s" % file_name)
- if need_update:
+ if need_update and not dry_run:
with open(file_name, "w") as output_file:
for l in update:
output_file.write(l)
-def main():
+def sync_version(pub_ver, local_ver, dry_run):
+ """Synchronize version."""
proj_root = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
- # python path
+
+ # python uses the PEP440: local version
update(
os.path.join(proj_root, "python", "tvm", "_ffi", "libinfo.py"),
- r"(?<=__version__ = \")[.0-9a-z]+",
- __version__,
+ r"(?<=__version__ = \")[.0-9a-z\+]+",
+ local_ver,
+ dry_run,
)
+ # Use public version for other parts for now
+ # Note that full git hash is already available in libtvm
# C++ header
update(
os.path.join(proj_root, "include", "tvm", "runtime",
"c_runtime_api.h"),
- '(?<=TVM_VERSION ")[.0-9a-z]+',
- __version__,
+ r'(?<=TVM_VERSION ")[.0-9a-z\+]+',
+ pub_ver,
+ dry_run,
)
# conda
- for path in ["recipe"]:
- update(
- os.path.join(proj_root, "conda", path, "meta.yaml"),
- "(?<=version = ')[.0-9a-z]+",
- __version__,
- )
+ update(
+ os.path.join(proj_root, "conda", "recipe", "meta.yaml"),
+ r"(?<=version = ')[.0-9a-z\+]+",
+ pub_ver,
+ dry_run,
+ )
+ # web
+ dev_pos = pub_ver.find(".dev")
+ npm_ver = pub_ver if dev_pos == -1 else "%s.0-%s" % (pub_ver[:dev_pos],
pub_ver[dev_pos + 1 :])
+ update(
+ os.path.join(proj_root, "web", "package.json"),
+ r'(?<="version": ")[.0-9a-z\+]+',
+ npm_ver,
+ dry_run,
+ )
+
+
+def main():
+ logging.basicConfig(level=logging.INFO)
+ parser = argparse.ArgumentParser(description="Detect and sychnronize
version.")
+ parser.add_argument(
+ "--print-version", action="store_true", help="Print version to the
command line."
Review comment:
In this case, no files are modified. I suggest making that explicit on
the `help`.
##########
File path: version.py
##########
@@ -27,14 +27,69 @@
"""
import os
import re
+import argparse
+import logging
+import subprocess
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.8.dev0"
+# most recent tag, used for git describe validation
+__most_recent_tag__ = "v0.7.0"
+
+
+def py_str(cstr):
+ return cstr.decode("utf-8")
+
+
+def git_describe_version():
+ """Get the suffix by git describe.
+
+ Returns
+ -------
+ pub_ver: str
+ Public version.
+
+ local_ver: str
+ Local version(with additional label).
+ """
+ cmd = ["git", "describe", "--tags"]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+ (out, _) = proc.communicate()
+
+ if proc.returncode != 0:
+ msg = py_str(out)
+ if msg.find("not a git repository") != -1:
+ return __version__, __version__
+ logging.warning("git describ error: %", msg)
Review comment:
```suggestion
logging.warning("git describe error: %", msg)
```
##########
File path: version.py
##########
@@ -27,14 +27,69 @@
"""
import os
import re
+import argparse
+import logging
+import subprocess
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.8.dev0"
+# most recent tag, used for git describe validation
+__most_recent_tag__ = "v0.7.0"
Review comment:
minor suggestion: given `__version__` and `__most_recent_tag__` are
constants, wouldn't make sense to spell them as `VERSION` and `MOST_RECENT_TAG`
instead?
##########
File path: version.py
##########
@@ -27,14 +27,69 @@
"""
import os
import re
+import argparse
+import logging
+import subprocess
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.8.dev0"
+# most recent tag, used for git describe validation
+__most_recent_tag__ = "v0.7.0"
+
+
+def py_str(cstr):
+ return cstr.decode("utf-8")
+
+
+def git_describe_version():
+ """Get the suffix by git describe.
+
+ Returns
+ -------
+ pub_ver: str
+ Public version.
+
+ local_ver: str
+ Local version(with additional label).
+ """
+ cmd = ["git", "describe", "--tags"]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+ (out, _) = proc.communicate()
+
+ if proc.returncode != 0:
+ msg = py_str(out)
+ if msg.find("not a git repository") != -1:
+ return __version__, __version__
+ logging.warning("git describ error: %", msg)
+ return __version__, __version__
+ describe = py_str(out).strip()
+ arr_info = describe.split("-")
+
+ if not arr_info[0].endswith(__most_recent_tag__):
+ logging.warning("%s does not match most recent tag %s", describe,
__most_recent_tag__)
Review comment:
My understanding is that in this case we'll use `__version__` as a
fallback. Maybe that should be clear on the warning?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]