Skip to content

Commit

Permalink
[python] Drop Python 2 support (#3581)
Browse files Browse the repository at this point in the history
* Update setup.py

* Update .appveyor.yml

* Update .travis.yml

* Update .vsts-ci.yml

* Update __init__.py

* Update test.sh

* Update test_windows.ps1

* Update advanced_example.py

* Update requirements_base.txt

* Update conf.py

* Update conf.py

* Update test_engine.py

* Update utils.py

* Update dockerfile-r

* Update README.md

* Update dockerfile.gpu

* Update test_consistency.py

* Update basic.py

* Update compat.py

* Update engine.py

* Update sklearn.py

* Update sklearn.py

* Update callback.py

* Update setup.py

* Update __init__.py

* Update plotting.py

* Update sklearn.py

* Update engine.py

* Update compat.py

* Update callback.py

* Update basic.py

* Update compat.py

* Update basic.py

* Update basic.py

* Update compat.py

* Update compat.py

* Update plotting.py

* Update engine.py

* Update basic.py

* Update sklearn.py

* Update compat.py

* Update engine.py

* Update engine.py

* Update callback.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update sklearn.py

* Update sklearn.py

* Update plotting.py

* Update sklearn.py

* Update compat.py

* Update compat.py

* Update engine.py

* Update plotting.py

* Update sklearn.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update compat.py

* Update compat.py

* Update compat.py

* Update engine.py

* Update basic.py

* Update compat.py

* Update basic.py

* Update basic.py

* Update basic.py

* Update compat.py

* Update compat.py

* Update basic.py

* Update basic.py

* Update .vsts-ci.yml

* Update .vsts-ci.yml

* Update conf.py

* Revert "Update dockerfile-r"

This reverts commit 4ff6ffc.
  • Loading branch information
StrikerRUS authored Dec 9, 2020
1 parent 1fb82e2 commit 44a6fb7
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 272 deletions.
1 change: 0 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ install:
- set CONDA_ENV="test-env"
- ps: >-
switch ($env:PYTHON_VERSION) {
"2.7" {$env:MINICONDA = "C:\Miniconda-x64"}
"3.6" {$env:MINICONDA = "C:\Miniconda36-x64"}
"3.7" {$env:MINICONDA = "C:\Miniconda37-x64"}
default {$env:MINICONDA = "C:\Miniconda37-x64"}
Expand Down
10 changes: 5 additions & 5 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ if [[ $TASK == "sdist" ]]; then
exit 0
elif [[ $TASK == "bdist" ]]; then
if [[ $OS_NAME == "macos" ]]; then
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --universal || exit -1
mv dist/lightgbm-$LGB_VER-py2.py3-none-macosx.whl dist/lightgbm-$LGB_VER-py2.py3-none-macosx_10_13_x86_64.macosx_10_14_x86_64.macosx_10_15_x86_64.whl
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --python-tag py3 || exit -1
mv dist/lightgbm-$LGB_VER-py3-none-macosx.whl dist/lightgbm-$LGB_VER-py3-none-macosx_10_13_x86_64.macosx_10_14_x86_64.macosx_10_15_x86_64.whl
if [[ $AZURE == "true" ]]; then
cp dist/lightgbm-$LGB_VER-py2.py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
cp dist/lightgbm-$LGB_VER-py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
fi
else
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=manylinux1_x86_64 --universal || exit -1
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=manylinux1_x86_64 --python-tag py3 || exit -1
if [[ $AZURE == "true" ]]; then
cp dist/lightgbm-$LGB_VER-py2.py3-none-manylinux1_x86_64.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
cp dist/lightgbm-$LGB_VER-py3-none-manylinux1_x86_64.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
fi
fi
pip install --user $BUILD_DIRECTORY/python-package/dist/*.whl || exit -1
Expand Down
2 changes: 1 addition & 1 deletion .ci/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ elseif ($env:TASK -eq "sdist") {
}
elseif ($env:TASK -eq "bdist") {
cd $env:BUILD_SOURCESDIRECTORY/python-package
python setup.py bdist_wheel --plat-name=win-amd64 --universal ; Check-Output $?
python setup.py bdist_wheel --plat-name=win-amd64 --python-tag py3 ; Check-Output $?
cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $?
cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY
} elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) {
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
- PYTHON_VERSION=3.8
matrix:
- TASK=regular PYTHON_VERSION=3.6
- TASK=sdist PYTHON_VERSION=2.7
- TASK=sdist
- TASK=bdist
- TASK=if-else
- TASK=lint
Expand Down
1 change: 0 additions & 1 deletion .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ jobs:
PYTHON_VERSION: 3.6
sdist:
TASK: sdist
PYTHON_VERSION: 2.7
bdist:
TASK: bdist
steps:
Expand Down
5 changes: 2 additions & 3 deletions docker/gpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
# Dockerfile for LightGBM GPU Version with Python

`dockerfile.gpu` - A docker file with LightGBM utilizing nvidia-docker. The file is based on the `nvidia/cuda:8.0-cudnn5-devel` image.
LightGBM can be utilized in GPU and CPU modes and via Python (2.7 & 3.6).
LightGBM can be utilized in GPU and CPU modes and via Python.

## Contents

- LightGBM (cpu + gpu)
- Python 2.7 (conda) + scikit-learn, notebooks, pandas, matplotlib
- Python 3.6 (conda) + scikit-learn, notebooks, pandas, matplotlib
- Python 3.8 (conda) + scikit-learn, notebooks, pandas, matplotlib

Running the container starts a Jupyter Notebook at `localhost:8888`.

Expand Down
4 changes: 1 addition & 3 deletions docker/gpu/dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ RUN echo "export PATH=$CONDA_DIR/bin:"'$PATH' > /etc/profile.d/conda.sh && \
rm ~/miniconda.sh

RUN conda config --set always_yes yes --set changeps1 no && \
conda create -y -q -n py2 python=2.7 mkl numpy scipy scikit-learn jupyter notebook ipython pandas matplotlib && \
conda create -y -q -n py3 python=3.6 mkl numpy scipy scikit-learn jupyter notebook ipython pandas matplotlib
conda create -y -q -n py3 python=3.8 mkl numpy scipy scikit-learn jupyter notebook ipython pandas matplotlib

#################################################################################################################
# LightGBM
Expand All @@ -90,7 +89,6 @@ RUN cd /usr/local/src && mkdir lightgbm && cd lightgbm && \

ENV PATH /usr/local/src/lightgbm/LightGBM:${PATH}

RUN /bin/bash -c "source activate py2 && cd /usr/local/src/lightgbm/LightGBM/python-package && python setup.py install --precompile && source deactivate"
RUN /bin/bash -c "source activate py3 && cd /usr/local/src/lightgbm/LightGBM/python-package && python setup.py install --precompile && source deactivate"

#################################################################################################################
Expand Down
13 changes: 3 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
from docutils.parsers.rst import Directive
from sphinx.errors import VersionRequirementError
from subprocess import PIPE, Popen
from unittest.mock import Mock

CURR_PATH = os.path.abspath(os.path.dirname(__file__))
LIB_PATH = os.path.join(CURR_PATH, os.path.pardir, 'python-package')
sys.path.insert(0, LIB_PATH)

# -- mock out modules
try:
from unittest.mock import Mock # Python 3.x
except ImportError:
from mock import Mock # Python 2.x

MOCK_MODULES = ['numpy', 'scipy', 'scipy.sparse',
'sklearn', 'matplotlib', 'pandas', 'graphviz']
for mod_name in MOCK_MODULES:
Expand Down Expand Up @@ -208,9 +204,7 @@ def generate_doxygen_xml(app):
"WARN_AS_ERROR=YES",
]
doxygen_input = '\n'.join(doxygen_args)
is_py3 = sys.version[0] == "3"
if is_py3:
doxygen_input = bytes(doxygen_input, "utf-8")
doxygen_input = bytes(doxygen_input, "utf-8")
if not os.path.exists(os.path.join(CURR_PATH, 'doxyoutput')):
os.makedirs(os.path.join(CURR_PATH, 'doxyoutput'))
try:
Expand All @@ -221,8 +215,7 @@ def generate_doxygen_xml(app):
process = Popen(["doxygen", "-"],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate(doxygen_input)
output = '\n'.join([i.decode('utf-8') if is_py3 else i
for i in (stdout, stderr) if i is not None])
output = '\n'.join([i.decode('utf-8') for i in (stdout, stderr) if i is not None])
if process.returncode != 0:
raise RuntimeError(output)
else:
Expand Down
1 change: 0 additions & 1 deletion docs/requirements_base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
sphinx
sphinx_rtd_theme >= 0.3
mock; python_version < '3'
5 changes: 1 addition & 4 deletions examples/python-guide/advanced_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# coding: utf-8
import json
import pickle
import lightgbm as lgb
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error

try:
import cPickle as pickle
except BaseException:
import pickle

print('Loading data...')
# load or create your dataset
Expand Down
9 changes: 0 additions & 9 deletions python-package/lightgbm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
Contributors: https://github.com/microsoft/LightGBM/graphs/contributors.
"""
from __future__ import absolute_import

from .basic import Booster, Dataset
from .callback import (early_stopping, print_evaluation, record_evaluation,
reset_parameter)
from .engine import cv, train, CVBooster

import os
import sys
import warnings

try:
from .sklearn import LGBMModel, LGBMRegressor, LGBMClassifier, LGBMRanker
Expand All @@ -36,8 +32,3 @@
'LGBMModel', 'LGBMRegressor', 'LGBMClassifier', 'LGBMRanker',
'print_evaluation', 'record_evaluation', 'reset_parameter', 'early_stopping',
'plot_importance', 'plot_split_value_histogram', 'plot_metric', 'plot_tree', 'create_tree_digraph']

# REMOVEME: remove warning after 3.1.0 version release
if sys.version_info[0] == 2:
warnings.warn("LightGBM 3.1 version is the last version that supports Python 2.\n"
"Next release will drop the support.", UserWarning)
Loading

0 comments on commit 44a6fb7

Please sign in to comment.