Skip to content

Commit 94d8f33

Browse files
committed
Include a file to indicate package manager
Soon we will have RPMs for yo. In that case, the automatic update check should not happen, and "yo version" should direct users to their package manager for updates. Rather than trying to detect at runtime how Yo got installed, let's just include a small file that indicates the package manager. The packaging script can overwrite the file with the correct information, and yo can detect this and efficiently update its behavior. Signed-off-by: Stephen Brennan <[email protected]>
1 parent ee9c773 commit 94d8f33

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"data/yo-tasks/*",
8989
"data/sample.yo.ini",
9090
"data/yo_tasklib.sh",
91+
"data/pkgman",
9192
],
9293
},
9394
)

yo/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from yo.util import latest_yo_version
6363
from yo.util import natural_sort
6464
from yo.util import one
65+
from yo.util import PKGMAN
6566
from yo.util import standardize_name
6667
from yo.util import YoConfig
6768
from yo.util import YoExc
@@ -1276,6 +1277,9 @@ def maybe_check_for_updates(self) -> t.Iterator[None]:
12761277
check and notify users to update, but do so without making any command
12771278
run longer than it would have.
12781279
"""
1280+
if PKGMAN != "pip":
1281+
yield
1282+
return
12791283
# Only check every N hours
12801284
since_last_check = now() - self.last_checked_for_update
12811285
hours = since_last_check.total_seconds() / 3600

yo/data/pkgman

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip

yo/main.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
from yo.util import hasherr
126126
from yo.util import latest_yo_version
127127
from yo.util import natural_sort
128+
from yo.util import PKGMAN
128129
from yo.util import shlex_join
129130
from yo.util import standardize_name
130131
from yo.util import strftime
@@ -145,7 +146,6 @@
145146
DOCUMENTATION_URL = "https://oracle.github.io/yo/"
146147
INITIAL_CONFIG_LINK = REPOSITORY_URL
147148

148-
149149
COMMAND_GROUP_ORDER = [
150150
"Basic Commands",
151151
"Instance Management",
@@ -2652,17 +2652,21 @@ def run(self) -> None:
26522652
print(f"Development & issues: {REPOSITORY_URL}")
26532653
print()
26542654

2655-
latest_ver = latest_yo_version()
2656-
if not latest_ver:
2657-
print("Error loading the latest version!")
2658-
return
2659-
elif latest_ver == ver:
2660-
print("You are up-to-date!")
2661-
return
2662-
print("Latest version: {}.{}.{}".format(*latest_ver))
2663-
print("To update:")
2664-
print(f" {yo.util.UPGRADE_COMMAND}")
2665-
print("Then verify by re-running yo version")
2655+
if PKGMAN == "pip":
2656+
latest_ver = latest_yo_version()
2657+
if not latest_ver:
2658+
print("Error loading the latest version!")
2659+
return
2660+
elif latest_ver == ver:
2661+
print("You are up-to-date!")
2662+
return
2663+
print("Latest version: {}.{}.{}".format(*latest_ver))
2664+
print("To update:")
2665+
print(f" {yo.util.UPGRADE_COMMAND}")
2666+
print("Then verify by re-running yo version")
2667+
else:
2668+
print(f"Yo's installation is managed by {PKGMAN}")
2669+
print("Please use that to find & install updates.")
26662670

26672671

26682672
class VolumeListCmd(YoCmd):

yo/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646

4747
T = t.TypeVar("T")
4848

49+
_PKGMAN_FILE = os.path.join(
50+
os.path.abspath(os.path.dirname(__file__)), "data/pkgman"
51+
)
52+
PKGMAN = (
53+
open(_PKGMAN_FILE).read().strip() if os.path.exists(_PKGMAN_FILE) else "pip"
54+
)
55+
4956

5057
class YoExc(Exception):
5158
pass

0 commit comments

Comments
 (0)