From 34806b59159f9effd1951ef29e34e3a89778d8b2 Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Sat, 17 Aug 2024 13:08:36 +0200 Subject: [PATCH 1/5] First draft of release --- .github/workflows/release.yml | 65 +++++++++++++++++++++++++++++++++++ README.md | 27 ++++++++++++++- pyproject.toml | 24 ++++++++++--- setup.cfg | 6 ---- 4 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 setup.cfg diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..70032e4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,65 @@ +name: Create release +on: [push] + +jobs: + release: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: "3.8" + + - name: Install Hatch + run: pipx install hatch + + - name: Set variables + id: set_variables + run: | + tag="$(git describe --tags --abbrev=0)" + echo "::group::Variables" + cat << EOF | tee -a "$GITHUB_OUTPUT" + tag=${tag} + version=v$(hatch project metadata | jq -r .version) + EOF + echo "::endgroup::" + + - name: Bundle and create release + env: + GH_TOKEN: ${{ github.token }} + tag: ${{ steps.set_variables.outputs.tag }} + version: ${{ steps.set_variables.outputs.version }} + if: | + env.tag != env.version + run: | + project_name="$(hatch project metadata | jq -r .name)" + sources="$(\ + hatch run default:pip list --verbose --format json \ + | jq -r '.[] | select(.editable_project_location == null) | "\(.name);\(.location)"' \ + )" + + echo "::group::Dependencies" + printf '%s\n' "${sources}" + echo "::endgroup::" + + mkdir bundle/ + cp -r yt_dlp_plugins bundle/ + + while IFS=';' read -r name path; do + if [[ ! "${name}" =~ ^(pip|setuptools|wheel)$ ]]; then + package_name="$(tr '[:upper:]' '[:lower:]' <<<"${name}" | sed 's/-/_/g')" + cp -r "${path}/${package_name}" bundle/ + fi + done <<<"${sources}" + + cd bundle/ + find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete + zip -9 --recurse-paths "${project_name}" * + gh release create "${version}" --latest \ + --title "${project_name} ${version}" \ + "${project_name}.zip" diff --git a/README.md b/README.md index 8e08880..fc69486 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This repository contains a sample plugin package for [yt-dlp](https://github.com/yt-dlp/yt-dlp#readme). +This repository contains a sample plugin package for [yt-dlp](https://github.com/yt-dlp/yt-dlp#readme). See [yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#plugins) for more details. @@ -18,3 +18,28 @@ See [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plug ## Development See the [Plugin Development](https://github.com/yt-dlp/yt-dlp/wiki/Plugin-Development) section of the yt-dlp wiki. +Add required dependencies to the `dependencies` section in the `pyproject.toml`. +From within the plugin, use an import pattern similar to the following: +```py +import sys +import pathlib + + +import_path = str(pathlib.Path(__file__).parent.parent.parent) + +sys.path.insert(0, import_path) +try: + import some_dependency + +except ImportError: + some_dependency = None + +finally: + sys.path.remove(import_path) +``` + +## Release + +To create a release, simply increment the version in the `pyproject.toml` file. +While convenient, conditional requirements or non pure python modules will most likely not work. +Please edit the `.github/workflows/release.yml` accordingly if you require more control. diff --git a/pyproject.toml b/pyproject.toml index 97057d9..539be64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,22 @@ [build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" -[tool.distutils.bdist_wheel] -universal = true +[project] +name = "yt-dlp-sample-plugins" +version = "2023.01.02" +readme = "README.md" +requires-python = ">=3.8" +license = "MIT" +keywords = ["yt-dlp", "yt-dlp-plugin"] +authors = [ + { name = "John Doe", email = "johndoe@example.com" }, +] +dependencies = [] + +[tool.hatch.env.default] +installer = "uv" +path = ".venv" + +[tool.hatch.build.targets.wheel] +packages = ["yt_dlp_plugins"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 63f8beb..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[metadata] -name = yt-dlp-sample-plugins -version = 2023.01.01 - -[options] -packages = find_namespace: From 464aed82c79e4c2daac437e35a1245afb3504350 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 30 Nov 2024 11:36:37 +1300 Subject: [PATCH 2/5] Point license in pyproject.yoml to LICENSE file Co-authored-by: N/Ame <173015200+grqz@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 539be64..d3c009f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "yt-dlp-sample-plugins" version = "2023.01.02" readme = "README.md" requires-python = ">=3.8" -license = "MIT" +license = {file = "LICENSE"} keywords = ["yt-dlp", "yt-dlp-plugin"] authors = [ { name = "John Doe", email = "johndoe@example.com" }, From 9f598162ad57c9471c26355283b688126df0ed5b Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 30 Nov 2024 11:41:28 +1300 Subject: [PATCH 3/5] Add manual install instructions to README --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc69486..736c2da 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,32 @@ See [yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#plugins) for more details. Requires yt-dlp `2023.01.02` or above. +### Install with pip + You can install this package with pip: ``` python3 -m pip install -U https://github.com/yt-dlp/yt-dlp-sample-plugins/archive/master.zip ``` -See [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plugins) for the other methods this plugin package can be installed. +### Install manually + +1. Download the latest release zip from [releases](https://github.com/yt-dlp/yt-dlp-sample-plugins/releases) + +2. Add the zip to one of the [yt-dlp plugin locations](https://github.com/yt-dlp/yt-dlp#installing-plugins) + + - User Plugins + - `${XDG_CONFIG_HOME}/yt-dlp/plugins` (recommended on Linux/MacOS) + - `~/.yt-dlp/plugins/` + - `${APPDATA}/yt-dlp/plugins/` (recommended on Windows) + + - System Plugins + - `/etc/yt-dlp/plugins/` + - `/etc/yt-dlp-plugins/` + + - Executable location + - Binary: where `/yt-dlp.exe`, `/yt-dlp-plugins/` +For more locations and methods, see [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plugins) ## Development From 0fc5ee962a28441e025d5870b43290c275248bc7 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 30 Nov 2024 11:47:09 +1300 Subject: [PATCH 4/5] Update readme instructions on bundling deps --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 736c2da..600e5dc 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,18 @@ For more locations and methods, see [installing yt-dlp plugins](https://github.c ## Development See the [Plugin Development](https://github.com/yt-dlp/yt-dlp/wiki/Plugin-Development) section of the yt-dlp wiki. + +### Dependencies + Add required dependencies to the `dependencies` section in the `pyproject.toml`. -From within the plugin, use an import pattern similar to the following: + +#### Bundling with release zip + +By default, the [release action](.github/workflows/release.yml) will try to bundle the dependencies in the release zip. +For these dependencies to work, they must be pure python modules. + +From within the plugin, you will also need to use an import pattern similar to the following: + ```py import sys import pathlib @@ -46,7 +56,7 @@ import pathlib import_path = str(pathlib.Path(__file__).parent.parent.parent) -sys.path.insert(0, import_path) +sys.path.append(0, import_path) try: import some_dependency @@ -57,6 +67,8 @@ finally: sys.path.remove(import_path) ``` +If you do not want to bundle the dependencies with the release zip, you can add the dependencies to the exclusion list in the [release action](.github/workflows/release.yml). + ## Release To create a release, simply increment the version in the `pyproject.toml` file. From 5894379d2e9cd18d511e599318574a91c58bf93f Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 30 Nov 2024 11:51:47 +1300 Subject: [PATCH 5/5] Update README.md Co-authored-by: N/Ame <173015200+grqz@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 600e5dc..ee28609 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ import pathlib import_path = str(pathlib.Path(__file__).parent.parent.parent) -sys.path.append(0, import_path) +sys.path.append(import_path) try: import some_dependency