• Stars
    star
    121
  • Rank 292,207 (Top 6 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created about 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

make entry_points specified in setup.py load more quickly.

Fast entry_points

Using entry_points in your setup.py makes scripts that start really slowly because it imports pkg_resources, which is a horrible thing to do if you want your trivial script to execute more or less instantly. Check it out: pypa/setuptools#510

Importing fastentrypoints in your setup.py file produces scripts that looks (more or less) like this:

# -*- coding: utf-8 -*-
import re
import sys

from package.module import entry_function

if __name__ == '__main__':
  sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
  sys.exit(entry_function())

This is ripped directly from the way wheels do it and is faster than whatever the heck the normal console scripts do.

Note:

This bug in setuptools only affects packages built with the normal setup.py method. Building wheels avoids the problem and has many other benefits as well. fastentrypoints simply ensures that your user scripts will not automatically import pkg_resources, no matter how they are built.

When using Python 3.8 and setuptools 47.2 (or newer), console scripts do not import pkg_resources.

Usage

To use fastentrypoints, simply copy fastentrypoints.py into your project folder in the same directory as setup.py, and import fastentrypoints in your setup.py file. This monkey-patches setuptools.command.easy_install.ScriptWriter.get_args() in the background, which in turn produces simple entry scripts (like the one above) when you install the package.

If you install fastentrypoints as a module, you have the fastep executable, which will copy fastentrypoints.py into the working directory (or into a list of directories you give it as arguments) and append include fastentrypoints.py to the MANIFEST.in file, and add an import statement to setup.py. It is available from PyPI.

Be sure to add fastentrypoints.py to MANIFEST.ini if you want to distribute your package on PyPI.

Alternatively, you can specify fastentrypoints as a build system dependency by adding a pyproject.toml file (PEP 518) with these lines to your project folder:

[build-system]
requires = ["setuptools", "wheel", "fastentrypoints"]

It is also possible to install it from PyPI with easy_install in the setup script:

try:
    import fastentrypoints
except ImportError:
    from setuptools.command import easy_install
    import pkg_resources
    easy_install.main(['fastentrypoints'])
    pkg_resources.require('fastentrypoints')
    import fastentrypoint

Let me know if there are places where this doesn't work well. I've mostly tested it with console_scripts so far, since I don't write the other thing.

Test

There is one test. To run it, do test/runtest.py. It installs a dummy package with fastentrypoints and ensures the generated script is what is expected.

More Repositories

1

replacing-bash-scripting-with-python

Guide on using using python for administrative scripting
1,044
star
2

administrative-scripting-with-julia

Guide for writing shell scripts in Julia
Jupyter Notebook
160
star
3

oo-and-polymorphism-in-julia

A short, opinionated guide to object orientation and polymorphism in Julia
Jupyter Notebook
94
star
4

dispatching-design-patterns

JuliaCon 2020 talk
HTML
64
star
5

bitocra

a small , clear bitmap font with good support latin-script languages and Hebrew
61
star
6

pyfil

Python one-liners in the spirit of Perl and AWK
Python
49
star
7

xonsh-quickstart

A crash course in the xonsh shell
42
star
8

lazycli

generate CLI scripts from function signatures in Python.
Python
18
star
9

CcallMacros.jl

Julian macros for wrapping ccall
Julia
15
star
10

dirlog

a directory history mechanism for the shell.
Python
11
star
11

hebrew-book

Free/Open Source Biblical Hebrew textbook written in asciidoc.
CSS
6
star
12

lazydots

generate pointed hebrew from ascii characters
Python
5
star
13

easyproc

a thin abstraction layer on subprocess.run() to simplify admin scripts. Python 3.5+
Python
5
star
14

wrld

simplified bash loops (or, xargs -I on steroids)
Python
4
star
15

ivsort

Sort pointed Hebrew words correctly!
Python
3
star
16

dot

config files
Shell
3
star
17

akkdict

lookup akkadian words in the CAD and stuff!
Python
2
star
18

eggshell

command shell which is a superset of python
Python
2
star
19

libaaron

my favorite functions
Python
2
star
20

statesaver

context managers for flushing state to disk
Python
1
star
21

compose-struct

yet another namedtuple alternative for Python
Python
1
star
22

ccall-macro-talk

talk about the @ccall macro for JuliaCon 2020
HTML
1
star