-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mraspaud/add-scripts
Add cli and git-based version
- Loading branch information
Showing
8 changed files
with
207 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
exclude: '^$' | ||
fail_fast: false | ||
|
||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: 'v0.3.7' | ||
hooks: | ||
- id: ruff | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: no-commit-to-branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
[project] | ||
name = "pytroll-watchers" | ||
version = "0.1.0" | ||
dynamic = ["version"] | ||
description = "Utility functions and scripts to watch for new files on local or remote filesystems." | ||
authors = [ | ||
{ name = "Martin Raspaud", email = "[email protected]" } | ||
] | ||
dependencies = ["universal-pathlib", "trollsift"] | ||
dependencies = ["universal-pathlib", "trollsift", "pyyaml"] | ||
readme = "README.md" | ||
requires-python = ">= 3.10" | ||
license = {file = "LICENSE.txt"} | ||
|
||
[project.scripts] | ||
pytroll-watcher = "pytroll_watchers.main_interface:cli" | ||
|
||
[project.urls] | ||
"Documentation" = "https://pytroll-watchers.readthedocs.io/en/latest/" | ||
|
||
|
@@ -20,7 +23,7 @@ publishing = ["posttroll"] | |
ssh = ["paramiko"] | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
requires = ["hatchling", "hatch-vcs"] | ||
build-backend = "hatchling.build" | ||
|
||
[tool.rye] | ||
|
@@ -33,6 +36,13 @@ allow-direct-references = true | |
[tool.hatch.build.targets.wheel] | ||
packages = ["src/pytroll_watchers"] | ||
|
||
[tool.hatch.version] | ||
source = "vcs" | ||
|
||
[tool.hatch.build.hooks.vcs] | ||
version-file = "src/pytroll_watchers/version.py" | ||
|
||
|
||
[tool.ruff] | ||
line-length = 120 | ||
|
||
|
@@ -43,6 +53,7 @@ select = ["A", "B", "D", "E", "W", "F", "I", "N", "PT", "S", "TID", "C90", "Q", | |
[tool.ruff.lint.per-file-ignores] | ||
"tests/*" = ["S101"] # assert allowed in tests | ||
"docs/source/conf.py" = ["D100", "A001"] # sphinx misbihaving | ||
"src/pytroll_watchers/version.py" = ["D100", "Q000"] # automatically generated by hatch-vcs | ||
|
||
[tool.ruff.lint.pydocstyle] | ||
convention = "google" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1 @@ | ||
"""Main package file for pytroll watchers.""" | ||
|
||
from pytroll_watchers.local_watcher import file_generator as local_generator | ||
from pytroll_watchers.local_watcher import file_publisher as local_publisher | ||
from pytroll_watchers.minio_notification_watcher import file_generator as minio_generator | ||
from pytroll_watchers.minio_notification_watcher import file_publisher as minio_publisher | ||
|
||
|
||
def get_publisher_for_backend(backend): | ||
"""Get the right publisher for the given backend. | ||
For the parameters to pass the returned function, check the individual backend documentation pages. | ||
Example: | ||
>>> file_publisher = get_publisher_for_backend("local") | ||
>>> file_publisher(fs_config, publisher_config, message_config) | ||
""" | ||
if backend == "minio": | ||
return minio_publisher | ||
elif backend == "local": | ||
return local_publisher | ||
else: | ||
raise ValueError(f"Unknown backend {backend}.") | ||
|
||
def get_generator_for_backend(backend): | ||
"""Get the right generator for the given backend. | ||
For the parameters to pass the returned function, check the individual backend documentation pages. | ||
Example: | ||
>>> file_generator = get_generator_for_backend("local") | ||
>>> for filename, file_metadata in file_generator("/tmp"): | ||
... # do something with filename and file_metadata | ||
""" | ||
if backend == "minio": | ||
return minio_generator | ||
elif backend == "local": | ||
return local_generator | ||
else: | ||
raise ValueError(f"Unknown backend {backend}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Main interface functions.""" | ||
|
||
import argparse | ||
|
||
import yaml | ||
|
||
from pytroll_watchers.local_watcher import file_generator as local_generator | ||
from pytroll_watchers.local_watcher import file_publisher as local_publisher | ||
from pytroll_watchers.minio_notification_watcher import file_generator as minio_generator | ||
from pytroll_watchers.minio_notification_watcher import file_publisher as minio_publisher | ||
|
||
|
||
def get_publisher_for_backend(backend): | ||
"""Get the right publisher for the given backend. | ||
For the parameters to pass the returned function, check the individual backend documentation pages. | ||
Example: | ||
>>> file_publisher = get_publisher_for_backend("local") | ||
>>> file_publisher(fs_config, publisher_config, message_config) | ||
""" | ||
if backend == "minio": | ||
return minio_publisher | ||
elif backend == "local": | ||
return local_publisher | ||
else: | ||
raise ValueError(f"Unknown backend {backend}.") | ||
|
||
def get_generator_for_backend(backend): | ||
"""Get the right generator for the given backend. | ||
For the parameters to pass the returned function, check the individual backend documentation pages. | ||
Example: | ||
>>> file_generator = get_generator_for_backend("local") | ||
>>> for filename, file_metadata in file_generator("/tmp"): | ||
... # do something with filename and file_metadata | ||
""" | ||
if backend == "minio": | ||
return minio_generator | ||
elif backend == "local": | ||
return local_generator | ||
else: | ||
raise ValueError(f"Unknown backend {backend}.") | ||
|
||
|
||
def publish_from_config(config): | ||
"""Publish files/objects given a config. | ||
Args: | ||
config: a dictionary containing the `backend` string (`local` or `minio`), and `fs_config`, `publisher_config` | ||
and `message_config` dictionaries. | ||
""" | ||
if config["backend"] == "local": | ||
return local_publisher(config["fs_config"], config["publisher_config"], config["message_config"]) | ||
elif config["backend"] == "minio": | ||
return minio_publisher(config["fs_config"], config["publisher_config"], config["message_config"]) | ||
else: | ||
raise ValueError(f"Unknown backend {config['backend']}") | ||
|
||
def cli(args=None): | ||
"""Command-line interface for pytroll-watchers.""" | ||
parser = argparse.ArgumentParser( | ||
prog="pytroll-watcher", | ||
description="Watches the appearance of new files/objects on different filesystems.", | ||
epilog="Thanks for using pytroll-watchers!") | ||
|
||
parser.add_argument("config", type=str, help="The yaml config file.") | ||
|
||
parsed = parser.parse_args(args) | ||
|
||
config_file = parsed.config | ||
|
||
with open(config_file) as fd: | ||
config_dict = yaml.safe_load(fd.read()) | ||
|
||
return publish_from_config(config_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters