Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pypi package #1075

Merged
merged 11 commits into from
Nov 26, 2021
Merged

Add pypi package #1075

merged 11 commits into from
Nov 26, 2021

Conversation

bryanwweber
Copy link
Member

@bryanwweber bryanwweber commented Jul 16, 2021

Changes proposed in this pull request

  • Add a new python_sdist interface, which builds a source distribution for Python. This sdist can be used to build all the platform wheels we care to support
  • Update the cython and python_minimal interfaces to use setup.cfg style configuration of the build and install
  • A couple of other cleanups of SCons* files

If applicable, fill in the issue number this pull request is fixing

Closes Cantera/enhancements#5 and #1114

If applicable, provide an example illustrating new features this pull request is introducing

python -m pip install cantera

In testing this pull request, I found that the CI jobs to build all the wheels take 4+ hours. This is partly due to compiling the complete library for every architecture/Python version that is supported. However, I think it is valuable to confirm that we can build from the source distribution. So once this PR is ready for merge, I propose that we create a separate repository that only houses the workflow configuration for building wheels, and runs a build whenever cantera/main is updated. That way, pull requests to this repository won't be held up by waiting for the wheels to build. Before merging this PR into cantera/main we should delete the python-package.yml workflow configuration and move it to the new repository.

The CI for this branch is running over on my fork: https://github.com/bryanwweber/cantera/actions/runs/1038707541

You can test the wheels for yourself by running:

python -m pip install --extra-index-url https://test.pypi.org/simple Cantera==2.6.0a2

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

Aside for new contributors: The branch that's attached to this pull request has been substantially cleaned up prior to proposing the pull request. Based on the history here, it looks like this feature came fully formed from my fingers into the computer. That is a total and complete fabrication. If you want to see the original history of this branch, go here: https://github.com/bryanwweber/cantera/commits/original-pypi-branch

The point is, it takes a lot of iteration to get complex features correct, but please make as many commits as you need! You can always clean it up later.

@codecov
Copy link

codecov bot commented Jul 16, 2021

Codecov Report

Merging #1075 (be54e5a) into main (0e2a33d) will increase coverage by 0.01%.
The diff coverage is 0.00%.

❗ Current head be54e5a differs from pull request most recent head 0e8791a. Consider uploading reports for the commit 0e8791a to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1075      +/-   ##
==========================================
+ Coverage   73.50%   73.52%   +0.01%     
==========================================
  Files         365      365              
  Lines       48247    48243       -4     
==========================================
+ Hits        35466    35470       +4     
+ Misses      12781    12773       -8     
Impacted Files Coverage Δ
include/cantera/base/global.h 93.33% <ø> (ø)
src/base/global.cpp 74.54% <0.00%> (-0.69%) ⬇️
src/base/AnyMap.cpp 89.83% <0.00%> (-0.70%) ⬇️
src/thermo/PengRobinson.cpp 88.26% <0.00%> (-0.41%) ⬇️
src/thermo/Species.cpp 98.90% <0.00%> (-0.02%) ⬇️
include/cantera/base/AnyMap.h 100.00% <0.00%> (ø)
test/thermo/PengRobinson_Test.cpp 100.00% <0.00%> (ø)
test/thermo/RedlichKwongMFTP_Test.cpp 100.00% <0.00%> (ø)
src/transport/GasTransport.cpp 87.52% <0.00%> (+0.16%) ⬆️
src/thermo/RedlichKwongMFTP.cpp 84.91% <0.00%> (+1.42%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e2a33d...0e8791a. Read the comment docs.

@bryanwweber
Copy link
Member Author

I should also note that modifying setup.py in the way that's done in bb094f5 removes the fixes that were previously in place for the bdist_msi builder. I don't think we need the MSI installers for Python anymore, in preference for the wheels.

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty reasonable to me, overall. I agree with the idea of moving the wheel builds to a separate repo where those builds only run after updates to select branches (main and 2.5). This might be a good opportunity to set up the conda builds to do something similar.

.github/workflows/python-package.yml Outdated Show resolved Hide resolved
.github/workflows/python-package.yml Outdated Show resolved Hide resolved
SConstruct Outdated Show resolved Hide resolved
interfaces/python_minimal/setup.cfg.in Outdated Show resolved Hide resolved
src/SConscript Outdated Show resolved Hide resolved
ext/SConscript Show resolved Hide resolved
interfaces/cython/SConscript Outdated Show resolved Hide resolved
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked over it and don't have anything substantial to add here. Found occasional single quotes (e.g. SConstruct, line 385); perhaps generate_license could build strings using f-strings, but it's ultimately inconsequential.

@bryanwweber bryanwweber force-pushed the add-pypi-package branch 3 times, most recently from 9a7692b to 20a2156 Compare November 22, 2021 01:35
@@ -1896,12 +1911,10 @@ def postBuildMessage(target, source, env):
print("- To run the test suite, type 'scons test'.")
print("- To list available tests, type 'scons test-help'.")
if env['googletest'] == 'none':
print(" WARNING: You set the 'googletest' to 'none' and all it's tests will be skipped.")
print(" WARNING: You set the 'googletest' to 'none' and all its tests will be skipped.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be issued by logger? (Although the same applies to the surrounding lines, so replacing things just here would be odd.)

Copy link
Member Author

@bryanwweber bryanwweber Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ideally it should. I just couldn't help fixing this typo 🤪 I'm still hoping to eventually be able to refactor this file to use those features I added in buildutils.py. I think the changes from #1137 are a great step in the right direction too!

@bryanwweber bryanwweber force-pushed the add-pypi-package branch 3 times, most recently from 0c2d76b to 94eb9d8 Compare November 22, 2021 19:37
Use a dictionary to collect the license file paths and names. This data
structure is more natural for this mapping of packages to files. It also
simplifies the loop to collect the files.
Add a new option for the Python package to build a source distribution.
It is added as a new interface to simplify copying files. All of the
Cantera plus external library source code is copied into the interface
folder for building.

Actually building the source distribution is handled by the 'build'
package, which becomes a new dependency to build the sdist. 'build'
handles installing all the build-time dependencies in an isolated
environment using specifications in pyproject.toml.
This is the same mechanism as employed for config.h in the main
SConstruct. It's needed here to avoid repeatedly copying the include
directory into the sdist, which fails due to the existing directory.
The function is not used anywhere within Cantera. When this function is
removed, the CANTERA_ROOT define in config.h can be removed as well.
The sysconfig module is available since Python 3.2. Distutils is
deprecated and slated for removal from Python in the next few years.
Likewise, the "SO" config variable has been deprecated for some time and
was slated for removal in Python 3.8, although that seems not to have
happened.
The bug was fixed in Python 3.7.3, so it no longer required.
This change mirrors the one for the source distribution. This change
results in a non-executable template file
(setup.cfg.in), which makes edits easier.

This change
removes the requirement to template the Python extension into setup.py,
and adds a Setuptools extension module. This results in correct builds
when bdist_wheel is specified and uses package_data properly.
This change provides similar benefits as for the other two Python
distributions. It should allow easier uploading to PyPI and now includes
the README and License files.
For some versions of Python, the DLL module extension included in the
sysconfig module is not correct. In that case, the file extension needs
to be constructed manually.

To make this information easier to get to, the JSON module is used to
parse data returned by sysconfig from the Python which will be building
the module.
@bryanwweber
Copy link
Member Author

@speth / @ischoegl This is ready for another review. All the builds are passing now over here: https://github.com/bryanwweber/cantera/actions/runs/1505864912 Note that the last commit on this branch should be dropped before merging to main, so that the wheel builds can move to another repo

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 ... thanks for your work on this, @bryanwweber. As mentioned earlier, packaging is not necessarily something I'm familiar with, but the coding itself looks fine to me. The only broader question I have is whether the wheels get tested before shipping (i.e. unit tests). I guess that they should 'just work', but then you never know ... .

PS: I noticed that you started building for Python 3.10 ... would it make sense to add this to the regular CI?

@bryanwweber
Copy link
Member Author

bryanwweber commented Nov 26, 2021

The only broader question I have is whether the wheels get tested before shipping (i.e. unit tests). I guess that they should 'just work', but then you never know ...

Great question 😊 I just added testing of the wheels with these updates, the CIBW_TEST_COMMAND runs pytest in a virtualenv with the Cantera wheel installed. That was how I caught the missing .parent in the __init__.py file 😃

PS: I noticed that you started building for Python 3.10 ... would it make sense to add this to the regular CI?

Yeah, we definitely should. Do you want to add that in your Intel PR, or shall I add it here?

@ischoegl
Copy link
Member

Do you want to add that in your Intel PR, or shall I add it here?

Go ahead and add it here. The Intel PR is a little thorny ... while compilation works, I'm not sure why those tests are failing.

@bryanwweber
Copy link
Member Author

Go ahead and add it here.

I'll add a separate PR, to simplify review.

@bryanwweber bryanwweber mentioned this pull request Nov 26, 2021
13 tasks
speth
speth previously approved these changes Nov 26, 2021
Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @bryanwweber. I don't have any further comments on this. Do you want to drop the final commit now so this can be merged?

@bryanwweber
Copy link
Member Author

@speth All set, I guess we'll have to wait for the checks to run again, and I think you have to do another "approve" checkmark.

@speth speth merged commit 7f35015 into Cantera:main Nov 26, 2021
@bryanwweber bryanwweber deleted the add-pypi-package branch August 2, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Install via pip
3 participants