KamitaniLab / bdpy

Python package for brain decoding analysis (BrainDecoderToolbox2 data format, machine learning analysis, functional MRI)
MIT License
33 stars 22 forks source link

Migrating packaging system from setup.py to pyproject.toml #67

Closed ganow closed 1 year ago

ganow commented 1 year ago

Changes

Verification

I have tested the following procedures work in the local environment.

Package building

$ git clone https://github.com/KamitaniLab/bdpy.git
$ cd bdpy && git fetch && git checkout update-packaging
$ hatch build
[sdist]
dist/bdpy-0.19.tar.gz

[wheel]
dist/bdpy-0.19-py3-none-any.whl

(update on 6/22) The following works:

$ pip install build
$ git clone https://github.com/KamitaniLab/bdpy.git
$ cd bdpy && git fetch && git checkout update-packaging
$ python -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for wheel...
* Building wheel...
Successfully built bdpy-0.19.tar.gz and bdpy-0.19-py3-none-any.whl

Until I investigated the Python build system this time, I was unaware that the hatchling specified in pyproject.toml is a build backend, and hatch is a command line frontend used to initiate hatchling. It is not necessarily required to match the frontend with the build backend. The build tool, managed by PyPA, uses the appropriate build backend according to the specifications in pyproject.toml, so it was not necessary to install the hatch frontend.

Installation

$ pip install 'dist/bdpy-0.19-py3-none-any.whl[fig]'
...
Installing collected packages: pytz, tzdata, threadpoolctl, six, pyyaml, pyparsing, pillow, numpy, kiwisolver, joblib, fonttools, cycler, scipy, python-dateutil, h5py, contourpy, scikit-learn, pandas, matplotlib, hdf5storage, bdpy
Successfully installed bdpy-0.19 contourpy-1.1.0 cycler-0.11.0 fonttools-4.40.0 h5py-3.9.0 hdf5storage-0.1.19 joblib-1.2.0 kiwisolver-1.4.4 matplotlib-3.7.1 numpy-1.24.3 pandas-2.0.2 pillow-9.5.0 pyparsing-3.1.0 python-dateutil-2.8.2 pytz-2023.3 pyyaml-6.0 scikit-learn-1.2.2 scipy-1.10.1 six-1.16.0 threadpoolctl-3.1.0 tzdata-2023.3

I have NOT tested the following works (since it'll affect the production environment), but conceptually it must work.

Deploy

$ hatch publish

(update on 6/26)

$ python -m twine upload dist/*

Notes

I have created initial version of the pyproject.toml by mitsuhiko/rye (and I privately use it for managing my dev environment). After the creation of pyproject.toml, I have manually edited it so that it can handle extra deps. ~I demonstrated how to build&publish the package by using hatch command because I thought that currently, rye is a newly developed tool and hatch might be a better option to use as a repository default.~ I have updated the example build&deploy scripts from hatch to build and twine, which seem to be widely used tools in recent years.

ganow commented 1 year ago

Random notes

ganow commented 1 year ago

What I've found via GitHub workflow:

(update on 6/22) I've summarized why the nipy installation fails for Python >=3.10 in https://github.com/KamitaniLab/bdpy/issues/68#issuecomment-1602175865

(update on 6/26) I closed the issue on the nipy installation failure for Python >= 3.10 since we can expect that it will be resolved for the next nipy release. (see https://github.com/KamitaniLab/bdpy/issues/68#issuecomment-1606582724 for the details)

github-actions[bot] commented 1 year ago

Coverage

Coverage Report
FileStmtsMissCoverMissing
bdpy
   __init__.py330%10–12
bdpy/bdata
   __init__.py220%7–8
   bdata.py4024020%26–924
   featureselector.py64640%8–124
   metadata.py67670%8–154
   utils.py1131130%4–258
bdpy/dataform
   __init__.py440%7–10
   datastore.py1071070%7–265
   features.py2752750%8–516
   pd.py990%7–44
   sparse.py67670%6–126
bdpy/distcomp
   __init__.py110%6
   distcomp.py92920%7–127
bdpy/dl
   caffe.py60600%4–129
bdpy/dl/torch
   __init__.py220%1–2
   base.py43430%6–105
   models.py1041040%1–369
   torch.py1091090%3–258
bdpy/evals
   metrics.py95950%3–179
bdpy/feature
   __init__.py110%3
   feature.py30300%1–74
bdpy/fig
   __init__.py440%6–9
   draw_group_image_set.py90900%3–182
   fig.py88880%16–164
   makeplots.py3363360%1–729
   tile_images.py59590%1–193
bdpy/ml
   __init__.py770%8–14
   crossvalidation.py59590%7–196
   ensemble.py13130%5–46
   learning.py2962960%4–574
   model.py1341340%4–277
   regress.py11110%6–38
   searchlight.py16160%4–51
bdpy/mri
   __init__.py770%7–13
   fmriprep.py4974970%4–866
   glm.py40400%4–95
   image.py24240%4–54
   load_epi.py28280%7–88
   load_mri.py19190%4–36
   roi.py2482480%4–499
   spm.py1581580%1–300
bdpy/opendata
   __init__.py110%1
   openneuro.py1781780%1–281
bdpy/preproc
   __init__.py330%8–10
   interface.py52520%8–217
   preprocessor.py1291290%8–236
   select_top.py22220%8–61
   util.py660%6–22
bdpy/recon
   utils.py55550%4–146
bdpy/recon/torch
   __init__.py110%1
   icnn.py1591590%15–473
bdpy/stats
   __init__.py110%14
   corr.py42420%7–116
bdpy/util
   __init__.py330%8–10
   info.py46460%1–76
   math.py12120%1–32
   utils.py35350%8–146
TOTAL452945290% 

Tests Skipped Failures Errors Time
110 0 :zzz: 13 :x: 6 :fire: 12.347s :stopwatch:
ganow commented 1 year ago

The reason why coverage==0% even though we have several test cases

ganow commented 1 year ago

Memo: The GitHub workflow created in this PR only reports lint errors and type errors and does not actively intervene in existing code. Running the following commands (black and ruff with fix option) in {workflow/local environment} would resolve the error somewhat automatically.

$ black bdpy  # formatting w/ Black
$ ruff check --fix bdpy  # (partial) formatting w/ Ruff by enabling autofix option

As a project, Ruff is designed to be used alongside Black and, as such, will defer implementing stylistic lint rules that are obviated by autoformatting.