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

GH-37929: [Python] begin moving static settings to pyproject.toml #41041

Merged
merged 26 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bdb87f2
GH-37929: [Python] begin moving static settings to pyproject.toml
anjakefala Apr 5, 2024
608cbb2
GH-37929: [Python][CI] ensure setuptools/setuptools_scm are the high …
anjakefala Apr 25, 2024
63d04ae
Remove unnecessary configuration
anjakefala May 2, 2024
62ce04d
Cleanup and add non-optional test dependencies
anjakefala May 17, 2024
4259cf7
setup.py sdist is now deprecated
anjakefala May 17, 2024
15c5c7a
Update to use python3 -m build --sdist
anjakefala May 17, 2024
327dd38
Add build as a dependency in CI
anjakefala May 17, 2024
3fccbd2
Revert "setup.py sdist is now deprecated"
anjakefala May 18, 2024
2b5a063
Revert "Update to use python3 -m build --sdist"
anjakefala May 18, 2024
9d6eaf2
Revert "Add build as a dependency in CI"
anjakefala May 18, 2024
f5fb1ed
Update python/pyproject.toml
jorisvandenbossche May 22, 2024
74d0f29
Change tests to modify/refer to fallback_version in pyproject.toml
anjakefala May 27, 2024
50f8f3e
Update tests for prepare release and bump_versions
raulcd May 28, 2024
83140a3
Use python setup.py build_ext --inplace instead of setup.py develop o…
raulcd May 28, 2024
d9bd3ce
Use the same command to build than the one used on python_build.sh
raulcd May 28, 2024
11e0a32
Add missing required numpy to install_requires options
raulcd May 28, 2024
07489af
Add missing quotes and format
raulcd May 28, 2024
b04b1fa
Install wheel requirement for minimal env examples, update pytest
raulcd May 28, 2024
482eac1
Add -e to installation
raulcd May 29, 2024
3e82475
Revert back to use Ubuntu:focal
raulcd May 29, 2024
2c879c6
Properly define required numpy dependency on project
raulcd May 29, 2024
2c343e6
Get out of arrow/python directory to not require editable mode instal…
raulcd May 29, 2024
6f75c2b
Remove unnecessary test_require and test_suite from setup.py
raulcd May 29, 2024
9adab26
Add pandas as a test dependency
anjakefala May 30, 2024
50a35c1
Remove wheel from build-system.requires
raulcd Jun 3, 2024
24054ef
add back install wheel
jorisvandenbossche Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
shell: bash
run: |
gem install test-unit
pip install "cython>=0.29.31" setuptools six pytest jira
pip install "cython>=0.29.31" setuptools six pytest jira setuptools-scm
anjakefala marked this conversation as resolved.
Show resolved Hide resolved
- name: Run Release Test
env:
ARROW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions ci/conda_env_python.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ numpy>=1.16.6
pytest
pytest-faulthandler
s3fs>=2023.10.0
setuptools
setuptools_scm
setuptools>=64
setuptools_scm>=8
6 changes: 3 additions & 3 deletions dev/release/01-prepare-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ def test_version_pre_tag
],
},
{
path: "python/setup.py",
path: "python/pyproject.toml",
hunks: [
["-default_version = '#{@snapshot_version}'",
"+default_version = '#{@release_version}'"],
["-fallback_version = '#{@release_version}a0'",
"+fallback_version = '#{@release_version}'"],
],
},
{
Expand Down
6 changes: 3 additions & 3 deletions dev/release/post-11-bump-versions-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def test_version_post_tag
],
},
{
path: "python/setup.py",
path: "python/pyproject.toml",
hunks: [
["-default_version = '#{@snapshot_version}'",
"+default_version = '#{@next_snapshot_version}'"],
["-fallback_version = '#{@release_version}a0'",
"+fallback_version = '#{@next_version}a0'"],
],
},
{
Expand Down
10 changes: 6 additions & 4 deletions dev/release/utils-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ update_versions() {
release)
local version=${base_version}
local r_version=${base_version}
local python_version=${base_version}
;;
snapshot)
local version=${next_version}-SNAPSHOT
local r_version=${base_version}.9000
local python_version=${next_version}a0
;;
esac
local major_version=${version%%.*}
Expand Down Expand Up @@ -126,10 +128,10 @@ update_versions() {

pushd "${ARROW_DIR}/python"
sed -i.bak -E -e \
"s/^default_version = '.+'/default_version = '${version}'/" \
setup.py
rm -f setup.py.bak
git add setup.py
"s/^fallback_version = '.+'/fallback_version = '${python_version}'/" \
pyproject.toml
rm -f pyproject.toml.bak
git add pyproject.toml
sed -i.bak -E -e \
"s/^set\(PYARROW_VERSION \".+\"\)/set(PYARROW_VERSION \"${version}\")/" \
CMakeLists.txt
Expand Down
2 changes: 1 addition & 1 deletion dev/tasks/python-minimal-build/github.linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
{{ macros.github_set_env(env) }}
steps:
{{ macros.github_checkout_arrow(submodules=false)|indent }}
{{ macros.github_checkout_arrow(fetch_depth=0, submodules=false)|indent }}
raulcd marked this conversation as resolved.
Show resolved Hide resolved

- name: Run minimal build example
run: |
Expand Down
3 changes: 2 additions & 1 deletion python/examples/minimal_build/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

FROM ubuntu:focal
FROM ubuntu:jammy
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason for this change? (I don't care to be clear, but I don't know how our general coverage is of ubuntu versions, and we should probably still test somewhere with focal)

Copy link
Member

Choose a reason for hiding this comment

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

We are already testing Ubuntu 20.04 on test-ubuntu-20.04-python-3 .
I did update the minimal_build to 22.04 because there was a minor issue building and was easier to update than investigate to fix it and as we are already testing 20.04 I knew it was a CI set-up. I could investigate but I do think that we have to start updating our default jobs to 22.04 so I preferred to update it.


ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -32,6 +32,7 @@ RUN apt-get update -y -q && \
python3-dev \
python3-pip \
python3-venv \
tzdata \
&& \
apt-get clean && rm -rf /var/lib/apt/lists*

Expand Down
9 changes: 4 additions & 5 deletions python/examples/minimal_build/build_conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ export CMAKE_PREFIX_PATH=${ARROW_HOME}${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}
export PYARROW_BUILD_TYPE=Debug
export PYARROW_CMAKE_GENERATOR=Ninja

# You can run either "develop" or "build_ext --inplace". Your pick

# python setup.py build_ext --inplace
python setup.py develop
# Use the same command that we use on python_build.sh
python -m pip install --no-deps --no-build-isolation -vv .
popd

py.test pyarrow
pytest -vv -r s ${PYTEST_ARGS} --pyargs pyarrow
11 changes: 6 additions & 5 deletions python/examples/minimal_build/build_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# specific language governing permissions and limitations
# under the License.

set -e
set -ex

#----------------------------------------------------------------------
# Change this to whatever makes sense for your system
Expand All @@ -35,6 +35,7 @@ source $WORKDIR/venv/bin/activate
git config --global --add safe.directory $ARROW_ROOT

pip install -r $ARROW_ROOT/python/requirements-build.txt
pip install wheel
Copy link
Member

Choose a reason for hiding this comment

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

Is this addition still needed? (my understanding is that pip install should not need it, since we also don't list it as a build dependency)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see we actually do list wheel as a build requirement ;) But I think nowadays the recommendation is not list wheel explicitly.
While I can't find an explicit reference for this, the original PEP text included wheel in the simple example (https://peps.python.org/pep-0518/#build-system-table), but the examples for using setuptools in the packaging guide or on the setuptools documentation (https://setuptools.pypa.io/en/latest/userguide/quickstart.html#basic-use) no longer include wheel.

So I think we should remove wheel from build-system.requires

Copy link
Member

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

@jorisvandenbossche It seems wheel is required otherwise we get the following failure:

 Processing /arrow/python
  Added file:///arrow/python to build tracker '/tmp/pip-req-tracker-grmxa_d3'
  Created temporary directory: /tmp/pip-modern-metadata-sclz_5km
  Preparing metadata (pyproject.toml): started
  Running command Preparing metadata (pyproject.toml)
  <string>:34: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  running dist_info
  creating /tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info
  writing /tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/PKG-INFO
  writing dependency_links to /tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/dependency_links.txt
  writing requirements to /tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/requires.txt
  writing top-level names to /tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/top_level.txt
  writing manifest file '/tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no previously-included files matching '*.so' found anywhere in distribution
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files matching '*~' found anywhere in distribution
  warning: no previously-included files matching '#*' found anywhere in distribution
  warning: no previously-included files matching '.DS_Store' found anywhere in distribution
  no previously-included directories found matching '.asv'
  adding license file '../LICENSE.txt'
  adding license file '../NOTICE.txt'
  writing manifest file '/tmp/pip-modern-metadata-sclz_5km/pyarrow.egg-info/SOURCES.txt'
  creating '/tmp/pip-modern-metadata-sclz_5km/pyarrow-17.0.0.dev252+g50a35c1b1.dist-info'
  error: invalid command 'bdist_wheel'
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

See: https://github.com/ursacomputing/crossbow/actions/runs/9348063637/job/25726407074

Copy link
Member

Choose a reason for hiding this comment

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

Ah, OK, diving in a bit more to understand what is happening: this is because we are using --no-build-isolation here. So it seems that setuptools will (in normal, isolated mode) automatically inject wheel as a dependency when building a wheel, but so that doesn't happen in non-isolated mode.

So it's still a good change to exlude wheel from the build requirements in pyproject.toml, but then we need to add it to the environments that use --no-build-isolation.

Note that explains this a bit in the setuptools docs (https://setuptools.pypa.io/en/latest/userguide/quickstart.html#basic-use):

Historically this documentation has unnecessarily listed wheel
in the requires list, and many projects still do that. This is
not recommended, as the backend no longer requires the wheel
package, and listing it explicitly causes it to be unnecessarily
required for source distribution builds.
You should only include wheel in requires if you need to explicitly
access it during build time (e.g. if your project needs a setup.py
script that imports wheel).

Copy link
Member

Choose a reason for hiding this comment

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

So it's still a good change to exlude wheel from the build requirements in pyproject.toml,

I may have missed something but is it really useful to exclude it from the build requirements? It's a pure Python package with zero non-trivial dependency, AFAICT.

Copy link
Member

Choose a reason for hiding this comment

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

For example:

$ pip list
Package    Version
---------- -------
pip        24.0
setuptools 59.6.0
$ pip install wheel
Collecting wheel
  Using cached wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
Using cached wheel-0.43.0-py3-none-any.whl (65 kB)
Installing collected packages: wheel
Successfully installed wheel-0.43.0

Copy link
Member

Choose a reason for hiding this comment

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

That's the recommendation from setuptools ..
(I agree it shouldn't hurt given it's an easy to install package, although I also noticed in the setuptools tracker that the next version of setuptools will actually remove wheel usage all together)


#----------------------------------------------------------------------
# Build C++ library
Expand Down Expand Up @@ -68,11 +69,11 @@ export CMAKE_PREFIX_PATH=${ARROW_HOME}${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}
export PYARROW_BUILD_TYPE=Debug
export PYARROW_CMAKE_GENERATOR=Ninja

# You can run either "develop" or "build_ext --inplace". Your pick
# Use the same command that we use on python_build.sh
python -m pip install --no-deps --no-build-isolation -vv .

# python setup.py build_ext --inplace
python setup.py develop
popd

pip install -r $ARROW_ROOT/python/requirements-test.txt

py.test pyarrow
pytest -vv -r s ${PYTEST_ARGS} --pyargs pyarrow
62 changes: 59 additions & 3 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,63 @@ requires = [
# continue using oldest-support-numpy.
"oldest-supported-numpy>=0.14; python_version<'3.9'",
"numpy>=1.25; python_version>='3.9'",
"setuptools_scm",
"setuptools >= 40.1.0",
"wheel"
# configuring setuptools_scm in pyproject.toml requires
# versions released after 2022
"setuptools_scm[toml]>=8",
"setuptools>=64",
]
build-backend = "setuptools.build_meta"

[project]
name = "pyarrow"
dynamic = ["version"]
requires-python = ">=3.8"
dependencies = [
"numpy >= 1.16.6"
]
description = "Python library for Apache Arrow"
readme = {file = "README.md", content-type = "text/markdown"}
license = {text = "Apache Software License"}
classifiers = [
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Langauge :: Python :: 3.12',
]
maintainers = [
{name = "Apache Arrow Developers", email = "[email protected]"}
]

[project.urls]
Homepage = "https://arrow.apache.org/"
Documentation = "https://arrow.apache.org/docs/python"
Repository = "https://github.com/apache/arrow"
Issues = "https://github.com/apache/arrow/issues"

[project.optional-dependencies]
test = [
'pytest',
'hypothesis',
'cffi',
'pytz',
'pandas'
]

[tool.setuptools]
zip-safe=false
include-package-data=true

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools.package-data]
pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]

[tool.setuptools_scm]
root = '..'
version_file = 'pyarrow/_generated_version.py'
version_scheme = 'guess-next-dev'
git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
raulcd marked this conversation as resolved.
Show resolved Hide resolved
fallback_version = '17.0.0a0'
4 changes: 2 additions & 2 deletions python/requirements-build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cython>=0.29.31
oldest-supported-numpy>=0.14; python_version<'3.9'
numpy>=1.25; python_version>='3.9'
setuptools_scm
setuptools>=38.6.0
setuptools_scm>=8
setuptools>=64
85 changes: 0 additions & 85 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,61 +352,11 @@ def get_outputs(self):
for name in self.get_names()]


# If the event of not running from a git clone (e.g. from a git archive
# or a Python sdist), see if we can set the version number ourselves
default_version = '17.0.0-SNAPSHOT'
if (not os.path.exists('../.git') and
not os.environ.get('SETUPTOOLS_SCM_PRETEND_VERSION')):
os.environ['SETUPTOOLS_SCM_PRETEND_VERSION'] = \
default_version.replace('-SNAPSHOT', 'a0')


# See https://github.com/pypa/setuptools_scm#configuration-parameters
scm_version_write_to_prefix = os.environ.get(
'SETUPTOOLS_SCM_VERSION_WRITE_TO_PREFIX', setup_dir)


def parse_git(root, **kwargs):
"""
Parse function for setuptools_scm that ignores tags for non-C++
subprojects, e.g. apache-arrow-js-XXX tags.
"""
from setuptools_scm.git import parse
kwargs['describe_command'] =\
'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
return parse(root, **kwargs)


def guess_next_dev_version(version):
if version.exact:
return version.format_with('{tag}')
else:
def guess_next_version(tag_version):
return default_version.replace('-SNAPSHOT', '')
return version.format_next_version(guess_next_version)


with open('README.md') as f:
long_description = f.read()


class BinaryDistribution(Distribution):
def has_ext_modules(foo):
return True


install_requires = (
'numpy >= 1.16.6',
)


# Only include pytest-runner in setup_requires if we're invoking tests
if {'pytest', 'test', 'ptr'}.intersection(sys.argv):
setup_requires = ['pytest-runner']
else:
setup_requires = []


if strtobool(os.environ.get('PYARROW_INSTALL_TESTS', '1')):
packages = find_namespace_packages(include=['pyarrow*'])
exclude_package_data = {}
Expand All @@ -420,47 +370,12 @@ def has_ext_modules(foo):


setup(
name='pyarrow',
packages=packages,
zip_safe=False,
package_data={'pyarrow': ['*.pxd', '*.pyx', 'includes/*.pxd']},
include_package_data=True,
exclude_package_data=exclude_package_data,
distclass=BinaryDistribution,
# Dummy extension to trigger build_ext
ext_modules=[Extension('__dummy__', sources=[])],
cmdclass={
'build_ext': build_ext
},
use_scm_version={
'root': os.path.dirname(setup_dir),
'parse': parse_git,
'write_to': os.path.join(scm_version_write_to_prefix,
'pyarrow/_generated_version.py'),
'version_scheme': guess_next_dev_version
},
setup_requires=['setuptools_scm', 'cython >= 0.29.31'] + setup_requires,
install_requires=install_requires,
tests_require=['pytest', 'pandas', 'hypothesis'],
python_requires='>=3.8',
description='Python library for Apache Arrow',
long_description=long_description,
long_description_content_type='text/markdown',
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
license='Apache License, Version 2.0',
maintainer='Apache Arrow Developers',
maintainer_email='[email protected]',
test_suite='pyarrow.tests',
url='https://arrow.apache.org/',
project_urls={
'Documentation': 'https://arrow.apache.org/docs/python',
'Source': 'https://github.com/apache/arrow',
},
)
Loading