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

Support Python packaging #1720

Merged
merged 45 commits into from
Dec 2, 2022
Merged

Conversation

DropD
Copy link
Contributor

@DropD DropD commented Jul 14, 2022

Currently in proof of concept mode. Uses skbuild to install the gridtools headers and cmake files into the pip package's data folder.

Missing in order to be considered for merging:

Feedback would be nice on:

  • How many more infrastructure files are acceptable? (non-issue, now that all is contained int a subdirectory)
  • Is it worth it to explore if the whole root of the python package can be nested away (might be complicated)? (turns out to be easy)

@havogt
Copy link
Contributor

havogt commented Jul 14, 2022

Is it worth it to explore if the whole root of the python package can be nested away (might be complicated)?

I had exactly the same question. Would be nice if we could put everything in a subdirectory. Where do you see problems? Pointing pip into the subdirectory?

@DropD
Copy link
Contributor Author

DropD commented Jul 14, 2022

Is it worth it to explore if the whole root of the python package can be nested away (might be complicated)?

I had exactly the same question. Would be nice if we could put everything in a subdirectory. Where do you see problems? Pointing pip into the subdirectory?

That (I have never tried yet), and there may be problems also in getting setuptools to include files from a parent directory of setup.py in the package. It's not a lot of work to try though.

@DropD
Copy link
Contributor Author

DropD commented Jul 14, 2022

Is it worth it to explore if the whole root of the python package can be nested away (might be complicated)?

I had exactly the same question. Would be nice if we could put everything in a subdirectory. Where do you see problems? Pointing pip into the subdirectory?

That (I have never tried yet), and there may be problems also in getting setuptools to include files from a parent directory of setup.py in the package. It's not a lot of work to try though.

Nope, worked first try (non-rigorously tested on my setup). The syntax for requiring the package is

install_requires =
    ...
    gridtools@git+https://github.com/DropD/gridtools.git@make-pip-installable#egg=subdir&subdirectory=pylibgt
    ...

@petiaccja
Copy link
Contributor

Is it not possible to put all the Python package related files into a separate repo and reference GridTools zips from GitHub releases from there? Then we wouldn't have to put anything into the main GridTools repo, although I'm not sure if this is what we want at all.

@DropD
Copy link
Contributor Author

DropD commented Jul 15, 2022

Is it not possible to put all the Python package related files into a separate repo and reference GridTools zips from GitHub releases from there? Then we wouldn't have to put anything into the main GridTools repo, although I'm not sure if this is what we want at all.

Should be possible. The cmake pypi distro is done like that. It only makes sense, though, if we get something back for the added complexity. Do you see any benefits?

In terms of added complexity, how would you request a specific version (commit) of the gridtools library if the python package is decoupled like that?

Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

I'd prefer .pip as a directory, but I think it makes sense to keep it here.

pylibgt/setup.py Outdated Show resolved Hide resolved
pylibgt/setup.py Outdated Show resolved Hide resolved
@DropD DropD marked this pull request as ready for review August 2, 2022 12:18
@DropD DropD requested a review from havogt August 3, 2022 14:36
pylibgt/MANIFEST.in Outdated Show resolved Hide resolved
pylibgt/py_src/gridtools/__init__.py Outdated Show resolved Hide resolved
pylibgt/setup.py Outdated Show resolved Hide resolved
pylibgt/noxfile.py Outdated Show resolved Hide resolved
pylibgt/setup.py Outdated Show resolved Hide resolved
pylibgt/py_src/gridtools/__init__.py Outdated Show resolved Hide resolved
pylibgt/setup.py Outdated Show resolved Hide resolved
pylibgt/pyproject.toml Outdated Show resolved Hide resolved
@DropD DropD requested a review from egparedes November 24, 2022 14:20
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

Basically ready to go. Just added some minor questions and suggestions

session.log("installed gridttols sources")
version_path = source_path / "version.txt"
setup_path = pathlib.Path(".") / "setup.cfg"
config = configparser.ConfigParser()
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably you're already aware, but configparser removes all comments and formatting from the original file. It's not very important in this case, though, but it is not nice. The only alternative I know which preserves format is ConfigUpdate (https://pypi.org/project/ConfigUpdater/) but is a third-party project

prepare(session)
dist_path = session.cache_dir.joinpath("dist").absolute()
workdir = pathlib.Path(".").absolute()
session.install("build[virtualenv]")
Copy link
Contributor

@egparedes egparedes Nov 25, 2022

Choose a reason for hiding this comment

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

Just a comment, maybe it would be good to add all packages used or installed here (build, cmake, ...) to the list of build_system.requires in pyproject.toml to make the dependencies explicit.

Copy link
Contributor Author

@DropD DropD Nov 25, 2022

Choose a reason for hiding this comment

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

We could add them for documentation purposes, even they are not build requirements anymore. They are pre-build requirements. In the PEP-517 conformant isolated build environment, they don't have to be present.

A compromise might be to add them commented-out, I guess?

name = gridtools-cpp
author = ETH Zurich
author_email = gridtools@cscs.ch
license_files = LICENSE
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to add a comment here to document the fact that the License file is being copied in the building process... (but configparser would delete the comment later 😓 )

project_urls =
Source Code = https://github.com/GridTools/gridtools
platforms = any
version = 2.2.1a2
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, I would like to add a comment here to document the fact that the version is actually updated from the main gridtools version file... (but configparser would delete the comment later 😓 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can solve these by generating setup.cfg from setup.cfg.in, which would have the comments. Only question is whether setup.cfg should still be versioned (since it has tool config as well).

Comment on lines 15 to 19
Development Status :: 5 - Production/Stable
License :: OSI Approved :: BSD License
Intended Audience :: Science/Research
Operating System :: OS Independent
Programming Language :: Python :: 3 :: Only
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, sort the classifiers alphabetically. Optionally, you might want to add the same topic classifiers used in gt4py:

    Topic :: Scientific/Engineering :: Atmospheric Science
    Topic :: Scientific/Engineering :: Mathematics
    Topic :: Scientific/Engineering :: Physics


[options.package_data]
* =
*.hpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Also optional, we could add the license file to the package sources, since the python package is some kind or source distribution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already included in the distribution. Can be found after install in the usual location .../site-packages/gridtools_cpp-XXX.dist-info/LICENSE.

.python_package/src/gridtools/__init__.py Outdated Show resolved Hide resolved
@DropD DropD requested a review from havogt November 25, 2022 13:47
Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

Minor readme changes.

.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
.python_package/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@havogt havogt left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@havogt havogt requested a review from egparedes December 2, 2022 15:43
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

It looks good.

@havogt havogt merged commit e732a64 into GridTools:master Dec 2, 2022
havogt pushed a commit to havogt/gridtools that referenced this pull request Dec 12, 2022
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.

6 participants