From d0df79f47783ff5d7069d8cbc6149f68e330168e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Thu, 4 Feb 2021 00:13:10 +0100 Subject: [PATCH] build(pyinstaller): add linux binary support --- .github/workflows/ci.yml | 54 ++++++++++++++------- guessit.spec | 42 ++++++++++++++++ guessit/{ => data}/tlds-alpha-by-domain.txt | 0 guessit/rules/properties/website.py | 2 +- setup.py | 5 +- 5 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 guessit.spec rename guessit/{ => data}/tlds-alpha-by-domain.txt (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7afac5b..7602e20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9, pypy-3.6, pypy-3.7 ] + python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9 ] # pypy-3.6, pypy-3.7 are supported but a bit slow. regex: [ "0", "1" ] exclude: # regex module doesn't play well with pypy and unicode. @@ -18,6 +18,15 @@ jobs: regex: "1" - python-version: pypy-3.7 regex: "1" + # test regex module only with Python 3.8. + - python-version: 3.5 + regex: "1" + - python-version: 3.6 + regex: "1" + - python-version: 3.7 + regex: "1" + - python-version: 3.9 + regex: "1" steps: - name: Setup python ${{ matrix.python-version }} @@ -41,25 +50,44 @@ jobs: - name: Install regex run: | pip install regex - if: ${{ matrix.regex == '1' }} + if: matrix.regex == '1' - - run: pylint guessit + - name: Pylint + run: pylint guessit if: matrix.python-version != '3.9' - - run: coverage run --source=guessit setup.py test + - name: Test + run: coverage run --source=guessit setup.py test env: REBULK_REGEX_ENABLED: ${{ matrix.regex }} - - run: python setup.py build - - name: Coveralls run: coveralls env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + - name: Build + run: python setup.py build + + - name: Binary + run: pyinstaller --dist ./dist guessit.spec + if: matrix.python-version != 'pypy-3.7' + + - name: Check binary + run: ./dist/guessit "Treme.1x03.Right.Place,.Wrong.Time.HDTV.XviD-NoTV.avi" + if: matrix.python-version != 'pypy-3.7' + + - uses: actions/upload-artifact@v2 + if: matrix.regex == '0' + with: + name: guessit-dist-${{matrix.python-version}} + path: ./dist + commitlint: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + steps: - uses: actions/checkout@v2 with: @@ -67,21 +95,16 @@ jobs: - uses: wagoid/commitlint-github-action@v2 release: - if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }} + if: github.ref == 'refs/heads/master' && github.event_name == 'push' needs: build runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: [ 3.8 ] - steps: - - name: Setup python ${{ matrix.python-version }} + - name: Setup python 3.8 uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: 3.8 - name: Checkout uses: actions/checkout@v2 @@ -93,9 +116,6 @@ jobs: git config --global user.email "action@github.com" git config --global user.name "github-actions" - - name: Install Dependencies - run: pip install -e .[test] - - name: Install python-semantic-release run: pip install python-semantic-release diff --git a/guessit.spec b/guessit.spec new file mode 100644 index 0000000..dfab59f --- /dev/null +++ b/guessit.spec @@ -0,0 +1,42 @@ +# -*- mode: python -*- + +block_cipher = None + +import babelfish + +a = Analysis(['guessit/__main__.py'], + pathex=[], + binaries=[], + datas=[ + ('guessit/config/*', 'guessit/config'), + ('guessit/data/*', 'guessit/data'), + (babelfish.__path__[0] + '/data', 'babelfish/data') + ], + hiddenimports=[ + 'pkg_resources.py2_warn', # https://github.com/pypa/setuptools/issues/1963 + 'babelfish.converters.alpha2', + 'babelfish.converters.alpha3b', + 'babelfish.converters.alpha3t', + 'babelfish.converters.name', + 'babelfish.converters.opensubtitles', + 'babelfish.converters.countryname' + ], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=True, + cipher=block_cipher) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + name='guessit', + debug=False, + strip=False, + upx=False, + runtime_tmpdir=None, + console=True ) \ No newline at end of file diff --git a/guessit/tlds-alpha-by-domain.txt b/guessit/data/tlds-alpha-by-domain.txt similarity index 100% rename from guessit/tlds-alpha-by-domain.txt rename to guessit/data/tlds-alpha-by-domain.txt diff --git a/guessit/rules/properties/website.py b/guessit/rules/properties/website.py index c196531..96bed64 100644 --- a/guessit/rules/properties/website.py +++ b/guessit/rules/properties/website.py @@ -27,7 +27,7 @@ def website(config): rebulk = rebulk.regex_defaults(flags=re.IGNORECASE).string_defaults(ignore_case=True) rebulk.defaults(name="website") - with resource_stream('guessit', 'tlds-alpha-by-domain.txt') as tld_file: + with resource_stream('guessit', 'data/tlds-alpha-by-domain.txt') as tld_file: tlds = [ tld.strip().decode('utf-8') for tld in tld_file.readlines() diff --git a/setup.py b/setup.py index 3c5edea..e82bccf 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,6 @@ from setuptools import setup, find_packages import io import os import re -import sys here = os.path.abspath(os.path.dirname(__file__)) @@ -20,11 +19,11 @@ install_requires = ['rebulk>=3', 'babelfish', 'python-dateutil'] setup_requires = ['pytest-runner'] -dev_require = ['tox', 'mkdocs', 'mkdocs-material'] +dev_require = ['tox', 'mkdocs', 'mkdocs-material', 'pyinstaller'] tests_require = ['pytest', 'pytest-benchmark', 'pylint', 'PyYAML'] -package_data = ['config/*'] +package_data = ['config/*', 'data/*'] entry_points = { 'console_scripts': [