GithubHelp home page GithubHelp logo

jayvdb / fast-entry_points Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ninjaaron/fast-entry_points

0.0 2.0 0.0 44 KB

make entry_points specified in setup.py load more quickly.

Python 100.00%

fast-entry_points's Introduction

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 look 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.

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.

fast-entry_points's People

Contributors

coldfix avatar drslump avatar lowks avatar marcelm avatar michaelgrupp avatar ninjaaron avatar quentincg avatar tbabej avatar thefab avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.