]> jfr.im git - yt-dlp.git/commitdiff
[build] Add `default` optional dependency group (#9295)
authorbashonly <redacted>
Mon, 4 Mar 2024 23:19:37 +0000 (17:19 -0600)
committerGitHub <redacted>
Mon, 4 Mar 2024 23:19:37 +0000 (23:19 +0000)
Authored by: bashonly, Grub4K

Co-authored-by: Simon Sawicki <redacted>
README.md
devscripts/install_deps.py
pyproject.toml

index 7e31e6560656f32b8588ce6df046b112b97f29c7..3f92a813666d96413691e63191ddcbe311de999a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -218,7 +218,7 @@ # To update to nightly from stable executable/binary:
 yt-dlp --update-to nightly
 
 # To install nightly with pip:
-python -m pip install -U --pre yt-dlp
+python -m pip install -U --pre yt-dlp[default]
 ```
 
 <!-- MANPAGE: BEGIN EXCLUDED SECTION -->
index 715e5b044049c6d5e75f9f62ab14970dd7a3ed24..889d9abeb7163a36c22766c1a906f9cf8338d551 100755 (executable)
@@ -19,7 +19,7 @@ def parse_args():
     parser.add_argument(
         'input', nargs='?', metavar='TOMLFILE', default='pyproject.toml', help='Input file (default: %(default)s)')
     parser.add_argument(
-        '-e', '--exclude', metavar='REQUIREMENT', action='append', help='Exclude a required dependency')
+        '-e', '--exclude', metavar='DEPENDENCY', action='append', help='Exclude a dependency')
     parser.add_argument(
         '-i', '--include', metavar='GROUP', action='append', help='Include an optional dependency group')
     parser.add_argument(
@@ -33,21 +33,28 @@ def parse_args():
 
 def main():
     args = parse_args()
-    toml_data = parse_toml(read_file(args.input))
-    deps = toml_data['project']['dependencies']
-    targets = deps.copy() if not args.only_optional else []
-
-    for exclude in args.exclude or []:
-        for dep in deps:
-            simplified_dep = re.match(r'[\w-]+', dep)[0]
-            if dep in targets and (exclude.lower() == simplified_dep.lower() or exclude == dep):
-                targets.remove(dep)
-
-    optional_deps = toml_data['project']['optional-dependencies']
-    for include in args.include or []:
-        group = optional_deps.get(include)
-        if group:
-            targets.extend(group)
+    project_table = parse_toml(read_file(args.input))['project']
+    optional_groups = project_table['optional-dependencies']
+    excludes = args.exclude or []
+
+    deps = []
+    if not args.only_optional:  # `-o` should exclude 'dependencies' and the 'default' group
+        deps.extend(project_table['dependencies'])
+        if 'default' not in excludes:  # `--exclude default` should exclude entire 'default' group
+            deps.extend(optional_groups['default'])
+
+    def name(dependency):
+        return re.match(r'[\w-]+', dependency)[0].lower()
+
+    target_map = {name(dep): dep for dep in deps}
+
+    for include in filter(None, map(optional_groups.get, args.include or [])):
+        target_map.update(zip(map(name, include), include))
+
+    for exclude in map(name, excludes):
+        target_map.pop(exclude, None)
+
+    targets = list(target_map.values())
 
     if args.print:
         for target in targets:
index 0c9c5fc0169193354d06d356882f81b40637c4aa..dda43288fc6cb3411bf0901a53a1e32019168b1f 100644 (file)
@@ -51,6 +51,7 @@ dependencies = [
 ]
 
 [project.optional-dependencies]
+default = []
 secretstorage = [
     "cffi",
     "secretstorage",