diff --git a/.github/actions/setup/action.yaml b/.github/actions/setup/action.yaml new file mode 100644 index 0000000..b5ed277 --- /dev/null +++ b/.github/actions/setup/action.yaml @@ -0,0 +1,21 @@ +name: Setup +description: Install uv and sync the project environment + +inputs: + python-version: + description: Python version for uv to install (defaults to uv's own default) + required: false + default: "" + +runs: + using: composite + steps: + - name: Install latest uv + uses: astral-sh/setup-uv@v8.2.0 + with: + python-version: ${{ inputs.python-version }} + enable-cache: true + + - name: Install dependencies + shell: bash + run: uv sync --all-groups diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f160ea5..96592d9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,4 +1,4 @@ -name: Tests +name: CI on: push: @@ -14,49 +14,67 @@ permissions: contents: read jobs: - tests: - timeout-minutes: 45 - runs-on: ${{ matrix.os }} - environment: - name: env1 + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + - uses: ./.github/actions/setup + + - name: Run pre-commit + run: uvx pre-commit run --all-files + + test: + name: Test (Python ${{ matrix.python-version }}) + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: [ubuntu-latest] - pyv: ["3.13"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.pyv }} - cache: 'pip' - - - name: install - run: | - pip install --upgrade pip wheel - pip install -e . pytest - pip list - - - name: run tests - timeout-minutes: 15 - env: - GDRIVE_FSSPEC_DRIVE: gdrivefs-testing - GDRIVE_FSSPEC_CREDENTIALS_PATH: ${{ secrets.GDRIVE_FSSPEC_CREDENTIALS_PATH }} - # Override the default marker filter so CI runs integration tests too. - run: pytest -vv -m "" + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + + - uses: ./.github/actions/setup + with: + python-version: ${{ matrix.python-version }} + + - name: Run unit tests + run: uv run pytest -v + + integration: + name: Integration tests + runs-on: ubuntu-latest + # Run only when Drive credentials are available: manual dispatch, pushes to + # master, or PRs from this repo (fork PRs are skipped — they cannot use secrets). + if: >- + github.event_name == 'workflow_dispatch' || + (github.event_name == 'push' && github.ref == 'refs/heads/master') || + (github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository) + timeout-minutes: 15 + environment: + name: env1 - lint: - name: lint - runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@main - - uses: actions/setup-python@main + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + + - uses: ./.github/actions/setup with: - python-version: "3.11" - - uses: pre-commit/action@main + python-version: "3.13" + + - name: Run integration tests + env: + GDRIVE_FSSPEC_DRIVE: gdrivefs-testing + GDRIVE_FSSPEC_CREDENTIALS_PATH: ${{ secrets.GDRIVE_FSSPEC_CREDENTIALS_PATH }} + run: uv run pytest -v -m integration diff --git a/.gitignore b/.gitignore index 364a4ab..caa9a83 100644 --- a/.gitignore +++ b/.gitignore @@ -90,6 +90,7 @@ celerybeat-schedule .venv venv/ ENV/ +uv.lock .idea/ # Spyder project settings @@ -105,5 +106,5 @@ ENV/ # mypy .mypy_cache/ -/gdrive_fsspec/_version.py +/src/gdrive_fsspec/_version.py /tmp/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 39640d0..4545198 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ exclude: > repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -13,15 +13,13 @@ repos: - id: check-json - id: check-yaml - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.9.2 + rev: v0.15.16 hooks: - # Run the linter. - id: ruff - args: [ --fix, "--show-fixes"] + args: [--fix, --show-fixes] - id: ruff-format types_or: [python] - repo: https://github.com/codespell-project/codespell - rev: v2.4.0 + rev: v2.4.2 hooks: - id: codespell diff --git a/README.md b/README.md index 62d8b5f..30d5f7d 100644 --- a/README.md +++ b/README.md @@ -75,33 +75,66 @@ See ``GoogleDriveFileSystem`` docstring for more details. ## Development +### Setup + +1. Install `uv` and `pre-commit`: + +- [uv install docs](https://docs.astral.sh/uv/getting-started/installation/) +- [pre-commit install docs](https://pre-commit.com/#install) + +2. Clone your fork and `cd` into the repo: + +```sh +git clone git@github.com:/gdrive-fsspec.git +cd gdrive-fsspec +``` + +3. Set up the environment: +```sh +uv sync +pre-commit install +``` + ### Running tests -The integration tests require the following environment variables: +There are unit tests and integration tests. Integration tests use a directory +named `gdrive_fsspec_testdir` on Google Drive. + +**Unit tests** mock the Google Drive API and need no credentials. By default, +`pytest` runs unit tests only: + +```sh +uv run pytest -v +``` + +**Integration tests** hit a real Google Drive account: + +```sh +uv run pytest -v -m integration +``` + +Set these environment variables before running them: - `GDRIVE_FSSPEC_CREDENTIALS_PATH` — path to a service-account JSON, or the JSON string (starting with `{`). Required when using `service_account` (the default). - `GDRIVE_FSSPEC_CREDENTIALS_TYPE` — token type (`service_account` default; use `cache` or `browser` for user OAuth). - `GDRIVE_FSSPEC_DRIVE` — **Shared Drive name**. Required for service-account upload tests. -Service accounts cannot own files in Google Drive and have no storage quota. Uploads must target a [Shared Drive](https://developers.google.com/workspace/drive/api/guides/about-shareddrives) where the service account is a member with at least **Contributor** access. See [Google’s storage-limit errors](https://developers.google.com/workspace/drive/api/guides/handle-errors#storage-limit). +Service accounts cannot own files in Google Drive and have no storage quota. +Uploads must target a [Shared Drive](https://developers.google.com/workspace/drive/api/guides/about-shareddrives) where the service account is a member with at least **Contributor** access. +See [Google’s storage-limit errors](https://developers.google.com/workspace/drive/api/guides/handle-errors#storage-limit). -For a personal Drive (no Shared Drive), run tests with user OAuth instead: `GDRIVE_FSSPEC_CREDENTIALS_TYPE=cache` after a one-time `browser` login. +For a personal Drive (no Shared Drive), use user OAuth instead: +`GDRIVE_FSSPEC_CREDENTIALS_TYPE=cache` after a one-time `browser` login. -All tests use a directory named `gdrive_fsspec_testdir`. +To run all tests, override the default marker filter: ```sh -pip install -e . pytest -pytest -v -m "" +uv run pytest -v -m "" ``` -### Style - -Please run pre-commit before submitting PRs. You can automate this by -calling -```bash -$ pre-commit install -``` -in the repo (once) before committing. +> **Note:** Integration tests do not run on PRs from forks, because those +> workflows cannot use repository secrets. They run on pushes to `master` and same repo PRs. +> Google Drive has no good emulator; see [link](https://github.com/fsspec/gdrive-fsspec/issues/23#issuecomment-2030367587). ## Other implementations diff --git a/pyproject.toml b/pyproject.toml index 955c6fe..4d7533d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,14 +8,14 @@ dynamic = ["version"] description = "File system on GDrive" readme = {file = "README.md", content-type = "text/markdown"} requires-python = ">=3.10" -license = { file = "LICENSE" } +license = "BSD-3-Clause" +license-files = ["LICENSE"] maintainers = [ {name = "Martin Durant", email = "martin.durant@alumni.utoronto.ca"} ] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -34,13 +34,14 @@ dependencies = [ [dependency-groups] dev = [ "pytest>=9.0.3", + "ruff>=0.15.16", ] [project.urls] Source = "http://github.com/fsspec/gdrive-fsspec" [tool.setuptools_scm] -version_file = "gdrive_fsspec/_version.py" +version_file = "src/gdrive_fsspec/_version.py" [tool.pytest.ini_options] addopts = """\ diff --git a/gdrive_fsspec/__init__.py b/src/gdrive_fsspec/__init__.py similarity index 100% rename from gdrive_fsspec/__init__.py rename to src/gdrive_fsspec/__init__.py diff --git a/gdrive_fsspec/core.py b/src/gdrive_fsspec/core.py similarity index 100% rename from gdrive_fsspec/core.py rename to src/gdrive_fsspec/core.py diff --git a/tests/conftest.py b/tests/conftest.py index 895e1b5..48c54ec 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ import pytest -from gdrive_fsspec.core import GoogleDriveFileSystem +from gdrive_fsspec import GoogleDriveFileSystem @pytest.fixture()