Skip to content

Commit

Permalink
version.py: make function names more clear (#23216)
Browse files Browse the repository at this point in the history
* rename a few version functions

* and is_prebuilt

* and some formatting 😊
  • Loading branch information
sshane committed Dec 14, 2021
1 parent 084ef39 commit b745a14
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions selfdrive/athena/manage_athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from common.params import Params
from selfdrive.manager.process import launcher
from selfdrive.swaglog import cloudlog
from selfdrive.version import get_version, get_dirty
from selfdrive.version import get_version, is_dirty

ATHENA_MGR_PID_PARAM = "AthenadPid"


def main():
params = Params()
dongle_id = params.get("DongleId").decode('utf-8')
cloudlog.bind_global(dongle_id=dongle_id, version=get_version(), dirty=get_dirty())
cloudlog.bind_global(dongle_id=dongle_id, version=get_version(), dirty=is_dirty())

try:
while 1:
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from common.params import Params
from common.basedir import BASEDIR
from selfdrive.version import get_comma_remote, get_tested_branch
from selfdrive.version import is_comma_remote, is_tested_branch
from selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars
from selfdrive.car.vin import get_vin, VIN_UNKNOWN
from selfdrive.car.fw_versions import get_fw_versions, match_fw_to_car
Expand All @@ -14,7 +14,7 @@


def get_startup_event(car_recognized, controller_available, fw_seen):
if get_comma_remote() and get_tested_branch():
if is_comma_remote() and is_tested_branch():
event = EventName.startup
else:
event = EventName.startupMaster
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/manager/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from common.text_window import TextWindow
from selfdrive.hardware import TICI
from selfdrive.swaglog import cloudlog, add_file_handler
from selfdrive.version import get_dirty
from selfdrive.version import is_dirty

MAX_CACHE_SIZE = 4e9 if "CI" in os.environ else 2e9
CACHE_DIR = Path("/data/scons_cache" if TICI else "/tmp/scons_cache")
Expand Down Expand Up @@ -98,4 +98,4 @@ def build(spinner, dirty=False):
if __name__ == "__main__" and not PREBUILT:
spinner = Spinner()
spinner.update_progress(0, 100)
build(spinner, get_dirty())
build(spinner, is_dirty())
12 changes: 6 additions & 6 deletions selfdrive/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from selfdrive.manager.process_config import managed_processes
from selfdrive.athena.registration import register, UNREGISTERED_DONGLE_ID
from selfdrive.swaglog import cloudlog, add_file_handler
from selfdrive.version import get_dirty, get_commit, get_version, get_origin, get_short_branch, \
terms_version, training_version, get_comma_remote
from selfdrive.version import is_dirty, get_commit, get_version, get_origin, get_short_branch, \
terms_version, training_version, is_comma_remote


sys.path.append(os.path.join(BASEDIR, "pyextra"))
Expand Down Expand Up @@ -86,16 +86,16 @@ def manager_init():
raise Exception(f"Registration failed for device {serial}")
os.environ['DONGLE_ID'] = dongle_id # Needed for swaglog

if not get_dirty():
if not is_dirty():
os.environ['CLEAN'] = '1'

cloudlog.bind_global(dongle_id=dongle_id, version=get_version(), dirty=get_dirty(),
cloudlog.bind_global(dongle_id=dongle_id, version=get_version(), dirty=is_dirty(),
device=HARDWARE.get_device_type())

if get_comma_remote() and not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
if is_comma_remote() and not (os.getenv("NOLOG") or os.getenv("NOCRASH") or PC):
crash.init()
crash.bind_user(id=dongle_id)
crash.bind_extra(dirty=get_dirty(), origin=get_origin(), branch=get_short_branch(), commit=get_commit(),
crash.bind_extra(dirty=is_dirty(), origin=get_origin(), branch=get_short_branch(), commit=get_commit(),
device=HARDWARE.get_device_type())


Expand Down
4 changes: 2 additions & 2 deletions selfdrive/tombstoned.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from selfdrive.hardware import TICI, HARDWARE
from selfdrive.loggerd.config import ROOT
from selfdrive.swaglog import cloudlog
from selfdrive.version import get_branch, get_commit, get_dirty, get_origin, get_version
from selfdrive.version import get_branch, get_commit, is_dirty, get_origin, get_version

MAX_SIZE = 100000 * 10 # mal size is 40-100k, allow up to 1M
if TICI:
Expand Down Expand Up @@ -207,7 +207,7 @@ def main():

dongle_id = Params().get("DongleId", encoding='utf-8')
sentry_sdk.set_user({"id": dongle_id})
sentry_sdk.set_tag("dirty", get_dirty())
sentry_sdk.set_tag("dirty", is_dirty())
sentry_sdk.set_tag("origin", get_origin())
sentry_sdk.set_tag("branch", get_branch())
sentry_sdk.set_tag("commit", get_commit())
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from selfdrive.hardware import EON, TICI, HARDWARE
from selfdrive.swaglog import cloudlog
from selfdrive.controls.lib.alertmanager import set_offroad_alert
from selfdrive.version import get_tested_branch
from selfdrive.version import is_tested_branch

LOCK_FILE = os.getenv("UPDATER_LOCK_FILE", "/tmp/safe_staging_overlay.lock")
STAGING_ROOT = os.getenv("UPDATER_STAGING_ROOT", "/data/safe_staging")
Expand Down Expand Up @@ -142,7 +142,7 @@ def set_params(new_version: bool, failed_count: int, exception: Optional[str]) -
now = datetime.datetime.utcnow()
dt = now - last_update
if failed_count > 15 and exception is not None:
if get_tested_branch():
if is_tested_branch():
extra_text = "Ensure the software is correctly installed"
else:
extra_text = exception
Expand Down
21 changes: 10 additions & 11 deletions selfdrive/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from common.basedir import BASEDIR
from selfdrive.swaglog import cloudlog


TESTED_BRANCHES = ['devel', 'release2-staging', 'release3-staging', 'dashcam-staging', 'release2', 'release3', 'dashcam']

training_version: bytes = b"0.2.0"
Expand Down Expand Up @@ -62,12 +61,12 @@ def get_version() -> str:


@cache
def get_prebuilt() -> bool:
def is_prebuilt() -> bool:
return os.path.exists(os.path.join(BASEDIR, 'prebuilt'))


@cache
def get_comma_remote() -> bool:
def is_comma_remote() -> bool:
origin = get_origin()
if origin is None:
return False
Expand All @@ -76,12 +75,12 @@ def get_comma_remote() -> bool:


@cache
def get_tested_branch() -> bool:
def is_tested_branch() -> bool:
return get_short_branch() in TESTED_BRANCHES


@cache
def get_dirty() -> bool:
def is_dirty() -> bool:
origin = get_origin()
branch = get_branch()
if (origin is None) or (branch is None):
Expand All @@ -90,7 +89,7 @@ def get_dirty() -> bool:
dirty = False
try:
# Actually check dirty files
if not get_prebuilt():
if not is_prebuilt():
# This is needed otherwise touched files might show up as modified
try:
subprocess.check_call(["git", "update-index", "--refresh"])
Expand All @@ -100,15 +99,15 @@ def get_dirty() -> bool:
dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"]) != 0)

# Log dirty files
if dirty and get_comma_remote():
if dirty and is_comma_remote():
try:
dirty_files = run_cmd(["git", "diff-index", branch, "--"])
cloudlog.event("dirty comma branch", version=get_version(), dirty=dirty, origin=origin, branch=branch,
dirty_files=dirty_files, commit=get_commit(), origin_commit=get_commit(branch))
dirty_files=dirty_files, commit=get_commit(), origin_commit=get_commit(branch))
except subprocess.CalledProcessError:
pass

dirty = dirty or (not get_comma_remote())
dirty = dirty or (not is_comma_remote())
dirty = dirty or ('master' in branch)

except subprocess.CalledProcessError:
Expand All @@ -125,9 +124,9 @@ def get_dirty() -> bool:
params.put("TermsVersion", terms_version)
params.put("TrainingVersion", training_version)

print("Dirty: %s" % get_dirty())
print("Dirty: %s" % is_dirty())
print("Version: %s" % get_version())
print("Origin: %s" % get_origin())
print("Branch: %s" % get_branch())
print("Short branch: %s" % get_short_branch())
print("Prebuilt: %s" % get_prebuilt())
print("Prebuilt: %s" % is_prebuilt())

0 comments on commit b745a14

Please sign in to comment.