songbirdcli 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *
2
+ !songbirdcli
3
+ !pyproject.toml
4
+ !tests
@@ -0,0 +1,65 @@
1
+ name: Docker Build/Publish Image
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ branches: [main]
7
+ release:
8
+ types: [published]
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-22.04
12
+ env:
13
+ DOCKER_REGISTRY: docker.io
14
+ DOCKER_IMAGE: cboin/songbird
15
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
16
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
17
+ DOCKER_TARGET_PLATFORM_x64: linux/amd64
18
+ DOCKER_TARGET_PLATFORM_ARM: linux/arm64/v8
19
+ # specify stage in multi-stage build to build up to
20
+ # using --target parameter in buildx
21
+ DOCKER_BUILD_TO_TARGET: build-image
22
+ DOCKER_PUSH: false
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - name: Get Commit or Tag
26
+ id: vars
27
+ run: |
28
+ tag="${GITHUB_SHA:0:8}"
29
+ if [ "${GITHUB_EVENT_NAME}" == "release" ]; then
30
+ ref="${GITHUB_REF}"
31
+ tag=$(echo $GITHUB_REF | sed 's/refs\/tags\///g')
32
+ fi
33
+ echo "TAG=$tag" >> $GITHUB_OUTPUT
34
+ - name: Set up Docker Buildx
35
+ uses: docker/setup-buildx-action@v3
36
+ - name: Prepare
37
+ if: success()
38
+ id: prepare
39
+ run: |
40
+ echo "DOCKER_PLATFORM_ARM=${DOCKER_TARGET_PLATFORM_ARM}" >> $GITHUB_OUTPUT
41
+ echo "DOCKER_PLATFORM_AMD64=${DOCKER_TARGET_PLATFORM_x64}" >> $GITHUB_OUTPUT
42
+ echo "DOCKER_IMAGE=${DOCKER_REGISTRY}/${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
43
+ echo "VERSION=${{steps.vars.outputs.TAG}}" >> $GITHUB_OUTPUT
44
+ echo "DOCKER_BUILD_TO_TARGET=${DOCKER_BUILD_TO_TARGET}" >> $GITHUB_OUTPUT
45
+ - name: Docker Login
46
+ if: success()
47
+ run: |
48
+ echo "${DOCKER_PASSWORD}" | docker login ${DOCKER_REGISTRY} --username "${DOCKER_USERNAME}" --password-stdin
49
+ - name: Run Buildx
50
+ if: success() && github.event_name == 'pull_request' # trigger only a build on PR's.
51
+ run: |
52
+ docker buildx build --platform ${{ steps.prepare.outputs.DOCKER_PLATFORM_AMD64 }},${{ steps.prepare.outputs.DOCKER_PLATFORM_ARM }} \
53
+ --target ${{ steps.prepare.outputs.DOCKER_BUILD_TO_TARGET }} \
54
+ -t ${{ steps.prepare.outputs.DOCKER_IMAGE }}:${{steps.prepare.outputs.VERSION}} \
55
+ -t ${{ steps.prepare.outputs.DOCKER_IMAGE }}:latest \
56
+ --file ./Dockerfile \
57
+ -o type=image,push=false .
58
+ - name: Run Buildx (push image)
59
+ if: success() && github.event_name == 'push' || github.event_name == 'release' # trigger a build and push to docker registry
60
+ run: |
61
+ docker buildx build --platform ${{ steps.prepare.outputs.DOCKER_PLATFORM_AMD64 }},${{ steps.prepare.outputs.DOCKER_PLATFORM_ARM }} \
62
+ --target ${{ steps.prepare.outputs.DOCKER_BUILD_TO_TARGET }} \
63
+ -t ${{ steps.prepare.outputs.DOCKER_IMAGE }}:${{steps.prepare.outputs.VERSION}} \
64
+ -t ${{ steps.prepare.outputs.DOCKER_IMAGE }}:latest \
65
+ --file ./Dockerfile -o type=image,push=true .
@@ -0,0 +1,118 @@
1
+ name: pypi-publish
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ name: Build distribution 📦
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Python
13
+ uses: actions/setup-python@v4
14
+ with:
15
+ python-version: "3.x"
16
+ - name: Install pypa/build
17
+ run: >-
18
+ python3 -m
19
+ pip install
20
+ build
21
+ --user
22
+ - name: Build a binary wheel and a source tarball
23
+ run: python3 -m build
24
+ - name: Store the distribution packages
25
+ uses: actions/upload-artifact@v3
26
+ with:
27
+ name: python-package-distributions
28
+ path: dist/
29
+
30
+ publish-to-pypi:
31
+ name: >-
32
+ Publish Python 🐍 distribution 📦 to PyPI
33
+ if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
34
+ needs:
35
+ - build
36
+ runs-on: ubuntu-latest
37
+ environment:
38
+ name: pypi
39
+ url: https://pypi.org/p/songbirdcli # Replace <package-name> with your PyPI project name
40
+ permissions:
41
+ id-token: write # IMPORTANT: mandatory for trusted publishing
42
+
43
+ steps:
44
+ - name: Download all the dists
45
+ uses: actions/download-artifact@v3
46
+ with:
47
+ name: python-package-distributions
48
+ path: dist/
49
+ - name: Publish distribution 📦 to PyPI
50
+ uses: pypa/gh-action-pypi-publish@release/v1
51
+
52
+ github-release:
53
+ name: >-
54
+ Sign the Python 🐍 distribution 📦 with Sigstore
55
+ and upload them to GitHub Release
56
+ needs:
57
+ - publish-to-pypi
58
+ runs-on: ubuntu-latest
59
+
60
+ permissions:
61
+ contents: write # IMPORTANT: mandatory for making GitHub Releases
62
+ id-token: write # IMPORTANT: mandatory for sigstore
63
+
64
+ steps:
65
+ - name: Download all the dists
66
+ uses: actions/download-artifact@v3
67
+ with:
68
+ name: python-package-distributions
69
+ path: dist/
70
+ - name: Sign the dists with Sigstore
71
+ uses: sigstore/gh-action-sigstore-python@v1.2.3
72
+ with:
73
+ inputs: >-
74
+ ./dist/*.tar.gz
75
+ ./dist/*.whl
76
+ - name: Create GitHub Release
77
+ env:
78
+ GITHUB_TOKEN: ${{ github.token }}
79
+ run: >-
80
+ gh release create
81
+ '${{ github.ref_name }}'
82
+ --repo '${{ github.repository }}'
83
+ --notes ""
84
+ - name: Upload artifact signatures to GitHub Release
85
+ env:
86
+ GITHUB_TOKEN: ${{ github.token }}
87
+ # Upload to GitHub Release using the `gh` CLI.
88
+ # `dist/` contains the built packages, and the
89
+ # sigstore-produced signatures and certificates.
90
+ run: >-
91
+ gh release upload
92
+ '${{ github.ref_name }}' dist/**
93
+ --repo '${{ github.repository }}'
94
+
95
+ publish-to-testpypi:
96
+ name: Publish Python 🐍 distribution 📦 to TestPyPI
97
+ needs:
98
+ - build
99
+ runs-on: ubuntu-latest
100
+ # run if push to main
101
+ if: github.ref == 'refs/heads/main'
102
+ environment:
103
+ name: testpypi
104
+ url: https://test.pypi.org/p/songbirdcli
105
+
106
+ permissions:
107
+ id-token: write # IMPORTANT: mandatory for trusted publishing
108
+
109
+ steps:
110
+ - name: Download all the dists
111
+ uses: actions/download-artifact@v3
112
+ with:
113
+ name: python-package-distributions
114
+ path: dist/
115
+ - name: Publish distribution 📦 to TestPyPI
116
+ uses: pypa/gh-action-pypi-publish@release/v1
117
+ with:
118
+ repository-url: https://test.pypi.org/legacy/
@@ -0,0 +1,15 @@
1
+ name: Lint
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ lint:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: psf/black@stable
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: 3.11
@@ -0,0 +1,50 @@
1
+ name: tests
2
+
3
+ on:
4
+ # run tests on all PR's to main.
5
+ pull_request:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.11", "3.12"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - name: Install dependencies
22
+ run: |
23
+ sudo apt-get update && sudo apt-get install -y --no-install-recommends ffmpeg
24
+ python -m pip install --upgrade pip
25
+ pip install -e .[dev]
26
+ playwright install
27
+ - name: Test with pytest
28
+ run: |
29
+ python -m pytest --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=songbirdcli --cov-report=xml --cov-report=html tests/unit -v
30
+ - name: Upload pytest results
31
+ uses: actions/upload-artifact@v4
32
+ with:
33
+ name: pytest-results-${{ matrix.python-version }}
34
+ path: junit/test-results-${{ matrix.python-version }}.xml
35
+ # Use always() to always run this step to publish test results when there are test failures
36
+ if: ${{ always() }}
37
+ - name: Upload xml coverage
38
+ uses: actions/upload-artifact@v4
39
+ with:
40
+ name: pytest-coverage-xml-${{ matrix.python-version }}
41
+ path: coverage.xml
42
+ # Use always() to always run this step to publish test results when there are test failures
43
+ if: ${{ always() }}
44
+ - name: Upload html coverage
45
+ uses: actions/upload-artifact@v4
46
+ with:
47
+ name: pytest-coverage-html-${{ matrix.python-version }}
48
+ path: htmlcov/
49
+ # Use always() to always run this step to publish test results when there are test failures
50
+ if: ${{ always() }}
@@ -0,0 +1,30 @@
1
+ # ENV files
2
+ *.env
3
+
4
+ # Vscode
5
+ .vscode
6
+
7
+ # Python
8
+ __pycache__
9
+ venv
10
+ *.egg-info
11
+
12
+
13
+ # Taskfile
14
+ .task
15
+
16
+ # Work directories
17
+ app
18
+ data
19
+ tests-output
20
+ # pytest junit output
21
+ junit
22
+
23
+ # code coverage
24
+ coverage.xml
25
+ .coverage
26
+ htmlcov
27
+
28
+ # Secrets
29
+ credentials.json
30
+ token.json
@@ -0,0 +1,54 @@
1
+ FROM ubuntu:23.04 AS builder
2
+
3
+ WORKDIR /app
4
+
5
+ # make sure we use the venv
6
+ ENV PATH="/venv/bin:$PATH"
7
+
8
+ RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc git python3 python3-pip python3-venv && \
9
+ rm -rf /var/lib/apt/lists/*
10
+
11
+ # setup venv
12
+ RUN python3 -m venv /venv
13
+
14
+ COPY songbirdcli/requirements.txt .
15
+
16
+ # install dependencies
17
+ RUN pip install --no-cache-dir -r requirements.txt
18
+
19
+ FROM ubuntu:23.04 as build-image
20
+
21
+ ENV PATH="/venv/bin:$PATH"
22
+
23
+ WORKDIR /app
24
+ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg python3-pip \
25
+ # playwright deps
26
+ libnss3 \
27
+ libnspr4 \
28
+ libatk1.0-0 \
29
+ libatk-bridge2.0-0 \
30
+ libcups2 \
31
+ libatspi2.0-0 \
32
+ libxcomposite1 \
33
+ libxdamage1 && \
34
+ # clear cache
35
+ rm -rf /var/lib/apt/lists/*
36
+
37
+ # copy venv
38
+ COPY --from=builder /venv /venv
39
+ # copy app contents
40
+ COPY ./songbirdcli/ ./songbirdcli
41
+ COPY pyproject.toml .
42
+
43
+ # install package locally, and setup playwright
44
+ RUN pip install . && playwright install chromium
45
+
46
+ CMD ["python3", "songbirdcli/cli.py"]
47
+
48
+ # RUN tests to confirm built code runs as expected
49
+ FROM build-image as test
50
+
51
+ RUN pip install -e .[dev]
52
+ COPY tests ./tests
53
+ WORKDIR /app
54
+ RUN python3 -m pytest ./tests/unit/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Christian Boin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,117 @@
1
+ APP_NAME=songbirdcli
2
+ REQUIREMENTS_FILE=requirements.txt
3
+
4
+ .PHONY: env
5
+ env:
6
+ # check ENV env var has been set
7
+ ifndef ENV
8
+ $(error Must set ENV variable!)
9
+ endif
10
+ # load env vars from .env file if present
11
+ ifneq ("$(wildcard $(ENV).env)", "")
12
+ @echo "Loading configuration from $(ENV).env"
13
+ # include cannot be indented
14
+ include $(ENV).env
15
+ else
16
+ @echo "Continuing without .env file."
17
+ @echo "Creating template $(ENV).env file"
18
+ echo 'RUN_LOCAL=false' > $(ENV).env
19
+ echo 'ITUNES_ENABLED=true' >> $(ENV).env
20
+ echo 'GDRIVE_ENABLED=true' >> $(ENV).env
21
+ endif
22
+
23
+ # variables as a list, required for pytest targets
24
+ # in this makefile
25
+ ENV_VARS = $(shell cat $(ENV).env | xargs)
26
+
27
+ .PHONY: setup
28
+ setup:
29
+ @echo sets up the development environment
30
+ python3 -m venv venv
31
+ @echo activate venv with 'source venv/bin/activate'
32
+
33
+ # /app/data folder is legacy for backwards compatability
34
+ # from the times before songbird was split across
35
+ # core, cli and api.
36
+ .PHONY: volumesinit
37
+ volumesinit:
38
+ mkdir -p ./$(APP_NAME)/data/dump
39
+ mkdir -p ./$(APP_NAME)/data/local_chromium
40
+ mkdir -p ./$(APP_NAME)/data/gdrive
41
+
42
+ .PHONY: volumesclean
43
+ volumesclean:
44
+ rm -rf ./$(APP_NAME)/data/dump
45
+ rm -rf ./$(APP_NAME)/data/local_chromium
46
+ rm -rf ./$(APP_NAME)/data/gdrive
47
+
48
+ .PHONY: requirements
49
+ requirements: env
50
+ pip install -r $(APP_NAME)/$(REQUIREMENTS_FILE)
51
+ # only install dependencies locally if in dev env
52
+ ifeq ($(ENV), dev)
53
+ echo "install dev dependencies"
54
+ pip install -e .[dev]
55
+ pip install -e ../songbirdcore
56
+ else
57
+ pip install -e .
58
+ endif
59
+ playwright install
60
+
61
+ .PHONY: update-requirements
62
+ update-requirements: env
63
+ pip uninstall songbirdcore
64
+ pip freeze --exclude-editable | xargs pip uninstall -y
65
+ rm $(APP_NAME)/$(REQUIREMENTS_FILE) || true
66
+ pip install -r $(APP_NAME)/requirements.txt.blank
67
+ pip freeze --exclude-editable > $(APP_NAME)/$(REQUIREMENTS_FILE)
68
+
69
+ .PHONY: build
70
+ build:
71
+ docker build -t $(APP_NAME):latest .
72
+
73
+ .PHONY: run-itunes
74
+ run-itunes:
75
+ docker run -it --env-file docker.env \
76
+ -v "${HOME}"/songbirdcli/data/dump:/app/data/dump \
77
+ -v "${HOME}"/songbirdcli/data/local_chromium:/root/.local/share/pyppeteer/local-chromium \
78
+ -v "${HOME}"/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music.localized:/app/data/itunesauto \
79
+ -v "${HOME}"/Music/Itunes/Itunes\ Media/Music:/app/data/ituneslib \
80
+ $(APP_NAME):latest
81
+
82
+ .PHONY: run-gdrive
83
+ run-gdrive:
84
+ docker run -it --env-file docker.env \
85
+ -v "${PWD}"/songbirdcli/data/dump:/app/data/dump \
86
+ -v "${PWD}"/songbirdcli/data/local_chromium:/root/.local/share/pyppeteer/local-chromium \
87
+ -v "${PWD}"/songbirdcli/data/gdrive:/app/data/gdrive \
88
+ -p 8080:8080 \
89
+ --hostname songbird \
90
+ $(APP_NAME):latest
91
+
92
+ .PHONY: run-default
93
+ run-default:
94
+ docker run -it --env-file docker.env \
95
+ -v "${PWD}"/songbirdcli/data/dump:/app/data/dump \
96
+ $(APP_NAME):latest
97
+
98
+ .PHONY: clean
99
+ clean:
100
+ docker rm $(APP_NAME) || true
101
+
102
+ .PHONY: stop
103
+ stop:
104
+ docker kill $(APP_NAME)
105
+
106
+ .PHONY: dev
107
+ dev: clean build run
108
+
109
+ lint:
110
+ black $(APP_NAME)/.
111
+ black tests
112
+
113
+ test:
114
+ python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=songbirdcli --cov-report=xml --cov-report=html tests/unit -v
115
+
116
+ test-env:
117
+ $(ENV_VARS) python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=songbirdcli --cov-report=xml --cov-report=html tests/unit -v