Skip to content

Commit

Permalink
Migrate package build to python-build
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzEeKkAa committed May 1, 2024
1 parent 86056f6 commit 26f0ceb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 28 deletions.
45 changes: 34 additions & 11 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ set "DPBENCH_SYCL=1"
set "CMAKE_GENERATOR=Ninja"
set "CC=icx"
set "CXX=icx"

"%PYTHON%" setup.py clean --all
:: Make CMake verbose
set "VERBOSE=1"

FOR %%V IN (14.0.0 14 15.0.0 15 16.0.0 16 17.0.0 17) DO @(
REM set DIR_HINT if directory exists
Expand All @@ -41,18 +41,41 @@ if EXIST "%PLATFORM_DIR%" (
if errorlevel 1 exit 1
)

@REM TODO: switch to pip build. Currently results in broken binary
@REM %PYTHON% -m pip install --no-index --no-deps --no-build-isolation . -v
:: -wnx flags mean: --wheel --no-isolation --skip-dependency-check
%PYTHON% -m build -w -n -x
if %ERRORLEVEL% neq 0 exit 1

:: `pip install dist\dpbench*.whl` does not work on windows,
:: so use a loop; there's only one wheel in dist/ anyway
for /f %%f in ('dir /b /S .\dist') do (
%PYTHON% -m wheel tags --remove --build %GIT_DESCRIBE_NUMBER% %%f
if %ERRORLEVEL% neq 0 exit 1
)

:: wheel file was renamed
for /f %%f in ('dir /b /S .\dist') do (
%PYTHON% -m pip install %%f ^
--no-build-isolation ^
--no-deps ^
--only-binary :all: ^
--no-index ^
--prefix %PREFIX% ^
-vv
if %ERRORLEVEL% neq 0 exit 1
)

:: Must be consistent with pyproject.toml project.scritps. Currently pip does
:: not allow to ignore scripts installation, so we have to remove them manually.
:: https://github.com/pypa/pip/issues/3980
:: We have to let conda-build manage it for use in order to set proper python
:: path.
:: https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#python-entry-points
rm %PREFIX%\Scripts\dpbench.exe

:: Copy wheel package
if NOT "%WHEELS_OUTPUT_FOLDER%"=="" (
rem Install and assemble wheel package from the build bits
"%PYTHON%" setup.py install --single-version-externally-managed --record=record.txt bdist_wheel --build-number %GIT_DESCRIBE_NUMBER%
if errorlevel 1 exit 1
copy dist\dpbench*.whl %WHEELS_OUTPUT_FOLDER%
if errorlevel 1 exit 1
) ELSE (
rem Only install
"%PYTHON%" setup.py install --single-version-externally-managed --record=record.txt
if errorlevel 1 exit 1
)

rem copy back
Expand Down
34 changes: 23 additions & 11 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ export CMAKE_GENERATOR="Ninja"
export CC=icx
export CXX=icpx

if [ -e "_skbuild" ]; then
${PYTHON} setup.py clean --all
fi

# TODO: switch to pip build. Currently results in broken binary on Windows
# $PYTHON -m pip install --no-index --no-deps --no-build-isolation . -v

# Build wheel package
if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then
$PYTHON setup.py install --single-version-externally-managed --record=record.txt bdist_wheel -p manylinux2014_x86_64 --build-number $GIT_DESCRIBE_NUMBER
mkdir -p ${WHEELS_OUTPUT_FOLDER}
cp dist/dpbench*.whl ${WHEELS_OUTPUT_FOLDER}
else
$PYTHON setup.py install --single-version-externally-managed --record=record.txt
# -wnx flags mean: --wheel --no-isolation --skip-dependency-check
${PYTHON} -m build -w -n -x
${PYTHON} -m wheel tags --remove --build "$GIT_DESCRIBE_NUMBER" \
--platform-tag manylinux2014_x86_64 dist/dpbench*.whl
${PYTHON} -m pip install dist/dpbench*.whl \
--no-build-isolation \
--no-deps \
--only-binary :all: \
--no-index \
--prefix ${PREFIX} \
-vv

# Must be consistent with pyproject.toml project.scritps. Currently pip does
# not allow to ignore scripts installation, so we have to remove them manually.
# https://github.com/pypa/pip/issues/3980
# We have to let conda-build manage it for use in order to set proper python
# path.
# https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#python-entry-points
rm ${PREFIX}/bin/dpbench

# Copy wheel package
if [[ -v WHEELS_OUTPUT_FOLDER ]]; then
cp dist/dpbench*.whl "${WHEELS_OUTPUT_FOLDER[@]}"
fi
19 changes: 13 additions & 6 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% set pyproject = load_file_data('pyproject.toml') %}
{% set py_deps = pyproject.get('project', {}).get('dependencies', []) %}
{% set py_build_deps = pyproject.get('build-system', {}).get('requires', []) %}
{% set project_scripts = pyproject.get('project', {}).get('scripts', {}) %}

package:
name: dpbench
Expand All @@ -17,6 +18,10 @@ build:
number: {{ GIT_DESCRIBE_NUMBER }}
script_env:
- WHEELS_OUTPUT_FOLDER
entry_points:
{% for script, module in project_scripts | dictsort %}
- {{ script ~ " = " ~ module }}
{% endfor %}

requirements:
build:
Expand All @@ -26,9 +31,15 @@ requirements:
- sysroot_linux-64 >=2.28 # [linux]
host:
- python
- pip
{% for dep in py_build_deps %}
{% if dep.startswith('ninja') %}
- {{ dep.split(';')[0] }} # [not win]
{% elif dep.startswith('cmake') %}
- cmake=3.26 # [win]
- {{ dep }} # [not win]
{% elif dep.startswith('build>=') %}
- {{ 'python-' ~ dep }}
{% else %}
- {{ dep|replace('_','-') }}
{% endif %}
Expand All @@ -39,12 +50,8 @@ requirements:
{% endfor %}

test:
requires:
- dpctl
- dpnp
- numba-dpex
- numba
- numpy
commands:
- dpbench --help

about:
home: https://github.com/IntelPython/dpbench
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ expected-failure = ["tomlkit"]
"Homepage" = "https://https://github.com/IntelPython/dpbench"

[project.scripts]
# Keep consistent with conda build scripts
dpbench = "dpbench.console.entry:main"

[build-system]
# TODO: make it optional for no sycl build. Workaround: `--no-deps`.
# https://github.com/scikit-build/scikit-build/issues/981
requires = [
"wheel>=0.43",
"build>=1.1",
"setuptools>=63.0.0",
"scikit-build>=0.17.0", # sycl build dep
"ninja>=1.11.1; platform_system!='Windows'", # sycl build dep
Expand Down

0 comments on commit 26f0ceb

Please sign in to comment.