ci.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. name: CI
  2. env:
  3. all-cpython-versions: 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12
  4. main-cpython-versions: 2.7, 3.2, 3.5, 3.9, 3.11
  5. pypy-versions: pypy-2.7, pypy-3.6, pypy-3.7
  6. cpython-versions: main
  7. test-set: core
  8. # Python beta version to be built using pyenv before setup-python support
  9. # Must also be included in all-cpython-versions
  10. next: 3.13
  11. on:
  12. push:
  13. # push inputs aren't known to GitHub
  14. inputs:
  15. cpython-versions:
  16. type: string
  17. default: all
  18. test-set:
  19. type: string
  20. default: core
  21. pull_request:
  22. # pull_request inputs aren't known to GitHub
  23. inputs:
  24. cpython-versions:
  25. type: string
  26. default: main
  27. test-set:
  28. type: string
  29. default: both
  30. workflow_dispatch:
  31. inputs:
  32. cpython-versions:
  33. type: choice
  34. description: CPython versions (main = 2.7, 3.2, 3.5, 3.9, 3.11)
  35. options:
  36. - all
  37. - main
  38. required: true
  39. default: main
  40. test-set:
  41. type: choice
  42. description: core, download
  43. options:
  44. - both
  45. - core
  46. - download
  47. required: true
  48. default: both
  49. permissions:
  50. contents: read
  51. jobs:
  52. select:
  53. name: Select tests from inputs
  54. runs-on: ubuntu-latest
  55. outputs:
  56. cpython-versions: ${{ steps.run.outputs.cpython-versions }}
  57. test-set: ${{ steps.run.outputs.test-set }}
  58. own-pip-versions: ${{ steps.run.outputs.own-pip-versions }}
  59. steps:
  60. # push and pull_request inputs aren't known to GitHub (pt3)
  61. - name: Set push defaults
  62. if: ${{ github.event_name == 'push' }}
  63. env:
  64. cpython-versions: all
  65. test-set: core
  66. run: |
  67. echo "cpython-versions=${{env.cpython-versions}}" >> "$GITHUB_ENV"
  68. echo "test_set=${{env.test_set}}" >> "$GITHUB_ENV"
  69. - name: Get pull_request inputs
  70. if: ${{ github.event_name == 'pull_request' }}
  71. env:
  72. cpython-versions: main
  73. test-set: both
  74. run: |
  75. echo "cpython-versions=${{env.cpython-versions}}" >> "$GITHUB_ENV"
  76. echo "test_set=${{env.test_set}}" >> "$GITHUB_ENV"
  77. - name: Make version array
  78. id: run
  79. run: |
  80. # Make a JSON Array from comma/space-separated string (no extra escaping)
  81. json_list() { \
  82. ret=""; IFS="${IFS},"; set -- $*; \
  83. for a in "$@"; do \
  84. ret=$(printf '%s"%s"' "${ret}${ret:+, }" "$a"); \
  85. done; \
  86. printf '[%s]' "$ret"; }
  87. tests="${{ inputs.test-set || env.test-set }}"
  88. [ $tests = both ] && tests="core download"
  89. printf 'test-set=%s\n' "$(json_list $tests)" >> "$GITHUB_OUTPUT"
  90. versions="${{ inputs.cpython-versions || env.cpython-versions }}"
  91. if [ "$versions" = all ]; then \
  92. versions="${{ env.all-cpython-versions }}"; else \
  93. versions="${{ env.main-cpython-versions }}"; \
  94. fi
  95. printf 'cpython-versions=%s\n' \
  96. "$(json_list ${versions}${versions:+, }${{ env.pypy-versions }})" >> "$GITHUB_OUTPUT"
  97. # versions with a special get-pip.py in a per-version subdirectory
  98. printf 'own-pip-versions=%s\n' \
  99. "$(json_list 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6)" >> "$GITHUB_OUTPUT"
  100. tests:
  101. name: Run tests
  102. needs: select
  103. permissions:
  104. contents: read
  105. packages: write
  106. runs-on: ${{ matrix.os }}
  107. env:
  108. PIP: python -m pip
  109. PIP_DISABLE_PIP_VERSION_CHECK: true
  110. PIP_NO_PYTHON_VERSION_WARNING: true
  111. strategy:
  112. fail-fast: true
  113. matrix:
  114. os: [ubuntu-22.04]
  115. python-version: ${{ fromJSON(needs.select.outputs.cpython-versions) }}
  116. python-impl: [cpython]
  117. ytdl-test-set: ${{ fromJSON(needs.select.outputs.test-set) }}
  118. run-tests-ext: [sh]
  119. include:
  120. - os: windows-2022
  121. python-version: 3.4
  122. python-impl: cpython
  123. ytdl-test-set: ${{ contains(needs.select.outputs.test-set, 'core') && 'core' || 'nocore' }}
  124. run-tests-ext: bat
  125. - os: windows-2022
  126. python-version: 3.4
  127. python-impl: cpython
  128. ytdl-test-set: ${{ contains(needs.select.outputs.test-set, 'download') && 'download' || 'nodownload' }}
  129. run-tests-ext: bat
  130. # jython
  131. - os: ubuntu-22.04
  132. python-version: 2.7
  133. python-impl: jython
  134. ytdl-test-set: ${{ contains(needs.select.outputs.test-set, 'core') && 'core' || 'nocore' }}
  135. run-tests-ext: sh
  136. - os: ubuntu-22.04
  137. python-version: 2.7
  138. python-impl: jython
  139. ytdl-test-set: ${{ contains(needs.select.outputs.test-set, 'download') && 'download' || 'nodownload' }}
  140. run-tests-ext: sh
  141. steps:
  142. - name: Prepare Linux
  143. if: ${{ startswith(matrix.os, 'ubuntu') }}
  144. shell: bash
  145. run: |
  146. # apt in runner, if needed, may not be up-to-date
  147. sudo apt-get update
  148. - name: Checkout
  149. uses: actions/checkout@v3
  150. #-------- Python 3 -----
  151. - name: Set up supported Python ${{ matrix.python-version }}
  152. id: setup-python
  153. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version != '2.6' && matrix.python-version != '2.7' && matrix.python-version != env.next }}
  154. # wrap broken actions/setup-python@v4
  155. # NB may run apt-get install in Linux
  156. uses: ytdl-org/setup-python@v1
  157. env:
  158. # Temporary (?) workaround for Python 3.5 failures - May 2024
  159. PIP_TRUSTED_HOST: "pypi.python.org pypi.org files.pythonhosted.org"
  160. with:
  161. python-version: ${{ matrix.python-version }}
  162. cache-build: true
  163. allow-build: info
  164. - name: Locate supported Python ${{ matrix.python-version }}
  165. if: ${{ env.pythonLocation }}
  166. shell: bash
  167. run: |
  168. echo "PYTHONHOME=${pythonLocation}" >> "$GITHUB_ENV"
  169. export expected="${{ steps.setup-python.outputs.python-path }}"
  170. dirname() { printf '%s\n' \
  171. 'import os, sys' \
  172. 'print(os.path.dirname(sys.argv[1]))' \
  173. | ${expected} - "$1"; }
  174. expd="$(dirname "$expected")"
  175. export python="$(command -v python)"
  176. [ "$expd" = "$(dirname "$python")" ] || echo "PATH=$expd:${PATH}" >> "$GITHUB_ENV"
  177. [ -x "$python" ] || printf '%s\n' \
  178. 'import os' \
  179. 'exp = os.environ["expected"]' \
  180. 'python = os.environ["python"]' \
  181. 'exps = os.path.split(exp)' \
  182. 'if python and (os.path.dirname(python) == exp[0]):' \
  183. ' exit(0)' \
  184. 'exps[1] = "python" + os.path.splitext(exps[1])[1]' \
  185. 'python = os.path.join(*exps)' \
  186. 'try:' \
  187. ' os.symlink(exp, python)' \
  188. 'except AttributeError:' \
  189. ' os.rename(exp, python)' \
  190. | ${expected} -
  191. printf '%s\n' \
  192. 'import sys' \
  193. 'print(sys.path)' \
  194. | ${expected} -
  195. #-------- Python next (was 3.12) -
  196. - name: Set up CPython 3.next environment
  197. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == env.next }}
  198. shell: bash
  199. run: |
  200. PYENV_ROOT=$HOME/.local/share/pyenv
  201. echo "PYENV_ROOT=${PYENV_ROOT}" >> "$GITHUB_ENV"
  202. - name: Cache Python 3.next
  203. id: cachenext
  204. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == env.next }}
  205. uses: actions/cache@v3
  206. with:
  207. key: python-${{ env.next }}
  208. path: |
  209. ${{ env.PYENV_ROOT }}
  210. - name: Build and set up Python 3.next
  211. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == env.next && ! steps.cachenext.outputs.cache-hit }}
  212. # dl and build locally
  213. shell: bash
  214. run: |
  215. # Install build environment
  216. sudo apt-get install -y build-essential llvm libssl-dev tk-dev \
  217. libncursesw5-dev libreadline-dev libsqlite3-dev \
  218. libffi-dev xz-utils zlib1g-dev libbz2-dev liblzma-dev
  219. # Download PyEnv from its GitHub repository.
  220. export PYENV_ROOT=${{ env.PYENV_ROOT }}
  221. export PATH=$PYENV_ROOT/bin:$PATH
  222. git clone "https://github.com/pyenv/pyenv.git" "$PYENV_ROOT"
  223. pyenv install ${{ env.next }}
  224. - name: Locate Python 3.next
  225. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == env.next }}
  226. shell: bash
  227. run: |
  228. PYTHONHOME="$(echo "${{ env.PYENV_ROOT }}/versions/${{ env.next }}."*)"
  229. test -n "$PYTHONHOME"
  230. echo "PYTHONHOME=$PYTHONHOME" >> "$GITHUB_ENV"
  231. echo "PATH=${PYTHONHOME}/bin:$PATH" >> "$GITHUB_ENV"
  232. #-------- Python 2.7 --
  233. - name: Set up Python 2.7
  234. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == '2.7' }}
  235. # install 2.7
  236. shell: bash
  237. run: |
  238. # Ubuntu 22.04 no longer has python-is-python2: fetch it
  239. curl -L "http://launchpadlibrarian.net/474693132/python-is-python2_2.7.17-4_all.deb" -o python-is-python2.deb
  240. sudo apt-get install -y python2
  241. sudo dpkg --force-breaks -i python-is-python2.deb
  242. echo "PYTHONHOME=/usr" >> "$GITHUB_ENV"
  243. #-------- Python 2.6 --
  244. - name: Set up Python 2.6 environment
  245. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == '2.6' }}
  246. shell: bash
  247. run: |
  248. openssl_name=openssl-1.0.2u
  249. echo "openssl_name=${openssl_name}" >> "$GITHUB_ENV"
  250. openssl_dir=$HOME/.local/opt/$openssl_name
  251. echo "openssl_dir=${openssl_dir}" >> "$GITHUB_ENV"
  252. PYENV_ROOT=$HOME/.local/share/pyenv
  253. echo "PYENV_ROOT=${PYENV_ROOT}" >> "$GITHUB_ENV"
  254. sudo apt-get install -y openssl ca-certificates
  255. - name: Cache Python 2.6
  256. id: cache26
  257. if: ${{ matrix.python-version == '2.6' }}
  258. uses: actions/cache@v3
  259. with:
  260. key: python-2.6.9
  261. path: |
  262. ${{ env.openssl_dir }}
  263. ${{ env.PYENV_ROOT }}
  264. - name: Build and set up Python 2.6
  265. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == '2.6' && ! steps.cache26.outputs.cache-hit }}
  266. # dl and build locally
  267. shell: bash
  268. run: |
  269. # Install build environment
  270. sudo apt-get install -y build-essential llvm libssl-dev tk-dev \
  271. libncursesw5-dev libreadline-dev libsqlite3-dev \
  272. libffi-dev xz-utils zlib1g-dev libbz2-dev liblzma-dev
  273. # Download and install OpenSSL 1.0.2, back in time
  274. openssl_name=${{ env.openssl_name }}
  275. openssl_targz=${openssl_name}.tar.gz
  276. openssl_dir=${{ env.openssl_dir }}
  277. openssl_inc=$openssl_dir/include
  278. openssl_lib=$openssl_dir/lib
  279. openssl_ssl=$openssl_dir/ssl
  280. curl -L "https://www.openssl.org/source/$openssl_targz" -o $openssl_targz
  281. tar -xf $openssl_targz
  282. ( cd $openssl_name; \
  283. ./config --prefix=$openssl_dir --openssldir=${openssl_dir}/ssl \
  284. --libdir=lib -Wl,-rpath=${openssl_dir}/lib shared zlib-dynamic && \
  285. make && \
  286. make install )
  287. rm -rf $openssl_name
  288. rmdir $openssl_ssl/certs && ln -s /etc/ssl/certs $openssl_ssl/certs
  289. # Download PyEnv from its GitHub repository.
  290. export PYENV_ROOT=${{ env.PYENV_ROOT }}
  291. export PATH=$PYENV_ROOT/bin:$PATH
  292. git clone "https://github.com/pyenv/pyenv.git" "$PYENV_ROOT"
  293. # Prevent pyenv build trying (and failing) to update pip
  294. export GET_PIP=get-pip-2.6.py
  295. echo 'import sys; sys.exit(0)' > ${GET_PIP}
  296. GET_PIP=$(realpath $GET_PIP)
  297. # Build and install Python
  298. export CFLAGS="-I$openssl_inc"
  299. export LDFLAGS="-L$openssl_lib"
  300. export LD_LIBRARY_PATH="$openssl_lib"
  301. pyenv install 2.6.9
  302. - name: Locate Python 2.6
  303. if: ${{ matrix.python-impl == 'cpython' && matrix.python-version == '2.6' }}
  304. shell: bash
  305. run: |
  306. PYTHONHOME="${{ env.PYENV_ROOT }}/versions/2.6.9"
  307. echo "PYTHONHOME=$PYTHONHOME" >> "$GITHUB_ENV"
  308. echo "PATH=${PYTHONHOME}/bin:$PATH" >> "$GITHUB_ENV"
  309. echo "LD_LIBRARY_PATH=${{ env.openssl_dir }}/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
  310. #-------- Jython ------
  311. - name: Set up Java 8
  312. if: ${{ matrix.python-impl == 'jython' }}
  313. uses: actions/setup-java@v3
  314. with:
  315. java-version: 8
  316. distribution: 'zulu'
  317. - name: Setup Jython environment
  318. if: ${{ matrix.python-impl == 'jython' }}
  319. shell: bash
  320. run: |
  321. echo "JYTHON_ROOT=${HOME}/jython" >> "$GITHUB_ENV"
  322. echo "PIP=pip" >> "$GITHUB_ENV"
  323. - name: Cache Jython
  324. id: cachejy
  325. if: ${{ matrix.python-impl == 'jython' && matrix.python-version == '2.7' }}
  326. uses: actions/cache@v3
  327. with:
  328. # 2.7.3 now available, may solve SNI issue
  329. key: jython-2.7.1
  330. path: |
  331. ${{ env.JYTHON_ROOT }}
  332. - name: Install Jython
  333. if: ${{ matrix.python-impl == 'jython' && matrix.python-version == '2.7' && ! steps.cachejy.outputs.cache-hit }}
  334. shell: bash
  335. run: |
  336. JYTHON_ROOT="${{ env.JYTHON_ROOT }}"
  337. curl -L "https://repo1.maven.org/maven2/org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar" -o jython-installer.jar
  338. java -jar jython-installer.jar -s -d "${JYTHON_ROOT}"
  339. echo "${JYTHON_ROOT}/bin" >> "$GITHUB_PATH"
  340. - name: Set up cached Jython
  341. if: ${{ steps.cachejy.outputs.cache-hit }}
  342. shell: bash
  343. run: |
  344. JYTHON_ROOT="${{ env.JYTHON_ROOT }}"
  345. echo "${JYTHON_ROOT}/bin" >> $GITHUB_PATH
  346. - name: Install supporting Python 2.7 if possible
  347. if: ${{ steps.cachejy.outputs.cache-hit }}
  348. shell: bash
  349. run: |
  350. sudo apt-get install -y python2.7 || true
  351. #-------- pip ---------
  352. - name: Set up supported Python ${{ matrix.python-version }} pip
  353. if: ${{ (matrix.python-version != '3.2' && steps.setup-python.outputs.python-path) || matrix.python-version == '2.7' }}
  354. # This step may run in either Linux or Windows
  355. shell: bash
  356. run: |
  357. echo "$PATH"
  358. echo "$PYTHONHOME"
  359. # curl is available on both Windows and Linux, -L follows redirects, -O gets name
  360. python -m ensurepip || python -m pip --version || { \
  361. get_pip="${{ contains(needs.select.outputs.own-pip-versions, matrix.python-version) && format('{0}/', matrix.python-version) || '' }}"; \
  362. curl -L -O "https://bootstrap.pypa.io/pip/${get_pip}get-pip.py"; \
  363. python get-pip.py; }
  364. - name: Set up Python 2.6 pip
  365. if: ${{ matrix.python-version == '2.6' }}
  366. shell: bash
  367. run: |
  368. python -m pip --version || { \
  369. curl -L -O "https://bootstrap.pypa.io/pip/2.6/get-pip.py"; \
  370. curl -L -O "https://files.pythonhosted.org/packages/ac/95/a05b56bb975efa78d3557efa36acaf9cf5d2fd0ee0062060493687432e03/pip-9.0.3-py2.py3-none-any.whl"; \
  371. python get-pip.py --no-setuptools --no-wheel pip-9.0.3-py2.py3-none-any.whl; }
  372. # work-around to invoke pip module on 2.6: https://bugs.python.org/issue2751
  373. echo "PIP=python -m pip.__main__" >> "$GITHUB_ENV"
  374. - name: Set up other Python ${{ matrix.python-version }} pip
  375. if: ${{ matrix.python-version == '3.2' && steps.setup-python.outputs.python-path }}
  376. shell: bash
  377. run: |
  378. python -m pip --version || { \
  379. curl -L -O "https://bootstrap.pypa.io/pip/3.2/get-pip.py"; \
  380. curl -L -O "https://files.pythonhosted.org/packages/b2/d0/cd115fe345dd6f07ec1c780020a7dfe74966fceeb171e0f20d1d4905b0b7/pip-7.1.2-py2.py3-none-any.whl"; \
  381. python get-pip.py --no-setuptools --no-wheel pip-7.1.2-py2.py3-none-any.whl; }
  382. #-------- unittest ----
  383. - name: Upgrade Unittest for Python 2.6
  384. if: ${{ matrix.python-version == '2.6' }}
  385. shell: bash
  386. run: |
  387. # Work around deprecation of support for non-SNI clients at PyPI CDN (see https://status.python.org/incidents/hzmjhqsdjqgb)
  388. $PIP -qq show unittest2 || { \
  389. for u in "65/26/32b8464df2a97e6dd1b656ed26b2c194606c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl" \
  390. "f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl" \
  391. "c7/a3/c5da2a44c85bfbb6eebcfc1dde24933f8704441b98fdde6528f4831757a6/linecache2-1.0.0-py2.py3-none-any.whl" \
  392. "17/0a/6ac05a3723017a967193456a2efa0aa9ac4b51456891af1e2353bb9de21e/traceback2-1.4.0-py2.py3-none-any.whl" \
  393. "72/20/7f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813/unittest2-1.1.0-py2.py3-none-any.whl"; do \
  394. curl -L -O "https://files.pythonhosted.org/packages/${u}"; \
  395. $PIP install ${u##*/}; \
  396. done; }
  397. # make tests use unittest2
  398. for test in ./test/test_*.py ./test/helper.py; do
  399. sed -r -i -e '/^import unittest$/s/test/test2 as unittest/' "$test"
  400. done
  401. #-------- nose --------
  402. - name: Install nose for Python ${{ matrix.python-version }}
  403. if: ${{ (matrix.python-version != '3.2' && steps.setup-python.outputs.python-path) || (matrix.python-impl == 'cpython' && (matrix.python-version == '2.7' || matrix.python-version == env.next)) }}
  404. shell: bash
  405. run: |
  406. echo "$PATH"
  407. echo "$PYTHONHOME"
  408. # Use PyNose for recent Pythons instead of Nose
  409. py3ver="${{ matrix.python-version }}"
  410. py3ver=${py3ver#3.}
  411. [ "$py3ver" != "${{ matrix.python-version }}" ] && py3ver=${py3ver%.*} || py3ver=0
  412. [ "$py3ver" -ge 9 ] && nose=pynose || nose=nose
  413. $PIP -qq show $nose || $PIP install $nose
  414. - name: Install nose for other Python 2
  415. if: ${{ matrix.python-impl == 'jython' || (matrix.python-impl == 'cpython' && matrix.python-version == '2.6') }}
  416. shell: bash
  417. run: |
  418. # Work around deprecation of support for non-SNI clients at PyPI CDN (see https://status.python.org/incidents/hzmjhqsdjqgb)
  419. $PIP -qq show nose || { \
  420. curl -L -O "https://files.pythonhosted.org/packages/99/4f/13fb671119e65c4dce97c60e67d3fd9e6f7f809f2b307e2611f4701205cb/nose-1.3.7-py2-none-any.whl"; \
  421. $PIP install nose-1.3.7-py2-none-any.whl; }
  422. - name: Install nose for other Python 3
  423. if: ${{ matrix.python-version == '3.2' && steps.setup-python.outputs.python-path }}
  424. shell: bash
  425. run: |
  426. $PIP -qq show nose || { \
  427. curl -L -O "https://files.pythonhosted.org/packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl"; \
  428. $PIP install nose-1.3.7-py3-none-any.whl; }
  429. - name: Set up nosetest test
  430. if: ${{ contains(needs.select.outputs.test-set, matrix.ytdl-test-set ) }}
  431. shell: bash
  432. run: |
  433. # set PYTHON_VER
  434. PYTHON_VER=${{ matrix.python-version }}
  435. [ "${PYTHON_VER#*-}" != "$PYTHON_VER" ] || PYTHON_VER="${{ matrix.python-impl }}-${PYTHON_VER}"
  436. echo "PYTHON_VER=$PYTHON_VER" >> "$GITHUB_ENV"
  437. echo "PYTHON_IMPL=${{ matrix.python-impl }}" >> "$GITHUB_ENV"
  438. # define a test to validate the Python version used by nosetests
  439. printf '%s\n' \
  440. 'from __future__ import unicode_literals' \
  441. 'import sys, os, platform' \
  442. 'try:' \
  443. ' import unittest2 as unittest' \
  444. 'except ImportError:' \
  445. ' import unittest' \
  446. 'class TestPython(unittest.TestCase):' \
  447. ' def setUp(self):' \
  448. ' self.ver = os.environ["PYTHON_VER"].split("-")' \
  449. ' def test_python_ver(self):' \
  450. ' self.assertEqual(["%d" % v for v in sys.version_info[:2]], self.ver[-1].split(".")[:2])' \
  451. ' self.assertTrue(sys.version.startswith(self.ver[-1]))' \
  452. ' self.assertIn(self.ver[0], ",".join((sys.version, platform.python_implementation())).lower())' \
  453. ' def test_python_impl(self):' \
  454. ' self.assertIn(platform.python_implementation().lower(), (os.environ["PYTHON_IMPL"], self.ver[0]))' \
  455. > test/test_python.py
  456. #-------- TESTS -------
  457. - name: Run tests
  458. if: ${{ contains(needs.select.outputs.test-set, matrix.ytdl-test-set ) }}
  459. continue-on-error: ${{ matrix.ytdl-test-set == 'download' || matrix.python-impl == 'jython' }}
  460. env:
  461. YTDL_TEST_SET: ${{ matrix.ytdl-test-set }}
  462. run: |
  463. ./devscripts/run_tests.${{ matrix.run-tests-ext }}
  464. flake8:
  465. name: Linter
  466. runs-on: ubuntu-latest
  467. steps:
  468. - uses: actions/checkout@v3
  469. - name: Set up Python
  470. uses: actions/setup-python@v4
  471. with:
  472. python-version: 3.9
  473. - name: Install flake8
  474. run: pip install flake8
  475. - name: Run flake8
  476. run: flake8 .