I am experimenting with using the CPython C API and managing dependencies (e.g. setuptools) via poetry.
To compile my code I wrote a Makefile looking something like this:
PYTHON = poetry run python
build: setup.py ...some C extension files...
$(PYTHON) setup.py build_ext -i
The problem is that when I go to run it, I get this error:
$ make
poetry run python setup.py build_ext
make: poetry: No such file or directory
make: *** [build] Error 1
When I run poetry
in my terminal, it works fine:
$ poetry --version
Poetry (version 2.0.1)
Even weirder:
$ type poetry
poetry is /Users/rusty/.local/bin/poetry
$ which poetry
$ echo $?
1
I thought that which
and type
would return the exact same results.
I checked my $PATH
and it contains the directory ~/.local/bin
(not /Users/rusty/.local/bin
, literally ~/.local/bin
in case that helps) (where poetry is installed).
I am on macOS 15.3.2.
Also, ~/.local/bin/poetry
is a symlink to another file which has read and execute for everyone.
I checked my
$PATH
and it contains the directory~/.local/bin
(not/Users/rusty/.local/bin
, literally~/.local/bin
in case that helps) (where pypoetry is installed) twice.
It is a feature of some shells to apply tilde expansion to interpreting elements of the executable search path. That is not provided by the underlying system calls, however, and it is not a behavior specified for the POSIX shell.
You are apparently relying on that behavior to run poetry
from your command line. That it works tells you that your default shell (probably Zsh) does perform tilde expansion on path elements. However, make
, by default, uses /bin/sh
to execute recipe lines. This will typically yield a shell that provides behavior very close to that of the POSIX shell. Normally, such a shell will not perform tilde expansion on path elements. Such a shell will not find your poetry
command in your path, and that's what you in fact seem to be observing.
Some of your options are:
poetry
executable. (Maybe it ends up at /usr/local/bin/poetry, for example.)~
to ${HOME}
should do it.SHELL
variable in your makefile to a full path to a different shell to use for executing recipes. For example, SHELL = /bin/zsh
. Note well, however, that this might produce behavior changes in other recipe lines, too.Those are ordered from most- to least-recommended, according to me.