diazona / setuptools-pyproject-migration

Generate a pyproject.toml file from setuptools
https://setuptools-pyproject-migration.readthedocs.io/en/latest/
MIT License
16 stars 3 forks source link

Support entry points #36

Closed diazona closed 1 year ago

diazona commented 1 year ago

This issue entails adding support for writing the entry-points, gui-scripts, and scripts fields in pyproject.toml when they are defined statically in the setuptools configuration.

sjlongland commented 1 year ago

So… a relatively complex project where I used two kinds of entry point is this little private project… just created the debug/dumpmeta branch which takes the Gist I did earlier, and refines it slightly.

{
    "methods": {
        "get_author": "Stuart Longland VK4MSL",
        "get_author_email": "me@vk4msl.id.au",
        "get_classifiers": [],
        "get_cmdline_options": {},
        "get_command_list": [
            "('build', 'build everything needed to install')",
            "('build_py', '\"build\" pure Python modules (copy to build directory)')",
            "('build_ext', 'build C/C++ extensions (compile/link to build directory)')",
            "('build_clib', 'build C/C++ libraries used by Python extensions')",
            "('build_scripts', '\"build\" scripts (copy and fixup #! line)')",
            "('clean', \"clean up temporary files from 'build' command\")",
            "('install', 'install everything from build directory')",
            "('install_lib', 'install all Python modules (extensions and pure Python)')",
            "('install_headers', 'install C/C++ header files')",
            "('install_scripts', 'install scripts (Python or otherwise)')",
            "('install_data', 'install data files')",
            "('sdist', 'create a source distribution (tarball, zip file, etc.)')",
            "('register', 'register the distribution with the Python package index')",
            "('bdist', 'create a built (binary) distribution')",
            "('bdist_dumb', 'create a \"dumb\" built distribution')",
            "('bdist_rpm', 'create an RPM distribution')",
            "('check', 'perform some checks on the package')",
            "('upload', 'upload binary package to PyPI')",
            "('dumpmeta', '(no description available)')",
            "('pyproject', '(no description available)')",
            "('alias', 'define a shortcut to invoke one or more commands')",
            "('bdist_egg', 'create an \"egg\" distribution')",
            "('develop', \"install package in 'development mode'\")",
            "('dist_info', 'DO NOT CALL DIRECTLY, INTERNAL ONLY: create .dist-info directory')",
            "('easy_install', 'Find/get/install Python packages')",
            "('editable_wheel', 'DO NOT CALL DIRECTLY, INTERNAL ONLY: create PEP 660 editable wheel')",
            "('egg_info', \"create a distribution's .egg-info directory\")",
            "('install_egg_info', 'Install an .egg-info directory for the package')",
            "('rotate', 'delete older distributions, keeping N newest files')",
            "('saveopts', 'save supplied options to setup.cfg or other config file')",
            "('setopt', 'set an option in setup.cfg or another config file')",
            "('test', 'run unit tests after in-place build (deprecated)')",
            "('upload_docs', 'Upload documentation to sites other than PyPi such as devpi')"
        ],
        "get_command_packages": [
            "distutils.command"
        ],
        "get_contact": "Stuart Longland VK4MSL",
        "get_contact_email": "me@vk4msl.id.au",
        "get_description": null,
        "get_download_url": null,
        "get_egg_cache_dir": "./.eggs",
        "get_fullname": "wicenrfidapi-0.2.1",
        "get_keywords": [],
        "get_license": "GPL-2.0-or-later",
        "get_long_description": null,
        "get_maintainer": null,
        "get_maintainer_email": null,
        "get_name": "wicenrfidapi",
        "get_obsoletes": [],
        "get_platforms": null,
        "get_provides": [],
        "get_requires": [
            "amqtt",
            "aiohttp",
            "aiohttp_cors",
            "passlib",
            "argon2_cffi",
            "pytz",
            "PyMySQL",
            "sqlalchemy",
            "pyyaml",
            "iso8601",
            "signalslot"
        ],
        "get_url": "https://gitlab.com/brisbanewicen/rfid-api/",
        "get_version": "0.2.1"
    },
    "properties": {
        "author": 0,
        "author_email": 0,
        "classifiers": 0,
        "cmdclass": {
            "dumpmeta": "<class 'setuptools_pyproject_migration.DumpMetadata'>"
        },
        "command_obj": {
            "dumpmeta": "<setuptools_pyproject_migration.DumpMetadata object at 0x7f576fd435d0>"
        },
        "command_options": {
            "aliases": {},
            "dumpmeta": {},
            "nosetests": {
                "cover_branches": "('setup.cfg', 'true')",
                "cover_erase": "('setup.cfg', 'true')",
                "cover_html": "('setup.cfg', 'true')",
                "cover_html_dir": "('setup.cfg', 'coverage/')",
                "cover_inclusive": "('setup.cfg', 'true')",
                "cover_package": "('setup.cfg', 'wicenrfidapi')",
                "with_coverage": "('setup.cfg', 'true')",
                "with_xunit": "('setup.cfg', 'true')",
                "xunit_file": "('setup.cfg', 'testreports.xml')"
            }
        },
        "command_packages": null,
        "commands": [
            "dumpmeta"
        ],
        "common_usage": "Common commands: (see '--help-commands' for more)\n\n  setup.py build      will build the package underneath 'build/'\n  setup.py install    will install the package\n",
        "contact": 0,
        "contact_email": 0,
        "data_files": null,
        "dependency_links": [],
        "description": 0,
        "display_option_names": [
            "help_commands",
            "name",
            "version",
            "fullname",
            "author",
            "author_email",
            "maintainer",
            "maintainer_email",
            "contact",
            "contact_email",
            "url",
            "license",
            "licence",
            "description",
            "long_description",
            "platforms",
            "classifiers",
            "keywords",
            "provides",
            "requires",
            "obsoletes"
        ],
        "display_options": [
            "('help-commands', None, 'list all available commands')",
            "('name', None, 'print package name')",
            "('version', 'V', 'print package version')",
            "('fullname', None, 'print <package name>-<version>')",
            "('author', None, \"print the author's name\")",
            "('author-email', None, \"print the author's email address\")",
            "('maintainer', None, \"print the maintainer's name\")",
            "('maintainer-email', None, \"print the maintainer's email address\")",
            "('contact', None, \"print the maintainer's name if known, else the author's\")",
            "('contact-email', None, \"print the maintainer's email address if known, else the author's\")",
            "('url', None, 'print the URL for this package')",
            "('license', None, 'print the license of the package')",
            "('licence', None, 'alias for --license')",
            "('description', None, 'print the package description')",
            "('long-description', None, 'print the long package description')",
            "('platforms', None, 'print the list of platforms')",
            "('classifiers', None, 'print the list of classifiers')",
            "('keywords', None, 'print the list of keywords')",
            "('provides', None, 'print the list of packages/modules provided')",
            "('requires', None, 'print the list of packages/modules required')",
            "('obsoletes', None, 'print the list of packages/modules made obsolete')"
        ],
        "dist_files": [],
        "dry_run": 0,
        "eager_resources": null,
        "entry_points": {
            "console_scripts": [
                "wicen-rfid-api=wicenrfidapi.main:main"
            ],
            "wicenrfidapi.amqtt.plugins": [
                "auth_wicen=wicenrfidapi.amqtt.plugins.wicenauth:WICENAuthPlugin",
                "event_logger_plugin=amqtt.plugins.logging:EventLoggerPlugin",
                "packet_logger_plugin=amqtt.plugins.logging:PacketLoggerPlugin",
                "topic_wicen=wicenrfidapi.amqtt.plugins.wicenacl:WICENACLPlugin",
                "msg_wicen=wicenrfidapi.amqtt.plugins.wicenmsg:WICENMessagingPlugin",
                "broker_sys=amqtt.plugins.sys.broker:BrokerSysPlugin"
            ]
        },
        "exclude_package_data": null,
        "ext_modules": null,
        "ext_package": null,
        "extra_path": null,
        "extras_require": {},
        "fullname": 0,
        "global_options": [
            "('verbose', 'v', 'run verbosely (default)', 1)",
            "('quiet', 'q', 'run quietly (turns verbosity off)')",
            "('dry-run', 'n', \"don't actually do anything\")",
            "('help', 'h', 'show detailed help message')",
            "('no-user-cfg', None, 'ignore pydistutils.cfg in your home directory')"
        ],
        "have_run": {
            "dumpmeta": 0
        },
        "headers": null,
        "help": 0,
        "help_commands": 0,
        "include_dirs": null,
        "include_package_data": null,
        "install_requires": [
            "amqtt",
            "aiohttp",
            "aiohttp_cors",
            "passlib",
            "argon2_cffi",
            "pytz",
            "PyMySQL",
            "sqlalchemy",
            "pyyaml",
            "iso8601",
            "signalslot"
        ],
        "keywords": 0,
        "libraries": null,
        "licence": 0,
        "license": 0,
        "long_description": 0,
        "maintainer": 0,
        "maintainer_email": 0,
        "metadata": "<distutils.dist.DistributionMetadata object at 0x7f57704db650>",
        "name": 0,
        "namespace_packages": null,
        "negative_opt": {
            "quiet": "verbose"
        },
        "obsoletes": 0,
        "package_data": {},
        "package_dir": {},
        "packages": [
            "wicenrfidapi",
            "wicenrfidapi.amqtt",
            "wicenrfidapi.amqtt.plugins",
            "wicenrfidapi.db",
            "wicenrfidapi.db.tables",
            "wicenrfidapi.db.types",
            "wicenrfidapi.db.views",
            "wicenrfidapi.util"
        ],
        "password": "",
        "platforms": 0,
        "provides": 0,
        "py_modules": null,
        "python_requires": null,
        "requires": 0,
        "script_args": [
            "dumpmeta"
        ],
        "script_name": "setup.py",
        "scripts": null,
        "setup_requires": [],
        "src_root": null,
        "test_loader": null,
        "test_runner": null,
        "test_suite": null,
        "tests_require": null,
        "url": 0,
        "use_2to3": null,
        "verbose": 1,
        "version": 0,
        "want_user_cfg": true,
        "zip_safe": null
    }
}

This project defines a CLI script, and a couple of "plug-ins" for a MQTT server library. I presume the GUI scripts work much the same way as CLI ones.

{
    "properties": {
        "entry_points": {
            "console_scripts": [
                "wicen-rfid-api=wicenrfidapi.main:main"
            ],
            "wicenrfidapi.amqtt.plugins": [
                "auth_wicen=wicenrfidapi.amqtt.plugins.wicenauth:WICENAuthPlugin",
                "event_logger_plugin=amqtt.plugins.logging:EventLoggerPlugin",
                "packet_logger_plugin=amqtt.plugins.logging:PacketLoggerPlugin",
                "topic_wicen=wicenrfidapi.amqtt.plugins.wicenacl:WICENACLPlugin",
                "msg_wicen=wicenrfidapi.amqtt.plugins.wicenmsg:WICENMessagingPlugin",
                "broker_sys=amqtt.plugins.sys.broker:BrokerSysPlugin"
            ]
        }
    }
}

That at least tells me where the entry points are hiding.

https://setuptools.pypa.io/en/latest/userguide/entry_point.html documents how setuptools expects to find them.

sjlongland commented 1 year ago
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "wicenrfidapi"
version = "0.2.1"
dependencies = ["PyMySQL", "aiohttp", "aiohttp_cors", "amqtt", "argon2_cffi", "iso8601", "passlib", "pytz", "pyyaml", "signalslot", "sqlalchemy"]

[project.scripts]
wicen-rfid-api = "wicenrfidapi.main:main"

[project.entry-points."wicenrfidapi.amqtt.plugins"]
auth_wicen = "wicenrfidapi.amqtt.plugins.wicenauth:WICENAuthPlugin"
event_logger_plugin = "amqtt.plugins.logging:EventLoggerPlugin"
packet_logger_plugin = "amqtt.plugins.logging:PacketLoggerPlugin"
topic_wicen = "wicenrfidapi.amqtt.plugins.wicenacl:WICENACLPlugin"
msg_wicen = "wicenrfidapi.amqtt.plugins.wicenmsg:WICENMessagingPlugin"
broker_sys = "amqtt.plugins.sys.broker:BrokerSysPlugin"

… looks pretty close.