Skip to content

Commit

Permalink
feat: refactor codebase, extend configuration file support
Browse files Browse the repository at this point in the history
Changes:
- Load configuration files from current directory when run as an executable
- Add support for YAML and TOML configuration files and convert default configuration file into those formats
- Generate new configuration file locations for files with .yaml, .yml and .toml extensions
- Add PyYAML as a dependency; tomllib is available in the Python standard library from 3.11 upwards
- Bump minimum supported Python version to 3.12
- Capture and log error messages from exceptions raised with exit code 2 when loading configuration files
- Override default Logger class and add method to log multi-line messages
- Log Windows paths with non-escaped backslashes
- If no configuration file can be loaded, exit the process immediately with exit code 1
- Only create one template instance (on application startup) for best performance
- Add startup log message with uvicorn logger acknowledging Starlette
- Add checks for Docker and Kubernetes container environments
- Add version number in package and display in web UI
- Minor web UI margin and text adjustments
- Open all web UI links in a new tab
- Update README to reflect changes
- Refactor code, add new functions for utility
- Add type hints
- Add coding declaration to the top of each Python script
- Update workflow to use main branch README to update Docker Hub description after pushing a new image
- Include pyproject.toml file for configuring ruff: change enforced line length from 88 to 100 and target version from py39 to py312
- Update pre-commit hooks and use check-merge-conflict and check-toml hooks
- Use --fix instead of --fix-only for ruff linter pre-commit hook
  • Loading branch information
qx6ghqkz committed Jan 17, 2025
1 parent 0058f43 commit 5d1e625
Show file tree
Hide file tree
Showing 17 changed files with 2,167 additions and 293 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ logs/
build/
dist/
*.spec

# Config
docs/config.*
pyproject.toml
16 changes: 8 additions & 8 deletions .github/workflows/dependabot-auto-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ permissions:

jobs:
dependabot:
name: 'Dependabot'
name: Dependabot
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.2.0
- name: Fetch Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: '${{ secrets.PERSONAL_TOKEN }}'
github-token: ${{ secrets.PERSONAL_TOKEN }}
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.PERSONAL_TOKEN}}
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
12 changes: 11 additions & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
Expand All @@ -67,3 +67,13 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Update Docker Hub description
if: ${{ github.ref_name == github.event.repository.default_branch }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ github.repository }}
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
11 changes: 7 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
types: [file] # override `types: [json]`
types: [file]
files: \.(json|conf)$
- id: check-yaml
- id: check-toml
- id: detect-private-key
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.10
rev: v0.9.2
hooks:
- id: ruff
args: [--fix-only]
args: [--fix]
- id: ruff-format
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ services:

### Python

If you have Python 3.9 or above installed and on your PATH, you can simply run the server using the command line. Clone this repository and install the required dependencies located in `requirements.txt` in a virtual environment.
If you have Python 3.12 or later installed and on your PATH, you can simply run the server using the command line. Clone this repository and install the required dependencies located in `requirements.txt` in a virtual environment.

Run the command below in the root folder while inside the virtual environment. On Windows, replace `python3` with `python`.

Expand Down Expand Up @@ -128,22 +128,30 @@ services:

## Configuration

Configuration of gallery-dl is as documented in the [official documentation](https://github.com/mikf/gallery-dl#configuration).
Configuration of gallery-dl is as documented in the [official documentation](https://github.com/mikf/gallery-dl#configuration). A configuration file is **required.**

A configuration file is **required.** If running outside of Docker, the [default locations](https://github.com/mikf/gallery-dl#locations) will be used to search for a configuration file. When running *with* Docker, the configuration file must be mounted inside the Docker container in one of the locations where gallery-dl-server will search for the config file.
If run outside of Docker, the [default locations](https://github.com/mikf/gallery-dl#locations) will be used to search for a configuration file. If run as an executable, the current directory will also be searched for a valid configuration file.

Additionally, YAML and TOML configuration files are supported at any of the pre-defined locations.

When run with Docker, the configuration file must be mounted inside the `/config` directory inside the container.

### Locations

- `/config/gallery-dl.conf`
- `/config/gallery-dl.{yaml, yml}`
- `/config/gallery-dl.toml`
- `/config/config.json`
- `/config/config.{yaml, yml}`
- `/config/config.toml`

A [default configuration file](docs/gallery-dl.conf) for use with gallery-dl-server has been provided and will automatically be placed in the directory mounted to `/config` if no valid config file exists in that location.
A [default configuration file](docs/gallery-dl.conf) for use with gallery-dl-server has been provided and will automatically be placed in the directory mounted to `/config` if no valid configuration file exists in that location.

For more information on configuration file options, see [gallery-dl/docs/configuration.rst](https://github.com/mikf/gallery-dl/blob/master/docs/configuration.rst).

Any additional locations specified in the configuration file must also exist inside the Docker container. For example, if you specify a cookies file location, make sure that location is accessible from within the Docker container.
Any additional locations specified in the configuration file must also exist inside the Docker container. For example, if you specify a cookies file location, ensure that location is accessible from within the Docker container.

It is recommended you place any additional files such as archive, cache and cookies files inside the same directory mounted to `/config` along with the config file.
It is recommended you place any additional files such as archive, cache and cookies files inside the same directory mounted to `/config` along with the configuration file.

## Usage

Expand Down
Loading

0 comments on commit 5d1e625

Please sign in to comment.