question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow creating a console/gui script with callable module

See original GitHub issue

Given a setup.cfg containing:

⊙  bat setup.cfg                                                                                                                                                                                  julian@Air
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: setup.cfg
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [metadata]
   2   │ name = foo
   3   │
   4   │ [options]
   5   │ packages = find:
   6   │
   7   │ [options.entry_points]
   8   │ console_scripts =
   9   │     foo = foo
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

where you’ll see the console_scripts there has foo = foo, rather than an intended e.g. foo = foo:main, attempting to install the package produces:

⊙  rm -rf venv; python3.8 -m venv venv; venv/bin/python -m pip install .                                                                                                                          julian@Air
Processing /Users/julian/Desktop/foo
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: foo
  Building wheel for foo (PEP 517) ... done
  Created wheel for foo: filename=foo-0.0.0-py3-none-any.whl size=2841 sha256=baed8c89b2417754b8e843ada0ac5f36da395f957e0470dabd1f8c5340fb4977
  Stored in directory: /private/var/folders/cr/h4lk12bj5cn4qdx4ct9hddmm0000gn/T/pip-ephem-wheel-cache-2alzb1jr/wheels/62/63/34/d22a94079c5f6ae4451bcf9e08db91c779e9e2b4ff02a6228b
Successfully built foo
Installing collected packages: foo
ERROR: Invalid script entry point: <ExportEntry foo = foo:None []> for req: foo==0.0.0 - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.

where the error message leaks some internals.

Describe the solution you’d like

An error message slightly tweaked to e.g. “Invalid script entry point: ‘foo = foo’ does not define which callable to enter. Provide one separated via a ‘:’. See https://packaging.python.org/specifications/entry-points/#use-for-scripts for details.”

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
saaketpcommented, Mar 22, 2022

Actually, even if foo is callable, pip checks whether a :suffix is provided when installing a wheel file. https://github.com/pypa/pip/blob/22.0.4/src/pip/_internal/operations/install/wheel.py#L420 But the specification link (that the error message points to) doesn’t really say that the suffix is required.

I was trying out making a callable module, and it worked when I installed with pip install --editable but not when I tried to build a wheel and install it.

I tried removing the suffix requirement but that didn’t work because distlib assumes that suffix will always be there and it can be imported as from module import suffix https://github.com/pypa/pip/blob/22.0.4/src/pip/_vendor/distlib/scripts.py#L44 https://github.com/pypa/pip/blob/22.0.4/src/pip/_vendor/distlib/scripts.py#L228-L230 So probably that has to be fixed first to handle the cases without suffix and just import module and treat the module itself as function (not sure if it is even worth it though).

0reactions
saaketpcommented, Mar 26, 2022

I gave it a try today and it didn’t need much changes. So I submitted a pull request https://github.com/pypa/distlib/pull/166

If that is merged we can solve this in pip by updating the vendored distlib and removing the suffix is None check (or would be better to replace that with a check for callable instead). But looks like the vendored distlib is downgraded to an older version for now, so it will probably take a while.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Command Line Scripts — Python Packaging Tutorial
The first approach is to write your script in a separate file, ... Setuptools allows modules to register entrypoints which other packages can...
Read more >
Callables in Python — How to Make Custom Instance Objects ...
The callable() Function. Fortunately, Python has a built-in function callable , which allows us to determine if an object is callable or not....
Read more >
Write TypeScript declaration file for callable module
This seems to work: declare module 'cldr-data' { interface CldrData { (path: any, ...args: any[]): any; availableLocales: any; all(): any; ...
Read more >
Script includes - Product Documentation | ServiceNow
This property changes the visibility of client-callable script includes by making them all public or private. Configure the property as ...
Read more >
Entry points specification - Python Packaging User Guide
gui_scripts are wrapped in a GUI executable, so they can be started without a console, but cannot use standard streams unless application code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found