Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use entry_points console_scripts #48

Closed
BastianZim opened this issue Nov 30, 2021 · 2 comments · Fixed by #52
Closed

Use entry_points console_scripts #48

BastianZim opened this issue Nov 30, 2021 · 2 comments · Fixed by #52

Comments

@BastianZim
Copy link
Contributor

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:

@DutytoDevelop
Copy link

DutytoDevelop commented Dec 16, 2021

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",
)

@BastianZim
Copy link
Contributor Author

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.

baseprime pushed a commit to breezerfp/breeze-openai that referenced this issue Mar 20, 2024
* rename snapshot to model in sdk (openai#48)

* updating version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants