update publish python package script

This commit is contained in:
Jincheng Chen 2021-11-23 11:37:18 +00:00
Родитель a4cda351af
Коммит a284dee39f
5 изменённых файлов: 176 добавлений и 7 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -1,4 +1,5 @@
build
compile
*egg-info
dist
*.so

Просмотреть файл

@ -40,7 +40,7 @@ To install LightGBM transform version, you could simply run following command:
.. code::
pip install lightgbm-transform==3.3.1
pip install lightgbm-transform
Alternatively, you could publish your own package with following commands:
@ -48,7 +48,6 @@ Alternatively, you could publish your own package with following commands:
git clone --recursive https://github.com/microsoft/lightgbm-transform/
cd lightgbm-transform
# change version and package name in ./external_libs/LightGBM/python-package manually
# install twine first
sh ./scripts/publish_python_package.sh

53
scripts/README.rst Normal file
Просмотреть файл

@ -0,0 +1,53 @@
LightGBM Feature Transformation Binding Python-package
======================================================
|License| |Python Versions| |PyPI Version| |API Docs|
Installation
------------
Preparation
'''''''''''
32-bit Python is not supported. Please install 64-bit version. If you have a strong need to install with 32-bit Python, refer to `Build 32-bit Version with 32-bit Python section <#build-32-bit-version-with-32-bit-python>`__.
`setuptools <https://pypi.org/project/setuptools>`_ is needed.
Install from `PyPI <https://pypi.org/project/lightgbm-transform>`_
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
.. code:: sh
pip install lightgbm-transform
You may need to install `wheel <https://pythonwheels.com>`_ via ``pip install wheel`` first.
Compiled library that is included in the wheel file supports **LightGBM MPI** versions out of the box.
Troubleshooting
---------------
In case you are facing any errors during the installation process, you can examine ``$HOME/LightGBM_compilation.log`` file, in which all operations are logged, to get more details about occurred problem. Also, please attach this file to the issue on GitHub to help faster indicate the cause of the error.
Refer to `FAQ <https://github.com/microsoft/LightGBM/tree/master/docs/FAQ.rst>`_.
Examples
--------
Refer to the walk through examples in `Transform tutorial <https://github.com/microsoft/lightgbm-transform/blob/main/docs/Transform-Tutorial.rst>`_.
Development Guide
-----------------
The code style of Python-package follows `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_. If you would like to make a contribution and not familiar with PEP 8, please check the PEP 8 style guide first. Otherwise, the check won't pass. Only E501 (line too long) and W503 (line break occurred before a binary operator) can be ignored.
Documentation strings (docstrings) are written in the NumPy style.
.. |License| image:: https://img.shields.io/github/license/microsoft/lightgbm.svg
:target: https://github.com/microsoft/lightgbm-transform/blob/main/LICENSE
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/lightgbm.svg?logo=python&logoColor=white
:target: https://pypi.org/project/lightgbm-transform
.. |PyPI Version| image:: https://img.shields.io/pypi/v/lightgbm.svg?logo=pypi&logoColor=white
:target: https://pypi.org/project/lightgbm-transform
.. |API Docs| image:: https://readthedocs.org/projects/lightgbm/badge/?version=latest
:target: https://lightgbm.readthedocs.io/en/latest/Python-API.html

Просмотреть файл

@ -2,16 +2,20 @@
lgb_python_pkg_dir="./external_libs/LightGBM/python-package"
# compile transformation, lightgbm, and customized parser libs.
mkdir build
cd build && cmake ../ && make -j4 && cd ../ || exit -1
# precompile mpi option.
cd build && cmake ../ -DUSE_MPI=ON && make -j4 && cd ../ || exit -1
# copy all shared libs to lightgbm python package directory.
cp ./lib_custom_parser.so ${lgb_python_pkg_dir}/lightgbm && \
cp ./src/lib_transform.so ${lgb_python_pkg_dir}/lightgbm && \
cp ./external_libs/LightGBM/lib_lightgbm.so ${lgb_python_pkg_dir}/lightgbm || exit -1
# modify `basic.py` to load all libs first, or cannot find them when calling python interfaces.
cp ${lgb_python_pkg_dir}/lightgbm/basic.py raw && cat ./scripts/load_precompiled_libs.py ${lgb_python_pkg_dir}/lightgbm/basic.py > tmp && cp tmp ${lgb_python_pkg_dir}/lightgbm/basic.py || exit -1
mkdir compile
cp -r ${lgb_python_pkg_dir}/lightgbm ./compile/ && cp ${lgb_python_pkg_dir}/MANIFEST.in ./compile/ || exit -1
cp ./scripts/setup.py ./compile/ && cp ./scripts/README.rst ./compile && cp VERSION.txt ./compile || exit -1
# pack wheel package.
cd ${lgb_python_pkg_dir} && rm -rf dist/ && python setup.py bdist_wheel --precompile && cd ../../../ || exit -1
# revert changes
mv raw ${lgb_python_pkg_dir}/lightgbm/basic.py && rm -rf raw tmp ${lgb_python_pkg_dir}/lightgbm/*.so build || exit -1
cd compile && python setup.py bdist_wheel --precompile && cd ../ || exit -1
# upload package to your pypi, use testpypi as an example.
twine upload --repository testpypi ${lgb_python_pkg_dir}/dist/* || exit -1
twine upload --repository pypi compile/dist/* || exit -1
# revert changes.
mv raw ${lgb_python_pkg_dir}/lightgbm/basic.py && rm -rf raw tmp ${lgb_python_pkg_dir}/lightgbm/*.so build compile || exit -1

112
scripts/setup.py Normal file
Просмотреть файл

@ -0,0 +1,112 @@
"""Setup lightgbm-transform package."""
import logging
import struct
import subprocess
import sys
from os import chdir
from pathlib import Path
from platform import system
from shutil import copyfile, copytree, rmtree
from typing import List, Optional, Union
from setuptools import find_packages, setup
from setuptools.command.install import install
sys.path.insert(0, '../external_libs/LightGBM/python-package')
from setup import LIGHTGBM_OPTIONS, CustomBdistWheel, clear_path
class CustomInstall(install):
user_options = install.user_options + LIGHTGBM_OPTIONS
def initialize_options(self) -> None:
install.initialize_options(self)
self.mingw = False
self.integrated_opencl = False
self.gpu = False
self.cuda = False
self.boost_root = None
self.boost_dir = None
self.boost_include_dir = None
self.boost_librarydir = None
self.opencl_include_dir = None
self.opencl_library = None
self.mpi = False
self.hdfs = False
self.precompile = True
self.nomp = False
self.bit32 = False
def run(self) -> None:
if (8 * struct.calcsize("P")) != 64:
if self.bit32:
logger.warning("You're installing 32-bit version. "
"This version is slow and untested, so use it on your own risk.")
else:
raise Exception("Cannot install LightGBM in 32-bit Python, "
"please use 64-bit Python instead.")
LOG_PATH.touch()
if not self.precompile:
raise Exception("Only precompilation is supported now.")
install.run(self)
if LOG_PATH.is_file():
LOG_PATH.unlink()
if __name__ == '__main__':
CURRENT_DIR = Path(__file__).absolute().parent
LOG_PATH = Path.home() / 'LightGBM_compilation.log'
LOG_NOTICE = f"The full version of error log was saved into {LOG_PATH}"
IS_SOURCE_FLAG_PATH = CURRENT_DIR / '_IS_SOURCE_PACKAGE.txt'
version_path = Path(__file__).parent / "VERSION.txt"
version = version_path.read_text(encoding='utf-8').strip()
readme = (CURRENT_DIR / 'README.rst').read_text(encoding='utf-8')
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('LightGBM')
setup(name='lightgbm-transform',
version=version,
description='LightGBM feature transformation binding python package',
long_description=readme,
install_requires=[
'wheel',
'numpy',
'scipy',
'scikit-learn!=0.22.0'
],
extras_require={
'dask': [
'dask[array]>=2.0.0',
'dask[dataframe]>=2.0.0',
'dask[distributed]>=2.0.0',
'pandas',
],
},
maintainer='Jincheng Chen',
maintainer_email='chjinche@microsoft.com',
zip_safe=False,
cmdclass={
'install': CustomInstall,
'bdist_wheel': CustomBdistWheel,
},
packages=find_packages(),
include_package_data=True,
license='The MIT License (Microsoft)',
url='https://github.com/microsoft/lightgbm-transform',
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering :: Artificial Intelligence'])