Skip to content

Use entry_points console_scripts  #48

Closed

Description

@BastianZim

Hi,

I was wondering if it might make sense to switch from scripts to entry_points console_scripts in setup.py. This is the more modern and preferred approach and recommended by PyPA nowadays.

Example:

entry_points={
    'console_scripts': [
        'sample=sample:main',
    ],
},

Guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/#scripts

Ref:

Activity

  1. DutytoDevelop commented on Dec 16, 2021

    @DutytoDevelop

    Holy moly, you had the exact same idea as me! I added platform-specific logic in order to detect the Windows 10 operating system and then use the entry_points console_scripts logic to allow setup.py to compile a Windows executable to the Scripts directory. This fixes the issue with Windows users having to install 3rd party programs that support running bash scripts since the bin/openai file is exactly that.

    Platform-specific logic isn't necessarily needed, however I figured we'd leave the Linux / Mac implementation unchanged for the time being. Here's my code:

    --

    import os
    import sys
    from setuptools import find_packages, setup
    
    version_contents = {}
    version_path = os.path.join(
        os.path.abspath(os.path.dirname(__file__)), "openai/version.py"
    )
    with open(version_path, "rt") as f:
        exec(f.read(), version_contents)
    
    if sys.platform == 'win32':
        # https://stackoverflow.com/questions/51785602/is-possible-to-install-a-module-and-a-wrapper-script-using-pip-at-once
        # Windows users: Include 'entry_points' in setup() but we exclude "bin/openai"
        entry_points = {
            'console_scripts' : [ 'openai = openai.openai_cli_tool:main' ]
        }
        scripts = []
    else:
        # Linux and macOS users: No 'entry_points' needed in setup() but we include "bin/openai"
        entry_points = {}
        scripts = ["bin/openai"]
    
    setup(
        name="openai",
        description="Python client library for the OpenAI API",
        version=version_contents["VERSION"],
        install_requires=[
            "requests>=2.20",  # to get the patch for CVE-2018-18074
            "tqdm",  # Needed for progress bars
            "pandas>=1.2.3",  # Needed for CLI fine-tuning data preparation tool
            "pandas-stubs>=1.1.0.11",  # Needed for type hints for mypy
            "openpyxl>=3.0.7",  # Needed for CLI fine-tuning data preparation tool xlsx format
        ],
        extras_require={"dev": ["black~=21.6b0", "pytest==6.*"]},
        python_requires=">=3.7.1",
        scripts=scripts,
        entry_points=entry_points,
        packages=find_packages(exclude=["tests", "tests.*"]),
        package_data={
            "openai": [
                "data/ca-certificates.crt",
                "py.typed",
            ]
        },
        author="OpenAI",
        author_email="support@openai.com",
        url="https://github.com/openai/openai-python",
    )
    
  2. BastianZim commented on Dec 17, 2021

    @BastianZim
    ContributorAuthor

    Haha that's great to hear!

    Since one of the key points of entry_points is cross platform support I wouldn't exclude it for a particular platform (and it'S much more modern anyways) but I have #52 so the maintainers from here can weigh in and then we can adapt accordingly.

  3. added a commit that references this issue on Mar 20, 2024
  4. added a commit that references this issue on Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions