conradtchan / starfit

Fit stellar abundance measurements to stellar models
Other
2 stars 0 forks source link

Transition to Meson build system #209

Closed conradtchan closed 1 year ago

conradtchan commented 1 year ago

Resolves #162

numpy.distutils will be removed in Python 3.12: https://numpy.org/doc/stable/reference/distutils_status_migration.html

Migration to another build system is necessary to build Fortran components. Meson is chosen based on the recommendations. It is likely to be well supported because it is used by SciPy.

Previously, the version number was set automatically using setuptools_scm from the git tag. In Meson, this is done using

meson rewrite kwargs set project / version $(git describe --tags)

in the release step. This was tested in https://github.com/conradtchan/starfit/releases/tag/0.19.1.dev0

This PR also removes setup.cfg, moving all of the config into pyproject.toml

2sn commented 1 year ago
pip install git+https://github.com/conradtchan/starfit.git@99c7960ba740d71d2ac29f70087119255e00c98a

...

ModuleNotFoundError: No module named 'mesonpy'

maybe requires extra dependency?

2sn commented 1 year ago

but there is no module named mesonpy:

~/python>pip install mesonpy
Collecting mesonpy
  Downloading MesonPy-0.0.1.tar.gz (14 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/n4/g1v3m0sn78lb3cyjqfhm3yh40000gn/T/pip-install-cc7dwhqy/mesonpy_704bfd5d7c134b39bc525215882dc8b0/setup.py", line 4, in <module>
          with open('requirements.txt') as f:
               ^^^^^^^^^^^^^^^^^^^^^^^^
      FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
2sn commented 1 year ago

meson-python

2sn commented 1 year ago
 ERROR: Could not detect Ninja v1.8.2 or newer
2sn commented 1 year ago
brew install ninja
2sn commented 1 year ago
Successfully installed starfit-0.0.0

This was for M1 (MacOS 13.1, homebrew)

The issue with failed version number for dev versions seems to persist with meson. But I do not recall whether this was an issue with setuptools or something else in the first place.

conradtchan commented 1 year ago

@2sn That's strange. Something is wrong if you manually need to install meson and ninja. The build requirements in pyproject.toml should get those automatically. The command:

pip install git+https://github.com/conradtchan/starfit.git@99c7960ba740d71d2ac29f70087119255e00c98a

works for me in a clean environment.

2sn commented 1 year ago

no, this did not work on my mac with homebrew.

2sn commented 1 year ago

I mean, it compiled after I manually installed the packages. On my linux machine I already have ninja installed (to compile vtk).

2sn commented 1 year ago

@conradtchan How do I install editable build?

~/python/starfit>pip install -U -e .[testing]
Obtaining file:///home/alex/python/starfit
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.21 in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (1.24.1)
Requirement already satisfied: scipy in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (1.10.0)
Requirement already satisfied: matplotlib in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (3.6.3)
Requirement already satisfied: setuptools in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (65.5.0)
Requirement already satisfied: psutil in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (5.9.4)
Requirement already satisfied: pyyaml in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (6.0)
Requirement already satisfied: pytest in /home/alex/Python/lib/python3.11/site-packages (from starfit==0.0.0) (7.2.1)
Requirement already satisfied: contourpy>=1.0.1 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (4.38.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (23.0)
Requirement already satisfied: pillow>=6.2.0 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (9.4.0)
Requirement already satisfied: pyparsing>=2.2.1 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /home/alex/Python/lib/python3.11/site-packages (from matplotlib->starfit==0.0.0) (2.8.2)
Requirement already satisfied: attrs>=19.2.0 in /home/alex/Python/lib/python3.11/site-packages (from pytest->starfit==0.0.0) (22.2.0)
Requirement already satisfied: iniconfig in /home/alex/Python/lib/python3.11/site-packages (from pytest->starfit==0.0.0) (2.0.0)
Requirement already satisfied: pluggy<2.0,>=0.12 in /home/alex/Python/lib/python3.11/site-packages (from pytest->starfit==0.0.0) (1.0.0)
Requirement already satisfied: six>=1.5 in /home/alex/Python/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib->starfit==0.0.0) (1.16.0)
Installing collected packages: starfit
  Attempting uninstall: starfit
    Found existing installation: starfit 0.18.0.post1.dev0+gdfe9039.d20221211
    Uninstalling starfit-0.18.0.post1.dev0+gdfe9039.d20221211:
      Successfully uninstalled starfit-0.18.0.post1.dev0+gdfe9039.d20221211
  Running setup.py develop for starfit
    error: subprocess-exited-with-error

    × python setup.py develop did not run successfully.
    │ exit code: 1
    ╰─> [1 lines of output]
        ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
        [end of output]

    note: This error originates from a subprocess, and is likely not a problem with pip.
  Rolling back uninstall of starfit
  Moving to /home/alex/Python_3.11.0/lib/python3.11/site-packages/starfit.egg-link
   from /tmp/pip-uninstall-jpt7jn8o/starfit.egg-link
error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
    ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
conradtchan commented 1 year ago

@2sn what is your pip --version?

2sn commented 1 year ago

should be current (updated yesterday)

2sn commented 1 year ago
pip 22.3.1 from /home/alex/Python/lib/python3.11/site-packages/pip (python 3.11)
2sn commented 1 year ago

Installed on my Linux as regular package, just need to know about editable install.

2sn commented 1 year ago

Maybe mesone version should be a branch not on the main distribution for now?

conradtchan commented 1 year ago

We need to implement editable installs (https://peps.python.org/pep-0660/) before this PR is ready. Switching this back to a draft.

@2sn When we were using setup.py, what happens when you edit the fortran source in an editable install? does it recompile, or ignore those changes?

2sn commented 1 year ago

@conradtchan I ran ran the editable install command again and it re-compiled. It did not do that automatically (unlike my build.py).

conradtchan commented 1 year ago

@2sn meson-python doesn't support editable installs yet. It's in the next release though: https://github.com/mesonbuild/meson-python/milestone/6

conradtchan commented 1 year ago

@2sn Builds and installs correctly on the web server.

2sn commented 1 year ago

@conradtchan it seems this is now ready to merge? Please go ahead!

2sn commented 1 year ago

@conradtchan now I have to learn how to use the new build system if I change anything ...