[POT] Fix bug with git (#9604)
* [POT] Fix bug with git * Add UNKNOWN_VERSION constant
This commit is contained in:
1 parent
0166cb8f5c
commit
cde61f2411
2 files changed
+19
-12
No files matched your search
@@ -4,6 +4,8 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
UNKNOWN_VERSION = "unknown version"
|
||||
|
||||
|
||||
def generate_pot_version():
|
||||
"""
|
||||
@@ -11,16 +13,17 @@ def generate_pot_version():
|
||||
custom_{branch_name}_{commit_hash}
|
||||
"""
|
||||
try:
|
||||
branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode()
|
||||
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode()
|
||||
return "custom_{}_{}".format(branch_name, commit_hash)
|
||||
pot_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))
|
||||
branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=pot_dir)
|
||||
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=pot_dir)
|
||||
return "custom_{}_{}".format(branch_name.strip().decode(), commit_hash.strip().decode())
|
||||
except Exception: # pylint:disable=W0703
|
||||
return "unknown version"
|
||||
return UNKNOWN_VERSION
|
||||
|
||||
|
||||
def get_version():
|
||||
version = generate_pot_version()
|
||||
if version == "unknown version":
|
||||
if version == UNKNOWN_VERSION:
|
||||
version_txt = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir, "version.txt")
|
||||
if os.path.isfile(version_txt):
|
||||
with open(version_txt) as f:
|
||||
|
||||
+11
-7
@@ -7,7 +7,7 @@ import sys
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
UNKNOWN_VERSION = "unknown version"
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
with open(os.path.join(here, 'README.md'), 'r') as fh:
|
||||
@@ -16,17 +16,21 @@ with open(os.path.join(here, 'README.md'), 'r') as fh:
|
||||
|
||||
def generate_pot_version():
|
||||
try:
|
||||
branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode()
|
||||
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode()
|
||||
return "custom_{}_{}".format(branch_name, commit_hash)
|
||||
pot_dir = os.path.normpath(os.path.join(here, "openvino", "tools"))
|
||||
branch_name = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=pot_dir)
|
||||
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=pot_dir)
|
||||
return "custom_{}_{}".format(branch_name.strip().decode(), commit_hash.strip().decode())
|
||||
except Exception: # pylint:disable=W0703
|
||||
return "unknown version"
|
||||
return UNKNOWN_VERSION
|
||||
|
||||
|
||||
def get_version():
|
||||
version = generate_pot_version()
|
||||
if version == "unknown version":
|
||||
version_txt = os.path.join(os.path.dirname(os.path.realpath(__file__)), "version.txt")
|
||||
version_txt = os.path.join(os.path.dirname(os.path.realpath(__file__)), "version.txt")
|
||||
if version != UNKNOWN_VERSION:
|
||||
with open(version_txt, 'w') as f:
|
||||
f.write(version + '\n')
|
||||
else:
|
||||
if os.path.isfile(version_txt):
|
||||
with open(version_txt) as f:
|
||||
version = f.readline().replace('\n', '')
|
||||
|
||||
Reference in new issue
Block a user