Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-16 Thread Nathaniel Smith
On Sat, Oct 15, 2016 at 4:38 PM, Ben Finney  wrote:
> Thomas Kluyver  writes:
>
>> If the entry point looks like:
>>
>> foo=foomod:main
>>
>> Then you can invoke it in a subprocess by running:
>>
>> subprocess.Popen([sys.executable, '-c', 'import foomod; foomod.main()'])
>
> That will invoke the program. I'll probably try that.
>
> One disadvantage there is the process won't have an informative name;
> instead of being named ‘/foo/bar/lipsum’, it will be named ‘python’
> which is less useful.

I won't claim it's pretty to look at, but if this is a major issue
then as a workaround I suppose you can consider adding a dependency on
https://pypi.org/project/setproctitle/ and running

[sys.executable, '-c', 'import setproctitle;
setproctitle.setproctitle("foo"); import foomod; foomod.main()]

-n

-- 
Nathaniel J. Smith -- https://vorpus.org
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-16 Thread Paul Moore
On 16 October 2016 at 00:38, Ben Finney  wrote:
>> This avoids the need to work out where the 'foo' script has been
>> installed to.
>
> So, I'm still wanting to know from Setuptools itself at run time, what
> filesystem path Setuptools installed the command to.

Setuptools doesn't install the command, it just records entry point
metadata. The installer (pip, presumably?) creates the wrapper. The
name of the wrapper file that gets installed is technically recorded
in the installed files metadata (for use by pip uninstall) but there's
no information recording the link between the entry point and the
file.

Paul
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Daniel Holth
It does not store that information, except maybe in the manifest used for
uninstall in the .*-info directory for your installed distribution.

On Sat, Oct 15, 2016, 19:39 Ben Finney  wrote:

> Thomas Kluyver  writes:
>
> > If the entry point looks like:
> >
> > foo=foomod:main
> >
> > Then you can invoke it in a subprocess by running:
> >
> > subprocess.Popen([sys.executable, '-c', 'import foomod; foomod.main()'])
>
> That will invoke the program. I'll probably try that.
>
> One disadvantage there is the process won't have an informative name;
> instead of being named ‘/foo/bar/lipsum’, it will be named ‘python’
> which is less useful.
>
> > This avoids the need to work out where the 'foo' script has been
> > installed to.
>
> So, I'm still wanting to know from Setuptools itself at run time, what
> filesystem path Setuptools installed the command to.
>
> --
>  \“I took it easy today. I just pretty much layed around in my |
>   `\underwear all day. … Got kicked out of quite a few places, |
> _o__)  though.” —Bug-Eyed Earl, _Red Meat_ |
> Ben Finney
>
> ___
> Distutils-SIG maillist  -  Distutils-SIG@python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Ben Finney
Thomas Kluyver  writes:

> If the entry point looks like:
>
> foo=foomod:main
>
> Then you can invoke it in a subprocess by running:
>
> subprocess.Popen([sys.executable, '-c', 'import foomod; foomod.main()'])

That will invoke the program. I'll probably try that.

One disadvantage there is the process won't have an informative name;
instead of being named ‘/foo/bar/lipsum’, it will be named ‘python’
which is less useful.

> This avoids the need to work out where the 'foo' script has been
> installed to.

So, I'm still wanting to know from Setuptools itself at run time, what
filesystem path Setuptools installed the command to.

-- 
 \“I took it easy today. I just pretty much layed around in my |
  `\underwear all day. … Got kicked out of quite a few places, |
_o__)  though.” —Bug-Eyed Earl, _Red Meat_ |
Ben Finney

___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Thomas Kluyver
On Sat, Oct 15, 2016, at 06:57 PM, Ben Finney wrote:
> I'm modifying an existing application that invokes the program as a
> subprocess, so I'm wanting to find that program as an external command.

If the entry point looks like:

foo=foomod:main

Then you can invoke it in a subprocess by running:

subprocess.Popen([sys.executable, '-c', 'import foomod; foomod.main()'])

This avoids the need to work out where the 'foo' script has been
installed to.
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Ben Finney
Nick Timkovich  writes:

> 1. include the shell scripts (could also be binaries) in the package &
> manifest
> (https://github.com/nicktimko/autolycus/blob/master/MANIFEST.in#L3)

No, I'm using ‘[…] install --install-scripts=APPLICATION_SCRIPTS_PATH’
at install time.

> 2. use pkg_resources to get where the .sh was so I could run it with
> subprocess.

What I need is for ‘pkg_resources’ to tell me at run time where
‘--install-scripts’ put the scripts for this application.

-- 
 \“I don't accept the currently fashionable assertion that any |
  `\   view is automatically as worthy of respect as any equal and |
_o__)   opposite view.” —Douglas Adams |
Ben Finney

___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Nick Timkovich
I recently was trying to port a mix of shell & Python scripts to pure
Python (https://github.com/nicktimko/autolycus), and my interim solution to
get something working to test was to:

1. include the shell scripts (could also be binaries) in the package &
manifest (https://github.com/nicktimko/autolycus/blob/master/MANIFEST.in#L3)
2. use pkg_resources to get where the .sh was so I could run it with
subprocess. (
https://github.com/nicktimko/autolycus/blob/master/autolycus/legacy.py)

Closer to what you need?

On Sat, Oct 15, 2016 at 12:57 PM, Ben Finney 
wrote:

> Nick Timkovich  writes:
>
> > Usually that entry point is on the PATH […]
>
> It's not, because I'm deliberately specifying that it shouldn't be, at
> install time. This is an executable that is private to the application
> and not for general availability on the host.
>
> > If you want to call that entry point from your code, the clean way
> > (same environment/version, and especially if you don't need to bother
> > multiprocessing it) would be to import the corresponding entry point
> > function & call that.
>
> I'm modifying an existing application that invokes the program as a
> subprocess, so I'm wanting to find that program as an external command.
>
> > I might not be answering your question directly, but hopefully there's
> > a workaround there. What's your use-case for grabbing the exec path?
>
> Existing code assumes it is an external command on the shell PATH, but
> I'm changing that so that it's not on PATH. I need to make a minimal
> change and want to ensure that I get the right filesystem path based on
> what the distribution knows about itself.
>
> --
>  \  “I like to fill my bathtub up with water, then turn the shower |
>   `\   on and pretend I'm in a submarine that's been hit.” —Steven |
> _o__)   Wright |
> Ben Finney
>
> ___
> Distutils-SIG maillist  -  Distutils-SIG@python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Ben Finney
Nick Timkovich  writes:

> Usually that entry point is on the PATH […]

It's not, because I'm deliberately specifying that it shouldn't be, at
install time. This is an executable that is private to the application
and not for general availability on the host.

> If you want to call that entry point from your code, the clean way
> (same environment/version, and especially if you don't need to bother
> multiprocessing it) would be to import the corresponding entry point
> function & call that.

I'm modifying an existing application that invokes the program as a
subprocess, so I'm wanting to find that program as an external command.

> I might not be answering your question directly, but hopefully there's
> a workaround there. What's your use-case for grabbing the exec path?

Existing code assumes it is an external command on the shell PATH, but
I'm changing that so that it's not on PATH. I need to make a minimal
change and want to ensure that I get the right filesystem path based on
what the distribution knows about itself.

-- 
 \  “I like to fill my bathtub up with water, then turn the shower |
  `\   on and pretend I'm in a submarine that's been hit.” —Steven |
_o__)   Wright |
Ben Finney

___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Nick Timkovich
Usually that entry point is on the PATH, so it should be somewhere in
os.environ['PATH'], so if you just `subprocess.run(['myentrything'])` that
would fire it.

If you want to call that entry point from your code, the clean way (same
environment/version, and especially if you don't need to bother
multiprocessing it) would be to import the corresponding entry point
function & call that.

I might not be answering your question directly, but hopefully there's a
workaround there. What's your use-case for grabbing the exec path?


On Sat, Oct 15, 2016 at 2:06 AM, Ben Finney 
wrote:

> Howdy,
>
> How can a Python application discover at run-time where on the
> filesystem its own ‘entry_points’ programs are available?
>
> The Setuptools ‘entry_points’ are available at run-time to the
> distribution, via the ‘pkg_resources’ API for entry points
>  resources.html#entry-points>.
>
> I don't see there how to interrogate for which filesystem path to invoke
> for a specific entry point's command.
>
> How can I reliably ask ‘pkg_resources’ for “where is the entry point
> named ‘foo’ installed?” such that I get a filesystem path of a command
> to invoke?
>
> --
>  \ “Geeks like to think that they can ignore politics. You can |
>   `\leave politics alone, but politics won't leave you alone.” |
> _o__) —Richard M. Stallman, 2002-07-26 |
> Ben Finney
>
> ___
> Distutils-SIG maillist  -  Distutils-SIG@python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig


[Distutils] Interrogate distribution for an entry point command path

2016-10-15 Thread Ben Finney
Howdy,

How can a Python application discover at run-time where on the
filesystem its own ‘entry_points’ programs are available?

The Setuptools ‘entry_points’ are available at run-time to the
distribution, via the ‘pkg_resources’ API for entry points
.

I don't see there how to interrogate for which filesystem path to invoke
for a specific entry point's command.

How can I reliably ask ‘pkg_resources’ for “where is the entry point
named ‘foo’ installed?” such that I get a filesystem path of a command
to invoke?

-- 
 \ “Geeks like to think that they can ignore politics. You can |
  `\leave politics alone, but politics won't leave you alone.” |
_o__) —Richard M. Stallman, 2002-07-26 |
Ben Finney

___
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig