]> jfr.im git - yt-dlp.git/commitdiff
[build, devscripts] Add devscript to set a build variant
authorpukkandan <redacted>
Fri, 29 Jul 2022 15:03:01 +0000 (20:33 +0530)
committerpukkandan <redacted>
Mon, 8 Aug 2022 19:38:48 +0000 (01:08 +0530)
Closes #4471

.github/workflows/build.yml
README.md
devscripts/make_readme.py
devscripts/set-variant.py [new file with mode: 0644]
devscripts/update-version.py
yt_dlp/YoutubeDL.py
yt_dlp/options.py
yt_dlp/update.py
yt_dlp/version.py

index f3cc9930d5a4f5d36c16937a34ec9c839648027f..bd343d95d35afa0072c785554fc71072478e5f0f 100644 (file)
@@ -89,6 +89,7 @@ jobs:
       if: "env.TWINE_PASSWORD != ''"
       run: |
         rm -rf dist/*
+        python devscripts/set-variant.py pip -M "You installed yt-dlp with pip or using the wheel from PyPi; Use that to update"
         python setup.py sdist bdist_wheel
         twine upload dist/*
 
index 0a6dd53d736e396091b32b75b61076542870b04c..e38c6981a9eea56cd669517dd309dad646cb4080 100644 (file)
--- a/README.md
+++ b/README.md
@@ -343,7 +343,8 @@ ### Standalone Py2Exe Builds (Windows)
 
 ### Related scripts
 
-* **`devscripts/update-version.py`** - Update the version number based on current timestamp
+* **`devscripts/update-version.py [revision]`** - Update the version number based on current date
+* **`devscripts/set-variant.py variant [-M update_message]`** - Set the build variant of the executable
 * **`devscripts/make_lazy_extractors.py`** - Create lazy extractors. Running this before building the binaries (any variant) will improve their startup performance. Set the environment variable `YTDLP_NO_LAZY_EXTRACTORS=1` if you wish to forcefully disable lazy extractor loading.
 
 You can also fork the project on github and run your fork's [build workflow](.github/workflows/build.yml) to automatically build a full release
@@ -360,8 +361,8 @@ # USAGE AND OPTIONS
 ## General Options:
     -h, --help                      Print this help text and exit
     --version                       Print program version and exit
-    -U, --update                    Update this program to latest version
-    --no-update                     Do not update (default)
+    -U, --update                    Update this program to the latest version
+    --no-update                     Do not check for updates (default)
     -i, --ignore-errors             Ignore download and postprocessing errors.
                                     The download will be considered successful
                                     even if the postprocessing fails
index 767ea5409f642e138ab7f4e35dac41ea034c9bc8..fad993a199d29a749ad4a281c6fd164cad3e71ca 100755 (executable)
@@ -45,6 +45,10 @@ def apply_patch(text, patch):
 delim = f'\n{" " * switch_col_width}'
 
 PATCHES = (
+    (   # Standardize update message
+        r'(?m)^(    -U, --update\s+).+(\n    \s.+)*$',
+        r'\1Update this program to the latest version',
+    ),
     (  # Headings
         r'(?m)^  (\w.+\n)(    (?=\w))?',
         r'## \1'
diff --git a/devscripts/set-variant.py b/devscripts/set-variant.py
new file mode 100644 (file)
index 0000000..10341e7
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+# Allow direct execution
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+
+import argparse
+import functools
+import re
+
+from devscripts.utils import compose_functions, read_file, write_file
+
+VERSION_FILE = 'yt_dlp/version.py'
+
+
+def parse_options():
+    parser = argparse.ArgumentParser(description='Set the build variant of the package')
+    parser.add_argument('variant', help='Name of the variant')
+    parser.add_argument('-M', '--update-message', default=None, help='Message to show in -U')
+    return parser.parse_args()
+
+
+def property_setter(name, value):
+    return functools.partial(re.sub, rf'(?m)^{name}\s*=\s*.+$', f'{name} = {value!r}')
+
+
+opts = parse_options()
+transform = compose_functions(
+    property_setter('VARIANT', opts.variant),
+    property_setter('UPDATE_HINT', opts.update_message)
+)
+
+write_file(VERSION_FILE, transform(read_file(VERSION_FILE)))
index c55dd371c5196ab1c06085cb664b78912bb37712..caebf42414eb8be4983f7557265eff482605e117 100644 (file)
@@ -43,6 +43,10 @@ def get_git_head():
 __version__ = {VERSION!r}
 
 RELEASE_GIT_HEAD = {GIT_HEAD!r}
+
+VARIANT = None
+
+UPDATE_HINT = None
 '''
 
 write_file('yt_dlp/version.py', VERSION_FILE)
index ded34b8edcb6d8e9ddbbedf91894a33ce4b1d2f9..228aa7bf5e2d8f2b400cacc192a7fabba2c31181 100644 (file)
     write_json_file,
     write_string,
 )
-from .version import RELEASE_GIT_HEAD, __version__
+from .version import RELEASE_GIT_HEAD, VARIANT, __version__
 
 if compat_os_name == 'nt':
     import ctypes
@@ -3676,6 +3676,8 @@ def get_encoding(stream):
             write_debug = lambda msg: self._write_string(f'[debug] {msg}\n')
 
         source = detect_variant()
+        if VARIANT not in (None, 'pip'):
+            source += '*'
         write_debug(join_nonempty(
             'yt-dlp version', __version__,
             f'[{RELEASE_GIT_HEAD}]' if RELEASE_GIT_HEAD else '',
index b70f5798e304ba3a2445bd360acfbbf91b08f269..2c7f686ddeb6be1b8cc5a1c4aa3ed79444444046 100644 (file)
     SponsorBlockPP,
 )
 from .postprocessor.modify_chapters import DEFAULT_SPONSORBLOCK_CHAPTER_TITLE
-from .update import detect_variant
+from .update import detect_variant, is_non_updateable
 from .utils import (
     OUTTMPL_TYPES,
     POSTPROCESS_WHEN,
     Config,
     expand_path,
+    format_field,
     get_executable_path,
     join_nonempty,
     remove_end,
@@ -333,11 +334,13 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
     general.add_option(
         '-U', '--update',
         action='store_true', dest='update_self',
-        help='Update this program to latest version')
+        help=format_field(
+            is_non_updateable(), None, 'Check if updates are available. %s',
+            default='Update this program to the latest version'))
     general.add_option(
         '--no-update',
         action='store_false', dest='update_self',
-        help='Do not update (default)')
+        help='Do not check for updates (default)')
     general.add_option(
         '-i', '--ignore-errors',
         action='store_true', dest='ignoreerrors',
index 92c07acc1401738d6f91c327a729874d5a0c399d..a04518c9b643fda11da4db0f68078b116ff2203c 100644 (file)
@@ -18,7 +18,7 @@
     traverse_obj,
     version_tuple,
 )
-from .version import __version__
+from .version import UPDATE_HINT, VARIANT, __version__
 
 REPOSITORY = 'yt-dlp/yt-dlp'
 API_URL = f'https://api.github.com/repos/{REPOSITORY}/releases'
@@ -47,7 +47,7 @@ def _get_variant_and_executable_path():
 
 
 def detect_variant():
-    return _get_variant_and_executable_path()[0]
+    return VARIANT or _get_variant_and_executable_path()[0]
 
 
 _FILE_SUFFIXES = {
@@ -64,13 +64,16 @@ def detect_variant():
     **{variant: f'Auto-update is not supported for unpackaged {name} executable; Re-download the latest release'
        for variant, name in {'win32_dir': 'Windows', 'darwin_dir': 'MacOS', 'linux_dir': 'Linux'}.items()},
     'source': 'You cannot update when running from source code; Use git to pull the latest changes',
-    'unknown': 'It looks like you installed yt-dlp with a package manager, pip or setup.py; Use that to update',
-    'other': 'It looks like you are using an unofficial build of yt-dlp; Build the executable again',
+    'unknown': 'You installed yt-dlp with a package manager or setup.py; Use that to update',
+    'other': 'You are using an unofficial build of yt-dlp; Build the executable again',
 }
 
 
 def is_non_updateable():
-    return _NON_UPDATEABLE_REASONS.get(detect_variant(), _NON_UPDATEABLE_REASONS['other'])
+    if UPDATE_HINT:
+        return UPDATE_HINT
+    return _NON_UPDATEABLE_REASONS.get(
+        detect_variant(), _NON_UPDATEABLE_REASONS['unknown' if VARIANT else 'other'])
 
 
 def _sha256_file(path):
index a1a5880e9524c19aae043a58c31851455b7f0a87..75ede4973c3ea1c99a2f4de7ef69cff2b0b07349 100644 (file)
@@ -3,3 +3,7 @@
 __version__ = '2022.07.18'
 
 RELEASE_GIT_HEAD = '135f05ef6'
+
+VARIANT = None
+
+UPDATE_HINT = None