5

setup.py used to define entry points like this:

entry_points={
    'console_scripts': [
        'cursive = cursive.tools.cmd:cursive_command',
    ],
},

How to do it for pipenv? There seems to be no canonical way to defined an entry point with Pipenv?

I've found that setuptools suggest that a setup.cfg file should be created, like this:

[options.entry_points]
console_scripts =
    cursive = cursive.tools.cmd:cursive_command

but then it never gets "intalled": that is, no cursive executable is created.

So, how to create entry points with Pipenv?

kolypto
  • 31,774
  • 17
  • 105
  • 99

2 Answers2

3

Leon Sandøy:

Pipenv isn't really meant for this sort of thing. It is great for projects that aren't meant to be built or distributed, though. If you're working on a package, you should be using poetry. It's one of the things it's uniquely better at.

kolypto
  • 31,774
  • 17
  • 105
  • 99
1

You can still register entrypoints even if you do not intend to package nor install your software.

Simply create a foobar.dist-info/entry_points.txt in the same folder where your modules are importable and list there what would traditionally go into the setup.cfg entry points section

# foobar.dist-info/entry_points.txt
[entrypoint.group]
name = foo.bar:something

This way the objects you registered will be available via

import importlib.metadata

importlib.metadata.entry_points()["entrypoint.group"]

Related https://stackoverflow.com/a/73476306/11715259


If you are solely interested in the console_scripts entry point, note that the described solution is useless: pip is the actual consumer of this entry point, creating/removing files that will be listed in your shell PATH when a package is installed/uninstalled with the aid of distlib.scripts.

It is much easier to use Pipfile scripts section https://pipenv.pypa.io/en/latest/advanced/#custom-script-shortcuts (if you are in doubt, stop reading and do this)

Otherwise you could package and actually install your software in editable mode.

Alternatively, imitate pip's behaviour creating the console scripts with distlib.scripts:ScriptMaker in a Makefile or alike in a requirements installation phase (if you are in doubt, you should probably avoid this option).

N1ngu
  • 2,862
  • 17
  • 35