Debugging install & `make test` failure

44 views
Skip to first unread message

Eric Altendorf

unread,
Aug 11, 2024, 12:27:52 AM8/11/24
to bean...@googlegroups.com
This is mentioned on another thread, but I'm raising it again here with a report from a hermetic environment.

To reproduce the failure:

mkdir beancount-install-test
cd beancount-install-test/
git clone https://github.com/beancount/beancount
python -m venv beancount-venv
source beancount-venv/bin/activate
cd beancount
python -m pip install -e .
python -m pip install pytest
make test

produces a bunch of ninja temp file errors of the form:

....
ERROR beancount/utils/test_utils.py - FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-env-o10kn_dq/normal/bin/ninja'
ERROR beancount/utils/test_utils_test.py - FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-env-o10kn_dq/normal/bin/ninja'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 79 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================== 79 errors in 2.82s ==================================================
make: *** [Makefile:150: test] Error 2

I also tried:
python -m pip install ninja

but I get the same failures after that.

There seems to be something very weird with some of the dev mode dependencies.

Martin Blais

unread,
Aug 11, 2024, 12:09:57 PM8/11/24
to bean...@googlegroups.com
I couldn't reproduce precisely your error (thanks for precise and hermetic steps).
However, bringing up your setup with venv, I'm seeing other problems that are related.
For example, overriding PYTHONPATH, I was unable to import the *_test.py files (!?)
I traced it down to some library called _beancount_editable_loader that seems to mess with importing and it installed in the venv.
You'll find it here:
beancount-install-test/beancount-venv/lib/python3.12/site-packages/_beancount_editable_loader.py
It looks like something that is generated by the meson build.
(I don't know more than that, but it messes with the imports somehow, probably via the pth file)
Maybe Daniele will know - he setup the Meson build - I still work the "old skool" way (make build, make test, from repo, with PYTHONPATH).

This modification to your steps will work:


mkdir beancount-install-test
cd beancount-install-test/
git clone https://github.com/beancount/beancount
python -m venv beancount-venv
source beancount-venv/bin/activate
cd beancount
python3 -m pip install -U pip
python3 -m pip install setuptools
python3 -m pip install regex click python-dateutil pytest
make build
make test









--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAFXPr0t%2BO0ji%2B8AzEv7T2_dqsWGR4F%2BCCtjYzayVrMuTXqDW6A%40mail.gmail.com.

Eric Altendorf

unread,
Aug 11, 2024, 2:21:50 PM8/11/24
to bean...@googlegroups.com
Thanks!  Interesting, so it works with setuptools but not pip...

I think I misunderstood the situation with setuptools, thinking it was deprecated when it sounds like actually it's only direct invocation of setup.py that's deprecated?  I dunno.  Python dependency and build management remains fairly mysterious to me.



Daniele Nicolodi

unread,
Aug 11, 2024, 2:42:51 PM8/11/24
to bean...@googlegroups.com
On 11/08/24 06:27, Eric Altendorf wrote:
> This is mentioned on another thread, but I'm raising it again here with
> a report from a hermetic environment.
>
> To reproduce the failure:
>
> mkdir beancount-install-test
> cd beancount-install-test/
> git clone https://github.com/beancount/beancount
> <https://github.com/beancount/beancount>
> python -m venv beancount-venv
> source beancount-venv/bin/activate
> cd beancount
> python -m pip install -e .
> python -m pip install pytest
> make test
>
> produces a bunch of ninja temp file errors

This is because the meson-python editable wheel support re-compiles the
project when it is imported. This requires all the build tools for the
project to be installed in the Python environment. However, by default,
pip created a throw-away environment for building the wheel where the
build tools are installed. The throw-away environment is deleted as soon
as the editable wheel is installed, and the build tools with it. This is
the reason why the meson-python documentation on editable wheels

https://mesonbuild.com/meson-python/how-to-guides/editable-installs.html

recommends to switch off this feature passing the --no-build-isolation
command line option to pip. This requires to install the build tools
required by the project, in the case of beancount this is meson-python,
meson, and ninja.

> I also tried:
> python -m pip install ninja
>
> but I get the same failures after that.

The failure you get after that is similar, but not the same. These
failures are due to the unusual way pytest uses to import the test code.

The last pytest major release does not work with a project that has the
test modules located alongside the source code but not installed in the
wheel. The only solution I've found for this is to install the test
modules. I'll prepare a PR to do this for beancount too.

Cheers,
Dan

Martin Blais

unread,
Aug 11, 2024, 2:49:07 PM8/11/24
to bean...@googlegroups.com
Great explanation, and thank you.
(I have to admit that feels like a lot of "magic" compared to the reasonable, simple, old school way of doing things.)



--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Daniele Nicolodi

unread,
Aug 11, 2024, 3:04:37 PM8/11/24
to bean...@googlegroups.com
On 11/08/24 18:09, Martin Blais wrote:
> I couldn't reproduce precisely your error (thanks for precise and
> hermetic steps).
> However, bringing up your setup with venv, I'm seeing other
> problems that are related.
> For example, overriding PYTHONPATH, I was unable to import the *_test.py
> files (!?)
> I traced it down to some library called _beancount_editable_loader that
> seems to mess with importing and it installed in the venv.
> You'll find it here:
> beancount-install-test/beancount-venv/lib/python3.12/site-packages/_beancount_editable_loader.py
> It looks like something that is generated by the meson build.
> (I don't know more than that, but it messes with the imports somehow,
> probably via the pth file) > Maybe Daniele will know - he setup the Meson build - I still work the
> "old skool" way (make build, make test, from repo, with PYTHONPATH).

I'm also one of the maintainers of meson-python, the Python wheel build
systems used by beancount (at least by default, the old setup.py based
build is still in the repository) and many other projects :-)

meson-python uses meson as build system. for very good reasons, meson
requires the build artifacts (in the case of beancount the extension
modules) to be generated outside the source tree. Therefore it is not
possible to use PYTHONPATH or equivalent to load Python modules and
Python extension modules from a project that contains both. This would
make development very tedious as it would require building and
installing a wheel after every edit to test it. For this reason there
are editable installs (or editable wheels, same thing).

meson-python implements editable installs using a custom Python module
loader that picks the files from the correct location (the build
directory for the compiled parts, and the source directory for the pure
Python parts).

This works well. Except that when pytest is instructed to execute a test
module foo/bar_test.py it expects to be able to import "foo.bar_test"
and this fails if the package "foo" does not install foo/bar_test.py.

The last version of pytest could be convinced to import the test modules
in a way that did not break in this case, but this does not work anymore
since the last major release. The only way I've found to make it work is
to install the test modules in the wheel.

Cheers,
Dan

Reply all
Reply to author
Forward
0 new messages