karthik-0306 opened a new pull request, #13402:
URL: https://github.com/apache/seatunnel/pull/13402

   ### Purpose of this pull request
   
   Related to #12707 (pip-installable SeaTunnel launcher).
   
   This PR contributes step 1 of the launcher roadmap on #12707 to Apache 
SeaTunnel: a per-user, per-version cache location and deterministic 
distribution URL construction. As agreed with @SEZ9 and @DanielLeens on #12707, 
it was opened only after #12858 merged, and it is kept strictly to those two 
pieces. It adds `tools/seatunnel-python-sdk/seatunnel/distribution.py` with two 
functions:
   
   - `cache_dir(version)` returns the directory that holds one SeaTunnel 
version for the current user. It only computes the path and never creates it.
   - `distribution_url(version, base_url=DEFAULT_BASE_URL)` returns the URL of 
the binary distribution archive of a release, for example 
`https://downloads.apache.org/seatunnel/3.0.0/apache-seatunnel-3.0.0-bin.tar.gz`.
   
   Behaviour:
   
   1. **Cache location per platform:**
      - Linux: `$XDG_CACHE_HOME/seatunnel/<version>`, or 
`~/.cache/seatunnel/<version>`. A relative `XDG_CACHE_HOME` is ignored, as the 
XDG specification requires.
      - macOS: `~/Library/Caches/seatunnel/<version>`.
      - Windows: `%LOCALAPPDATA%\seatunnel\<version>`, falling back to 
`~\AppData\Local` when `LOCALAPPDATA` is not set.
   
      The result is always an absolute path. If no absolute per-user location 
can be determined, `DistributionError` is raised instead of returning a 
relative path.
   2. **Isolation across users and versions:** each version gets its own folder 
under the same per-user root, and each user gets a root under their own home or 
cache directory, so two versions or two users never share or overwrite files.
   3. **Version validation:** a version must start and end with a letter or 
digit and may only contain `A-Z a-z 0-9 . _ -`. A version can never name a 
folder outside the cache (`..`, `.`, `../x`, `a/b`), and `3.0.` and `3.0` stay 
apart on Windows, which drops a trailing dot from folder names. Whitespace 
around the version is dropped, and `None` or a non-string raises 
`DistributionError`.
   4. **Deterministic URL:** the URL follows the ASF release layout 
`<base_url>/<version>/apache-seatunnel-<version>-bin.tar.gz` and needs no 
network access. The `.sha512` checksum and the `.asc` signature published next 
to the archive are at the same URL with those suffixes, so the verification 
steps can reuse it.
   5. **Base URL:** `base_url` defaults to 
`https://downloads.apache.org/seatunnel`. downloads.apache.org only keeps 
current releases, and the ASF moves older ones to 
`https://archive.apache.org/dist/seatunnel`, which a caller can pass instead. 
It must be an `https://` URL with a host and no query or fragment, so the 
archive, checksum and signature cannot be altered in transit. A trailing slash 
is ignored.
   6. **No side effects:** the module creates no directory, writes no file, 
opens no network connection and downloads nothing.
   
   **Ownership boundary:** `cache_dir()` is the per-user, per-version directory 
that the launcher owns, and it is the only location that later launcher helpers 
(download, extraction, plugin installation through `install_plugins()` from 
#12858) are allowed to modify. It is never a source checkout, a shared 
installation or the Python package directory (`site-packages`), so installing 
or upgrading the Python package neither touches nor loses a downloaded 
distribution. This is stated in the module docstring and in the `cache_dir()` 
docstring, as requested on #12707.
   
   **Design note:** the cache path follows each platform's standard per-user 
cache location instead of a fixed `~/.seatunnel` folder. A downloaded 
distribution can always be fetched again, so it belongs in the cache directory, 
which users and tools expect to be safe to clear. `distribution_url()` takes 
the base URL as a parameter but reads no environment variable. The mirror 
environment variable, the gpg CLI vs. a Python dependency for signature checks, 
and the first target version are left to the steps that need them, as @SEZ9 
asked on #12707.
   
   Scope: two new files under `tools/seatunnel-python-sdk`. The module uses 
only the standard library and is not exported from `seatunnel/__init__.py`. The 
engine, the shell scripts and `plugin_config` are untouched. Usage docs will be 
added in the launcher PR that exposes the command to users.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. It is an internal helper that nothing calls yet, and it is not part of 
the SDK's public API.
   
   ### How was this patch tested?
   
   Added 21 unit tests in 
`tools/seatunnel-python-sdk/tests/test_distribution.py`. They fake 
`sys.platform`, the home directory and the cache-related environment variables, 
so all platforms are tested on any OS, with no network and no files written. 
They cover:
   
   - **URL resolution:** the exact URL for `3.0.0`; the same input always gives 
the same URL; different versions give different URLs; whitespace around the 
version is dropped; a single-character version is accepted
   - **Custom base URL:** `archive.apache.org`, with and without a trailing 
slash
   - **Invalid versions** raise `DistributionError`: `""`, blank, `.`, `..`, 
`../x`, `-3.0.0`, `3.0.`, `3.0-`, `3.0/1`, `3.0\1`, `3.0 beta`, `3.0;rm`, 
`3.0?x=1`, `3.0#frag`, `None` and a non-string
   - **Invalid base URLs** raise `DistributionError`: `http://`, `ftp://`, 
`https://` with no host, a query, a fragment, no scheme, empty and `None`
   - **Cache location per platform:** Linux default, Linux with 
`XDG_CACHE_HOME`, relative `XDG_CACHE_HOME` ignored, macOS, Windows with 
`LOCALAPPDATA`, Windows fallback to the home directory, and a relative location 
raising an error
   - **Isolation across versions:** two versions get sibling folders under the 
same root (`test_versions_are_isolated_from_each_other`)
   - **Isolation across users:** two users get folders under their own home 
directory (`test_users_are_isolated_from_each_other`)
   - **No escape from the cache:** `..`, `.`, `../../etc`, `3.0/../..`, `/abs` 
and `a/b` are rejected 
(`test_version_cannot_name_a_directory_outside_the_cache`)
   - **No side effects:** the path is absolute and the directory is not created 
(`test_cache_dir_is_absolute_and_not_created`). With the real environment, the 
cache is not inside the installed package 
(`test_cache_dir_is_not_inside_the_installed_package`).
   
   Results: all SDK tests pass on Linux (Ubuntu 22.04, Python 3.10: 88 passed) 
and on Windows (Python 3.11: 87 passed, 1 skipped; the skipped one is the 
existing POSIX-only lock test from #12858). The SDK CI workflow runs the same 
suite on Python 3.9 and 3.13.
   
   To run the tests (from `tools/seatunnel-python-sdk/`):
   
       python -m pytest tests/ -v
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License 
Notice according
     [New License 
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the 
following files are updated:
     1. Update 
[plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties)
 and add new connector information in it
     2. Update the pom file of 
[seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in 
[label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in 
[seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector 
[plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to