Fix pip module package building #421
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status: Ready
The v1.0.0 release on PyPI is missing all submodules (wave, tidal, dolfyn, etc.) when installed via pip and downstream via conda.
Reproduction
pip install "mhkit[all]"Installed Package Contents
Inspecting the installed package shows two files (run
python -m siteto findsite-packagespath):
All submodules (wave, river, tidal, dolfyn, power, loads, mooring, acoustics, qc, utils) are missing.
Reproduction
Running the same build command used by GitHub Actions:
python -m build --wheel --outdir dist/ .python -m build: Runs Python'sbuildmodule (PEP 517 build frontend) to build the package--wheel: Build only a wheel distribution (skips source distribution)--outdir dist/: Output directory for built files.: Build the package in the current directory (wherepyproject.tomlis)Build output shows two files being copied:
Wheel contents:
Probable Root Cause
In
pyproject.toml, this configuration tells setuptools to only include the top-levelmhkitpackage, not any subpackages per: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configurationProposed Fix
Replace the explicit package list with automatic package discovery using setuptools'
finddirective.Setuptools Package Discovery Documentation
What this does (from setuptools docs):
where = ["."]: Search for packages starting from the root directoryinclude = ["mhkit*"]: Only include packages that match the patternmhkit*(this includesmhkit,mhkit.wave,mhkit.river, etc.)__init__.pyfilesThis will automatically discover and include:
mhkitmhkit.wavemhkit.rivermhkit.tidalmhkit.dolfynmhkit.dolfyn.adpmhkit.dolfyn.advmhkit.dolfyn.iomhkit.dolfyn.rotatemhkit.dolfyn.toolsmhkit.powermhkit.loadsmhkit.loads.extrememhkit.mooringmhkit.acousticsmhkit.qcmhkit.utilsmhkit.wave.iomhkit.wave.io.hindcastmhkit.tidal.iomhkit.river.iomhkit.tests.*Verification of Fix
python -m build: Runs Python'sbuildmodule to build the package--sdist: Build a source distribution (.tar.gzfile) - a compressed archive of source code--wheel: Build a wheel (.whlfile) - a pre-built distribution that pip installs directlyunzip -l dist/mhkit-1.0.0-py3-none-any.whl | grep "mhkit/" | grep "__init__.py"Why build both formats?
pip install mhkitdownloads and installs. The bug affects this format.References:
Contents of newly build wheel:
In [1]: import mhkit In [2]: mhkit.__version__ Out[2]: 'v1.0.0' In [3]: from mhkit import river In [4]: river.performance.circular(30) Out[4]: (30, 706.8583470577034)Preventing Future Issues
To prevent this issue from happening again, this adds two GH actions changes in
.github/workflows/main.ymland
.github/workflows/pypi.yml,to verify the built wheel includes all submodules and run thetests against the installed wheel.