mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.62k stars 1.3k forks source link

BUG: python setup.py creates mne.egg-info #11856

Closed larsoner closed 1 day ago

larsoner commented 12 months ago

python setup.py sdist creates a mne.egg-info in the root dir that can then mess up the importlib.metadata resolution of the package version. See discussion in https://github.com/mne-tools/mne-bids/pull/1160#discussion_r1281947981. The TL;DR is that @hoechenberger and I had versions reported as 1.4.2 when we were on 1.5.0.dev because this file sat around out of date.

Ideally this file would not be produced at all, but even python -m build . seems to create it.

cbrnr commented 11 months ago

Where is this relevant? When doing mne.__version__? Can importlib.metadata be instructed to only use specific directories (not sure what exactly you are referring to though)?

larsoner commented 11 months ago

The discussion linked above https://github.com/mne-tools/mne-bids/pull/1160#discussion_r1281947981 shows how/where it's relevant

Can importlib.metadata be instructed to only use specific directories

Not that I know of but feel free to investigate

cbrnr commented 11 months ago

Thanks @larsoner, I didn't find anything, only this SO post where the author confirms that deleting the directory solves the issue.

BTW, the problem also occurs when installing with pip install -e . if the folder mne.egg-info already exists (with some previous build info). If it doesn't exist, it gets created and is properly populated with the correct version string. Not sure where to report this issue, to me it sounds like pip should properly rebuild that folder.

cbrnr commented 11 months ago

It's probably not pip, because a minimal example is working as expected:

❯ tree
.
├── mypackage
│   └── __init__.py
└── pyproject.toml
❯ cat pyproject.toml           
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "mypackage"
version = "0.1.0"
❯ cat mypackage/__init__.py           
from importlib.metadata import version

__version__ = version(__package__)

print(__version__)

Install that package with

❯ pip install -e .

This creates the mypackage.egg-info folder. Test with

❯ python -c "import mypackage"

Now change the version to e.g. "0.2.0" in pyproject.toml, run pip install -e . again, and python -c "import mypackage" will show the updated version.

So I think the problem might be in the fallback _version.py?

sappelhoff commented 2 days ago

@larsoner given the changes to our build system, can this be closed now?

larsoner commented 1 day ago

Yes setup.py is gone and even just now doing pip install --no-build-isolation -ve . the problematic mne.egg-info was not created