Skip to content

Supporting custom entry points other than console_scripts in pex envs #17308

Answered by benjyw
achimnol asked this question in Q&A
Discussion options

You must be logged in to vote

I did a bit of experimenting, and you can achieve this today with no Pex or Pants changes with something like:

src_root/anyname.dist_info/entry_points.txt:

[mygroup]
myentrypoint = entry.point:location

src_root/foo/bar.py:

from importlib.metadata import entry_points

print("Entry points: ")
for grp, in_group in entry_points().items():
    print(f"  Group: {grp}")
    for ep in in_group:
        print(f"    {ep}")

src_root/foo/BUILD:

python_sources()

src_root/BUILD:

resources(
  name="dist_info", 
  sources=["anyname.dist-info/**/*"]
)

pex_binary(
  name = "demo",
  dependencies = ["src_root/foo", ":dist_info"],
  entry_point = "foo.bar",
)

Now:

$ ./pants package src_root:demo
19:26:2…

Replies: 4 comments 27 replies

Comment options

benjyw
Oct 21, 2022
Maintainer Sponsor

You must be logged in to vote
1 reply
@benjyw
Comment options

benjyw Oct 21, 2022
Maintainer Sponsor

Comment options

benjyw
Oct 21, 2022
Maintainer Sponsor

You must be logged in to vote
0 replies
Comment options

benjyw
Oct 21, 2022
Maintainer Sponsor

You must be logged in to vote
17 replies
@benjyw
Comment options

benjyw Oct 25, 2022
Maintainer Sponsor

@dbari
Comment options

@benjyw
Comment options

benjyw Oct 26, 2022
Maintainer Sponsor

@dbari
Comment options

@benjyw
Comment options

benjyw Oct 26, 2022
Maintainer Sponsor

Answer selected by benjyw
Comment options

You must be logged in to vote
9 replies
@tgolsson
Comment options

@benjyw
Comment options

benjyw Nov 22, 2022
Maintainer Sponsor

@tgolsson
Comment options

@tgolsson
Comment options

@benjyw
Comment options

benjyw Nov 22, 2022
Maintainer Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants