paddlenlp

Форк
0
/
setup.py 
198 строк · 6.5 Кб
1
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
import errno
15
import io
16
import os
17
import subprocess
18

19
import setuptools
20

21
PADDLENLP_STABLE_VERSION = "PADDLENLP_STABLE_VERSION"
22

23

24
def read_requirements_file(filepath):
25
    with open(filepath) as fin:
26
        requirements = fin.read()
27
    return requirements
28

29

30
def is_git_repo(dir: str) -> bool:
31
    """Is the given directory version-controlled with git?"""
32
    return os.path.exists(os.path.join(dir, ".git"))
33

34

35
def have_git() -> bool:
36
    """Can we run the git executable?"""
37
    try:
38
        subprocess.check_output(["git", "--help"])
39
        return True
40
    except subprocess.CalledProcessError:
41
        return False
42
    except OSError:
43
        return False
44

45

46
def git_revision(dir: str) -> bytes:
47
    """Get the SHA-1 of the HEAD of a git repository."""
48
    return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=dir).strip()
49

50

51
def git_checkout(dir: str, filename: str) -> bytes:
52
    """Get the SHA-1 of the HEAD of a git repository."""
53
    return subprocess.check_output(["git", "checkout", filename], cwd=dir).strip()
54

55

56
def is_dirty(dir: str) -> bool:
57
    """Check whether a git repository has uncommitted changes."""
58
    output = subprocess.check_output(["git", "status", "-uno", "--porcelain"], cwd=dir)
59
    return output.strip() != b""
60

61

62
commit = "unknown"
63
paddlenlp_dir = os.path.abspath(os.path.dirname(__file__))
64
if commit.endswith("unknown") and is_git_repo(paddlenlp_dir) and have_git():
65
    commit = git_revision(paddlenlp_dir).decode("utf-8")
66
    if is_dirty(paddlenlp_dir):
67
        commit += ".dirty"
68

69

70
def write_version_py(filename="paddlenlp/version/__init__.py"):
71
    cnt = '''# THIS FILE IS GENERATED FROM PADDLENLP SETUP.PY
72
commit           = '%(commit)s'
73

74
__all__ = ['show']
75

76
def show():
77
    """Get the corresponding commit id of paddlenlp.
78

79
    Returns:
80
        The commit-id of paddlenlp will be output.
81

82
        full_version: version of paddlenlp
83

84

85
    Examples:
86
        .. code-block:: python
87

88
            import paddlenlp
89

90
            paddlenlp.version.show()
91
            # commit: 1ef5b94a18773bb0b1bba1651526e5f5fc5b16fa
92

93
    """
94
    print("commit:", commit)
95

96
'''
97
    commit_id = commit
98
    content = cnt % {"commit": commit_id}
99

100
    dirname = os.path.dirname(filename)
101

102
    try:
103
        os.makedirs(dirname)
104
    except OSError as e:
105
        if e.errno != errno.EEXIST:
106
            raise
107

108
    with open(filename, "w") as f:
109
        f.write(content)
110

111

112
__version__ = "2.7.1.post"
113
if os.getenv(PADDLENLP_STABLE_VERSION):
114
    __version__ = __version__.replace(".post", "")
115

116

117
extras = {}
118
REQUIRED_PACKAGES = read_requirements_file("requirements.txt")
119
extras["tests"] = read_requirements_file("tests/requirements.txt")
120
extras["docs"] = read_requirements_file("docs/requirements.txt")
121
extras["autonlp"] = read_requirements_file("paddlenlp/experimental/autonlp/requirements.txt")
122
extras["dev"] = extras["tests"] + extras["docs"] + extras["autonlp"]
123

124

125
def read(*names, **kwargs):
126
    with io.open(os.path.join(os.path.dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8")) as fp:
127
        return fp.read()
128

129

130
def get_package_data_files(package, data, package_dir=None):
131
    """
132
    Helps to list all specified files in package including files in directories
133
    since `package_data` ignores directories.
134
    """
135
    if package_dir is None:
136
        package_dir = os.path.join(*package.split("."))
137
    all_files = []
138
    for f in data:
139
        path = os.path.join(package_dir, f)
140
        if os.path.isfile(path):
141
            all_files.append(f)
142
            continue
143
        for root, _dirs, files in os.walk(path, followlinks=True):
144
            root = os.path.relpath(root, package_dir)
145
            for file in files:
146
                file = os.path.join(root, file)
147
                if file not in all_files:
148
                    all_files.append(file)
149
    return all_files
150

151

152
if commit != "unknown":
153
    write_version_py(filename="paddlenlp/version/__init__.py")
154

155
try:
156
    setuptools.setup(
157
        name="paddlenlp",
158
        version=__version__,
159
        author="PaddleNLP Team",
160
        author_email="paddlenlp@baidu.com",
161
        description="Easy-to-use and powerful NLP library with Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including Neural Search, Question Answering, Information Extraction and Sentiment Analysis end-to-end system.",
162
        long_description=read("README_en.md"),
163
        long_description_content_type="text/markdown",
164
        url="https://github.com/PaddlePaddle/PaddleNLP",
165
        license_files=("LICENSE",),
166
        packages=setuptools.find_packages(
167
            where=".",
168
            exclude=("examples*", "tests*", "applications*", "fast_tokenizer*", "fast_generation*", "model_zoo*"),
169
        ),
170
        package_data={
171
            "paddlenlp.ops": get_package_data_files(
172
                "paddlenlp.ops", ["CMakeLists.txt", "README.md", "cmake", "fast_transformer", "patches", "optimizer"]
173
            ),
174
            "paddlenlp.transformers.layoutxlm": get_package_data_files(
175
                "paddlenlp.transformers.layoutxlm", ["visual_backbone.yaml"]
176
            ),
177
        },
178
        setup_requires=["cython", "numpy"],
179
        install_requires=REQUIRED_PACKAGES,
180
        entry_points={"console_scripts": ["paddlenlp = paddlenlp.cli:main"]},
181
        extras_require=extras,
182
        python_requires=">=3.6",
183
        classifiers=[
184
            "Programming Language :: Python :: 3",
185
            "Programming Language :: Python :: 3.6",
186
            "Programming Language :: Python :: 3.7",
187
            "Programming Language :: Python :: 3.8",
188
            "Programming Language :: Python :: 3.9",
189
            "License :: OSI Approved :: Apache Software License",
190
            "Operating System :: OS Independent",
191
        ],
192
        license="Apache 2.0",
193
    )
194
except Exception as e:
195
    git_checkout(paddlenlp_dir, "paddlenlp/version/__init__.py") if commit != "unknown" else None
196
    raise e
197

198
git_checkout(paddlenlp_dir, "paddlenlp/version/__init__.py") if commit != "unknown" else None
199

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.