[Automatic Script Creation] ‘console_scripts’ on POSIX

To make things more clear, I plan to write different posts to talk about what should be done for a specific entry_point on a specific platform. This post just focuses on the ‘console_scripts’ entry_point on POSIX, which is learned from setuptools. Future implementation in packaging may be much different, but we can enhance it against this post.

Five things should be done (already done in setuptools) to implement ‘console_scripts’ on POSIX:

1.    generate the script header
  1) string example:
     #!python.exe
     # EASY-INSTALL-ENTRY-SCRIPT:’    setuptools==0.6c11′,’console_scripts’,’easy_install-2.7′
  2) reference in setuptools:
     get_script_header() function
  3) need entry_points or pkg_resource support ?
     no
  4) consideration:
     It does not need entry_points or pkg_resource support, so this kind of function can be implemented for packaging at first.

2.    get the requirement specification
  1) string example:
     __requires__ = ‘setuptools==0.6c11’
  2) reference in setuptools:
     the line in get_script_args: spec = str(dist.as_requirement())
  3) need entry_points or pkg_resource support ?
     Yes
  4) consideration:
     how to get the requirement specification string without pkg_resource there?

3.    construct the script text to be written into the script file
  1) string example:
     __requires__ = ‘setuptools==0.6c11’
     import sys
     from pkg_resources import load_entry_point

     sys.exit(
     load_entry_point(‘setuptools==0.6c11’, ‘console_scripts’, ‘easy_install-2.7’)()
     )
  2) reference in setuptools:
     the ‘script_text’ variable in the get_script_args() function
  3) need entry_points or pkg_resource support ?
     no
  4) consideration:
     There is no pkg_resource in future packaging module, so the kind of ‘load_entry_point’ string will be much different. After we implement such kind of entry point loading function for packaging, this script text constructed can be meaningful.

4.    write the (script header + script text) into the script file
     Just write the file and change it to an executive mode, so no more to say.

5.    make this script run (platform support)
  1) string example:
     ‘load_entry_point’ in the script file
  2) reference in setuptools:
     check the ‘load_entry_point’ function in pkg_resource
  3) need entry_points or pkg_resource support ?
     definitely yes
  4) consideration:
     we should implement such kind of ‘load_entry_point’ function in packaging, thus all problems can be solved

Advertisements
This entry was posted in Distutils2, GSOC2011, Python. Bookmark the permalink.

One Response to [Automatic Script Creation] ‘console_scripts’ on POSIX

  1. Éric Araujo says:

    > #!python.exe
    That’s not POSIX, unless you consider Mono 🙂

    > get the requirement specification […]
    > ‘load_entry_point’ in the script file […]
    > we should implement such kind of ‘load_entry_point’ function in packaging,
    > thus all problems can be solved

    I think you’re too deep in setuptools/distribute. Step back, forget the entry points system, pkg_resources and multi versions, just consider the feature: generate platform-appropriate scripts from paths to callable objects. The starting point is something like “sphinx-build = sphinx.build.main”, and the POSIX script needs not be more complicated that a file named “sphinx-build” (no extension) with this content:

    #!/usr/local/bin/python3
    from sphinx.build import main
    main()

    (You could use the runpy module, but it does not exist in 2.4)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s