1 ################################################################################
3 # python3.cygclass - functions for installing Python3 modules
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/python3.cygclass
28 # Python is a general-purpose, interpreted programming language used in a
29 # wide variety of software. It comes with a large standard library, and is
30 # easily extendible with modules written in Python and/or C/C++. Programs
31 # can also embed a Python interpreter for use with their own extensions.
33 # The new 3.x versions of Python are incompatible with the widely used 2.x
34 # versions, so they are designed to be installed in parallel as separate
37 # This cygclass provides definitions and some install helpers which can be used
38 # by any Python3-based package. Python3 modules and programs are built in a
39 # number of ways, so this cygclass does not provide any build functions. The
40 # two most common build systems for Python3 packages are Distutils and autotools.
42 # python3.cygclass is for the 3.x versions of Python; for the 2.x versions,
43 # see python2.cygclass.
45 # python-wheel.cygclass
50 # cross-compiling is not (yet?) supported
51 __cross_compiling_error
53 check_prog_req python3
55 #****d* python3.cygclass/PYTHON3
57 # Absolute path to the Python3 interpreter.
59 PYTHON3=$(readlink -f /usr/bin/python3 | sed -e 's/\.exe$//')
61 #****d* python3.cygclass/PYTHON3_CONFIG
63 # Absolute path to the Python3 config script.
65 PYTHON3_CONFIG=$(readlink -f /usr/bin/python3-config)
67 #****d* python3.cygclass/PYTHON3_VERSION
69 # The major.minor version of the current Python3 interpreter.
71 PYTHON3_VERSION=$(${PYTHON3} -c 'from distutils.sysconfig import * ; print(get_python_version());')
73 #****d* python3.cygclass/PYTHON3_PKGVERSION
75 # The $major$minor version (without a dot) for use in package names.
77 PYTHON3_PKGVERSION=${PYTHON3_VERSION/.}
79 #****d* python3.cygclass/PYTHON3_ABIFLAGS
81 # The ABI flags of the current Python3 interpreter, as used in the names of
82 # the interpreter, config script and subdir, shared library, and includedir.
84 PYTHON3_ABIFLAGS=$(${PYTHON3_CONFIG} --abiflags 2>/dev/null)
86 #****d* python3.cygclass/PYTHON3_INCLUDEDIR
88 # Path containing the Python3 C library headers.
90 PYTHON3_INCLUDEDIR=$(${PYTHON3} -c 'from distutils.sysconfig import * ; print(get_python_inc());')
92 #****d* python3.cygclass/PYTHON3_LIB
94 # Path containing the Python3 standard library.
96 # Never install third-party extensions into PYTHON3_LIB; use PYTHON3_SITELIB instead.
98 PYTHON3_LIB=$(${PYTHON3} -c 'from distutils.sysconfig import * ; print(get_python_lib(0,1));')
100 #****d* python3.cygclass/PYTHON3_SITELIB
102 # Installation path for all Python3 extension modules.
104 PYTHON3_SITELIB=$(${PYTHON3} -c 'from distutils.sysconfig import * ; print(get_python_lib(0,0));')
106 #****d* python3.cygclass/LIBPYTHON3
108 # Link flags for the Python3 C library. This definition must be properly quoted.
110 LIBPYTHON3=$(${PYTHON3_CONFIG} --libs)
112 #****I* python3.cygclass/python3into
114 # python3into SUBDIRECTORY
116 # Subdirectory of PYTHON3_SITELIB into which dopython3 should install. This is
117 # usually unnecessary.
122 error "python3into accepts exactly one argument";
126 /*) error "python3into argument should be only a subdirectory" ;;
129 _python3into_dir=${1};
132 #****I* python3.cygclass/dopython3
134 # [python3into SUBDIRECTORY]
135 # dopython3 MODULE1 [MODULE2] ...
137 # Installs the given Python3 module(s) (.py or .dll) into PYTHON3_SITELIB under $D,
138 # or a subdirectory thereof if python3into was previously called.
144 if defined _python3into_dir
146 pydir=${PYTHON3_SITELIB}/${_python3into_dir}
148 pydir=${PYTHON3_SITELIB}
159 __doinstall 0755 ${i} ${pydir} || error "dopython3 ${i} failed"
162 __doinstall 0644 ${i} ${pydir} || error "dopython3 ${i} failed"
166 error "dopython3: ${i}: file not found"
171 #****I* python3.cygclass/python3_optimize
173 # python3_optimize DIRECTORY [DIRECTORY] ...
175 # Bytecode-compile all Python3 modules found in the given directories under $D.
182 if [ ! -d ${D}${pyd} ]
184 error "directory ${pyd} does not exist"
187 inform "Compiling ${pyd}..."
188 ${PYTHON3} ${PYTHON3_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
189 ${PYTHON3} -O ${PYTHON3_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
190 ${PYTHON3} -OO ${PYTHON3_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
194 #****I* python3.cygclass/python3_fix_shebang
196 # python3_fix_shebang SCRIPT [SCRIPT ...]
198 # Fixes the designated interpreter of SCRIPT to PYTHON3. This would be necessary
199 # if the original uses an incorrect path (e.g. /usr/local/bin) or an
200 # incorrectly versioned binary. SCRIPT need not be prefixed by $D.
202 python3_fix_shebang() {
205 __fix_shebang ${PYTHON3} ${D}/${f#${D}}
209 readonly -f python3into dopython3 python3_optimize python3_fix_shebang