From 9c1afc037683c07dd61c713e64a02887010e54d8 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 11:54:16 -0300 Subject: [PATCH 1/8] Change m3u8 project to use poetry --- .github/workflows/main.yml | 10 ++++++++++ .gitignore | 1 + MANIFEST.in | 3 --- pyproject.toml | 36 ++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 8 -------- requirements.txt | 1 - runtests | 6 +++--- setup.py | 28 ---------------------------- 8 files changed, 50 insertions(+), 43 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd84fec3..1114409a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,16 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.5.1 + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + - run: poetry env use ${{ matrix.python-version }} + # Runs a single command using the runners shell - name: Run all tests run: ./runtests diff --git a/.gitignore b/.gitignore index 35c96ea1..6186cfa5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ local/ .vscode/ venv/ pyvenv.cfg +poetry.lock \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 259261b0..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include requirements.txt -include LICENSE -include README.md diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..8f9d7937 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,36 @@ +[tool.poetry] +name = "m3u8" +version = "6.0.0" +description = "Python m3u8 parser" +authors = ["Globo.com"] +license = "MIT" +readme = "README.md" +repository = "https://github.com/globocom/m3u8" +packages = [ + {include = "m3u8"}, + {include = "LICENSE"}, + {include = "README.md"}, +] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] + +[tool.poetry.dependencies] +python = "^3.7" +backports-datetime-fromisoformat = {version = "*", python = "<3.11"} + +[tool.poetry.group.dev.dependencies] +bottle = "*" +pytest = "*" +pytest-cov = ">=2.4.0,<2.6" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 56806d35..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,8 +0,0 @@ --r requirements.txt -bottle -pytest -# pytest-cov 2.6.0 has increased the version requirement -# for the coverage package from >=3.7.1 to >=4.4, -# which is in conflict with the version requirement -# defined by the python-coveralls package for coverage==4.0.3 -pytest-cov>=2.4.0,<2.6 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c785d132..00000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -backports-datetime-fromisoformat; python_version < '3.11' diff --git a/runtests b/runtests index 7d55bd76..469a8904 100755 --- a/runtests +++ b/runtests @@ -3,12 +3,12 @@ test_server_stdout=tests/server.stdout function install_deps { - pip install -r requirements-dev.txt + poetry install } function start_server { rm -f ${test_server_stdout} - python tests/m3u8server.py >${test_server_stdout} 2>&1 & + poetry run python tests/m3u8server.py >${test_server_stdout} 2>&1 & } function stop_server { @@ -17,7 +17,7 @@ function stop_server { } function run { - PYTHONPATH=. py.test -vv --cov-report term-missing --cov m3u8 tests/ + poetry run pytest -vv --cov-report term-missing --cov m3u8 tests/ } function main { diff --git a/setup.py b/setup.py deleted file mode 100644 index 237d7aeb..00000000 --- a/setup.py +++ /dev/null @@ -1,28 +0,0 @@ -from os.path import abspath, dirname, exists, join - -from setuptools import setup - -long_description = None -if exists("README.md"): - with open("README.md") as file: - long_description = file.read() - -install_reqs = [ - req for req in open(abspath(join(dirname(__file__), "requirements.txt"))) -] - -setup( - name="m3u8", - author="Globo.com", - version="6.0.0", - license="MIT", - zip_safe=False, - include_package_data=True, - install_requires=install_reqs, - packages=["m3u8"], - url="https://github.com/globocom/m3u8", - description="Python m3u8 parser", - long_description=long_description, - long_description_content_type="text/markdown", - python_requires=">=3.7", -) From dd21361c4962244a7652835fc77dbcb56de63996 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 12:07:31 -0300 Subject: [PATCH 2/8] Add use of cache to avoid reinstalling the packages every time --- .github/workflows/main.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1114409a..b18425b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,8 +42,20 @@ jobs: virtualenvs-in-project: true installer-parallel: true - - run: poetry env use ${{ matrix.python-version }} + - name: Load Cached Environment + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} + + - name: Select Poetry Python ${{ matrix.python-version }} Version + run: poetry env use ${{ matrix.python-version }} + - name: Install Python ${{ matrix.python-version }} Dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + # Runs a single command using the runners shell - name: Run all tests run: ./runtests From 63c1a2e1184fcd16d766c43c02e8dc78f05bf831 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 12:48:45 -0300 Subject: [PATCH 3/8] Install poetry just a single time --- .github/workflows/main.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b18425b7..179b7a94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,20 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" + # This job is used to install Poetry + setup-poetry: + runs-on: ubuntu-latest + steps: + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.5.1 + virtualenvs-create: true + virtualenvs-in-project: true + outputs: + poetry-version: ${{ steps.poetry-version.outputs.version }} + + # This job is used to install dependencies and run tests for each supported Python version build: # The type of runner that the job will run on runs-on: ubuntu-latest @@ -47,16 +60,12 @@ jobs: uses: actions/cache@v4 with: path: .venv - key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} - - name: Select Poetry Python ${{ matrix.python-version }} Version - run: poetry env use ${{ matrix.python-version }} - - - name: Install Python ${{ matrix.python-version }} Dependencies + - name: Install Dependencies if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install --no-interaction --no-root # Runs a single command using the runners shell - name: Run all tests - run: ./runtests - + run: poetry run./runtests From 411061fadcf780ef4091782b6c712a6bb767f745 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 12:50:41 -0300 Subject: [PATCH 4/8] Add depends-on clause for github actions --- .github/workflows/main.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 179b7a94..13a1a71b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,11 +25,14 @@ jobs: version: 1.5.1 virtualenvs-create: true virtualenvs-in-project: true + installer-parallel: true outputs: poetry-version: ${{ steps.poetry-version.outputs.version }} # This job is used to install dependencies and run tests for each supported Python version build: + # This job depends on the setup-poetry job + needs: setup-poetry # The type of runner that the job will run on runs-on: ubuntu-latest strategy: @@ -47,14 +50,6 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.5.1 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - - name: Load Cached Environment id: cached-poetry-dependencies uses: actions/cache@v4 @@ -68,4 +63,4 @@ jobs: # Runs a single command using the runners shell - name: Run all tests - run: poetry run./runtests + run: poetry run ./runtests From 5a1810ff3f8a6292a695d0e724c0436cad0f09af Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 12:56:13 -0300 Subject: [PATCH 5/8] Change snoke to abatilo poetry --- .github/workflows/main.yml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 13a1a71b..222dfa59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,24 +15,8 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This job is used to install Poetry - setup-poetry: - runs-on: ubuntu-latest - steps: - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.5.1 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - outputs: - poetry-version: ${{ steps.poetry-version.outputs.version }} - - # This job is used to install dependencies and run tests for each supported Python version + # This workflow contains a single job called "build" build: - # This job depends on the setup-poetry job - needs: setup-poetry # The type of runner that the job will run on runs-on: ubuntu-latest strategy: @@ -50,6 +34,16 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install Poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: 1.5.1 + + - name: Setup Local Virtual Environment + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + - name: Load Cached Environment id: cached-poetry-dependencies uses: actions/cache@v4 From ce70aedda689486d0091c271ec33bedef1771714 Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 12:59:22 -0300 Subject: [PATCH 6/8] Add a few comments in the workflows --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 222dfa59..ff0fe9d4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,16 +34,19 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Poetry + # Use abatilo/actions-poetry@v2 to install Poetry + - name: Install Poetry uses: abatilo/actions-poetry@v2 with: poetry-version: 1.5.1 + # Setup Local Virtual Environment if no poetry.toml file - name: Setup Local Virtual Environment run: | poetry config virtualenvs.create true --local poetry config virtualenvs.in-project true --local + # Load Cached Environment if it exists - name: Load Cached Environment id: cached-poetry-dependencies uses: actions/cache@v4 @@ -51,6 +54,7 @@ jobs: path: .venv key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} + # Install Dependencies if no cached environment - name: Install Dependencies if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install --no-interaction --no-root From 10a5bd7f53d68d3caf894dcbeb23def759ae526e Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 13:03:01 -0300 Subject: [PATCH 7/8] Verify if Github actions variable is defined --- runtests | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtests b/runtests index 469a8904..d63665b5 100755 --- a/runtests +++ b/runtests @@ -3,7 +3,11 @@ test_server_stdout=tests/server.stdout function install_deps { - poetry install + if [ -z "$GITHUB_ACTIONS" ]; then + poetry install + else + echo "Skipping dependency installation on GitHub Actions" + fi } function start_server { From 12cffeaace4b5d3c7633af22a9c74e98d2fbf35f Mon Sep 17 00:00:00 2001 From: Bruno Dantas Date: Tue, 8 Oct 2024 16:04:59 -0300 Subject: [PATCH 8/8] Upgrade setup-python action version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff0fe9d4..e06827a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }}