Repository: yt-dlp/yt-dlp
File: pyinst.py (Python)

Code before:
    set_version_info(final_file, version)


def parse_options():
    # Compatibility with older arguments
    opts = sys.argv[1:]
    if opts[0:1] in (['32'], ['64']):
        if ARCH != opts[0]:
            raise Exception(f'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
        opts = opts[1:]
    return opts


# Get the version from yt_dlp/version.py without importing the package
def read_version(fname):
    with open(fname, encoding='utf-8') as f:
        exec(compile(f.read(), fname, 'exec'))
        return locals()['__version__']


def exe(onedir):
    """@returns (name, path)"""
    name = '_'.join(filter(None, (
        'yt-dlp',
        {'win32': '', 'darwin': 'macos'}.get(OS_NAME, OS_NAME),
        ('i' in MACHINE and '86' in MACHINE and 'x86') or (MACHINE != 'x86_64' and MACHINE != 'amd64' and MACHINE)
    )))
    return name, ''.join(filter(None, (
        'dist/',
        onedir and f'{name}/',
        name,
        OS_NAME == 'win32' and '.exe'
    )))


def version_to_list(version):
    version_list = version.split('.')
    return list(map(int, version_list)) + [0] * (4 - len(version_list))


def dependency_options():
    # Due to the current implementation, these are auto-detected, but explicitly add them just in case
    dependencies = [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
    excluded_modules = ['test', 'ytdlp_plugins', 'youtube_dl', 'youtube_dlc']

    yield from (f'--hidden-import={module}' for module in dependencies)
    yield '--collect-submodules=websockets'
    yield from (f'--exclude-module={module}' for module in excluded_modules)


def pycryptodome_module():

Review comment (suggestion):
```suggestion
        '' if MACHINE in ('x86_64', 'amd64') else 'x86' if ('i' in MACHINE and '86' in MACHINE) else MACHINE
```
The and syntax is good for short conditions but is unreadable when it's this complex

Code after:
    ]

    print(f'Running PyInstaller with {opts}')
    run_pyinstaller(opts)
    set_version_info(final_file, version)


def parse_options():
    # Compatibility with older arguments
    opts = sys.argv[1:]
    if opts[0:1] in (['32'], ['64']):
        ARCH = platform.architecture()[0][:2]
        if ARCH != opts[0]:
            raise Exception(f'{opts[0]}bit executable cannot be built on a {ARCH}bit system')
        opts = opts[1:]
    return opts


# Get the version from yt_dlp/version.py without importing the package
def read_version(fname):
    with open(fname, encoding='utf-8') as f:
        exec(compile(f.read(), fname, 'exec'))
        return locals()['__version__']


def exe(onedir):
    """@returns (name, path)"""
    name = '_'.join(filter(None, (
        'yt-dlp',
        {'win32': '', 'darwin': 'macos'}.get(OS_NAME, OS_NAME),
        MACHINE
    )))
    return name, ''.join(filter(None, (
        'dist/',
        onedir and f'{name}/',
        name,
        OS_NAME == 'win32' and '.exe'
    )))


def version_to_list(version):
    version_list = version.split('.')
    return list(map(int, version_list)) + [0] * (4 - len(version_list))


def dependency_options():
    # Due to the current implementation, these are auto-detected, but explicitly add them just in case
    dependencies = [pycryptodome_module(), 'mutagen', 'brotli', 'certifi', 'websockets']
    excluded_modules = ['test', 'ytdlp_plugins', 'youtube_dl', 'youtube_dlc']

    yield from (f'--hidden-import={module}' for module in dependencies)