docput 1.0.2__tar.gz → 1.1.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.
Files changed (60) hide show
  1. {docput-1.0.2 → docput-1.1.0}/.forgejo/workflows/push.yml +3 -3
  2. {docput-1.0.2 → docput-1.1.0}/CHANGELOG.md +14 -2
  3. {docput-1.0.2 → docput-1.1.0}/Justfile +4 -4
  4. {docput-1.0.2 → docput-1.1.0}/PKG-INFO +11 -8
  5. {docput-1.0.2 → docput-1.1.0}/README.md +7 -7
  6. docput-1.1.0/docs/.gitignore +2 -0
  7. {docput-1.0.2 → docput-1.1.0}/docs/Justfile +4 -4
  8. {docput-1.0.2 → docput-1.1.0}/docs/installation.md +2 -1
  9. {docput-1.0.2 → docput-1.1.0}/docs/user_guide.md +0 -1
  10. {docput-1.0.2 → docput-1.1.0}/pyproject.toml +6 -4
  11. docput-1.1.0/src/docput/cli/main.py +169 -0
  12. {docput-1.0.2 → docput-1.1.0}/src/docput/cli/manifest.py +5 -5
  13. {docput-1.0.2 → docput-1.1.0}/src/docput/cli/version.py +25 -19
  14. docput-1.1.0/src/docput/remote/__init__.py +90 -0
  15. {docput-1.0.2 → docput-1.1.0}/src/docput/remote/base.py +15 -11
  16. docput-1.1.0/src/docput/remote/exceptions.py +6 -0
  17. {docput-1.0.2 → docput-1.1.0}/src/docput/remote/filesystem.py +17 -5
  18. docput-1.1.0/src/docput/remote/git_pages/__init__.py +202 -0
  19. docput-1.1.0/src/docput/remote/git_pages/archive.py +186 -0
  20. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/PKG-INFO +11 -8
  21. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/SOURCES.txt +3 -1
  22. docput-1.1.0/src/docput.egg-info/requires.txt +8 -0
  23. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/scm_file_list.json +3 -1
  24. docput-1.1.0/src/docput.egg-info/scm_version.json +8 -0
  25. {docput-1.0.2 → docput-1.1.0}/tests/test_remotes.py +35 -7
  26. docput-1.0.2/docs/.gitignore +0 -1
  27. docput-1.0.2/src/docput/cli/main.py +0 -132
  28. docput-1.0.2/src/docput/remote/__init__.py +0 -43
  29. docput-1.0.2/src/docput/remote/git_pages.py +0 -202
  30. docput-1.0.2/src/docput.egg-info/requires.txt +0 -3
  31. docput-1.0.2/src/docput.egg-info/scm_version.json +0 -8
  32. {docput-1.0.2 → docput-1.1.0}/.gitignore +0 -0
  33. {docput-1.0.2 → docput-1.1.0}/LICENSE.md +0 -0
  34. {docput-1.0.2 → docput-1.1.0}/docs/_include/forgejo-hover.svg +0 -0
  35. {docput-1.0.2 → docput-1.1.0}/docs/_include/forgejo-monochrome.svg +0 -0
  36. {docput-1.0.2 → docput-1.1.0}/docs/_include/pypi-hover.svg +0 -0
  37. {docput-1.0.2 → docput-1.1.0}/docs/_include/pypi-monochrome.svg +0 -0
  38. {docput-1.0.2 → docput-1.1.0}/docs/_root/_headers +0 -0
  39. {docput-1.0.2 → docput-1.1.0}/docs/_root/_redirects +0 -0
  40. {docput-1.0.2 → docput-1.1.0}/docs/_static/css/custom.css +0 -0
  41. {docput-1.0.2 → docput-1.1.0}/docs/_templates/page.html +0 -0
  42. {docput-1.0.2 → docput-1.1.0}/docs/commands/index.md +0 -0
  43. {docput-1.0.2 → docput-1.1.0}/docs/commands/manifest.md +0 -0
  44. {docput-1.0.2 → docput-1.1.0}/docs/commands/version.md +0 -0
  45. {docput-1.0.2 → docput-1.1.0}/docs/conf.py +0 -0
  46. {docput-1.0.2 → docput-1.1.0}/docs/index.md +0 -0
  47. {docput-1.0.2 → docput-1.1.0}/docs/version-manifest.json +0 -0
  48. {docput-1.0.2 → docput-1.1.0}/docs/version-marker.json +0 -0
  49. {docput-1.0.2 → docput-1.1.0}/setup.cfg +0 -0
  50. {docput-1.0.2 → docput-1.1.0}/src/docput/__init__.py +0 -0
  51. {docput-1.0.2 → docput-1.1.0}/src/docput/__main__.py +0 -0
  52. {docput-1.0.2 → docput-1.1.0}/src/docput/cli/__init__.py +0 -0
  53. {docput-1.0.2 → docput-1.1.0}/src/docput/config.py +0 -0
  54. {docput-1.0.2 → docput-1.1.0}/src/docput/manifest.py +30 -30
  55. {docput-1.0.2 → docput-1.1.0}/src/docput/scripts/docput.js +0 -0
  56. {docput-1.0.2 → docput-1.1.0}/src/docput/sphinx_ext/__init__.py +0 -0
  57. {docput-1.0.2 → docput-1.1.0}/src/docput/sphinx_ext/_templates/sidebar/version-switch.html +0 -0
  58. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/dependency_links.txt +0 -0
  59. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/entry_points.txt +0 -0
  60. {docput-1.0.2 → docput-1.1.0}/src/docput.egg-info/top_level.txt +0 -0
@@ -10,14 +10,14 @@ jobs:
10
10
  runs-on: ubuntu-26.04
11
11
  strategy:
12
12
  matrix:
13
- python-version: [ "3.14", "3.15" ]
13
+ python-version: [ "3.12", "3.13", "3.14", "3.15" ]
14
14
  services:
15
15
  gitpages:
16
- image: codeberg.org/git-pages/git-pages:0.9.1
16
+ image: codeberg.org/git-pages/git-pages:0.10.1
17
17
  env:
18
18
  PAGES_INSECURE: 1
19
19
  env:
20
- DOCPUT_TEST_GIT_PAGES_URL: http://gitpages:3000
20
+ DOCPUT_TEST_GIT_PAGES_URL: http://gitpages:3000/test
21
21
 
22
22
  steps:
23
23
  - name: Checkout
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file
4
4
 
5
+ ## 1.1.0 - 2026-11-24
6
+
7
+ ### Changed
8
+
9
+ - Reduced minimum python version to 3.12
10
+ - Improved error handling (#5)
11
+
12
+ ### Added
13
+
14
+ - git-pages: Added support for incremental updates
15
+
16
+
5
17
  ## 1.0.2 - 2026-10-29
6
18
 
7
19
  ### Fixed
@@ -13,14 +25,14 @@ All notable changes to this project will be documented in this file
13
25
 
14
26
  ### Fixed
15
27
 
16
- - Fixed error with trailing slashes in paths when using the git-pages backend on Python 3.15 (#4)
28
+ - git-pages: Fixed error with trailing slashes in paths when using the git-pages backend on Python 3.15 (#4)
17
29
 
18
30
 
19
31
  ## 1.0.0 - 2026-08-23
20
32
 
21
33
  ### Changed
22
34
 
23
- - Reversed display order of versions in dropdown menu, so most recent versions are at the top
35
+ - Sphinx: Reversed display order of versions in dropdown menu, so most recent versions are at the top
24
36
 
25
37
 
26
38
  ## 0.2.1 - 2026-07-30
@@ -7,14 +7,14 @@ source_dirs := "src/ tests/"
7
7
  # Lint python source code
8
8
  lint:
9
9
  pyflakes {{ source_dirs }}
10
- black --quiet --check {{ source_dirs }}
10
+ black --check {{ source_dirs }}
11
11
  zuban check {{ source_dirs }}
12
12
 
13
13
  # Format python source code and other support files
14
14
  format: && docs::format
15
- black --quiet {{ source_dirs }}
15
+ black {{ source_dirs }}
16
16
  mdformat README.md
17
- {{ just_executable() }} --fmt --unstable
17
+ '{{ just_executable() }}' --fmt --unstable
18
18
 
19
19
  # Run tests
20
20
  test *args:
@@ -26,7 +26,7 @@ build:
26
26
 
27
27
  pre-commit := f"""
28
28
  #!/bin/sh
29
- PATH={{`dirname "$(which python)"`}}:$PATH just lint test"""
29
+ PATH={{ `dirname "$(which python)"` }}:$PATH just lint test"""
30
30
 
31
31
  # Install recommended git hooks. Do this after activating your virtual environment
32
32
  install-hooks:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docput
3
- Version: 1.0.2
3
+ Version: 1.1.0
4
4
  Summary: Deploy multi-versioned docs to static hosting
5
5
  Author-email: Andrew Cassidy <drewcassidy@me.com>
6
6
  License-Expression: MIT
@@ -21,12 +21,15 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
21
21
  Classifier: Topic :: Software Development :: Documentation
22
22
  Classifier: Framework :: Sphinx
23
23
  Classifier: Framework :: Sphinx :: Extension
24
- Requires-Python: >=3.14
24
+ Requires-Python: >=3.12
25
25
  Description-Content-Type: text/markdown
26
26
  License-File: LICENSE.md
27
27
  Requires-Dist: click>=8.4
28
28
  Requires-Dist: requests>=2.33
29
29
  Requires-Dist: urlpath>=2.0.0
30
+ Requires-Dist: rich>=14.3.3
31
+ Requires-Dist: humanize>=4.16.0
32
+ Requires-Dist: backports.zstd>=1.8.0; python_version < "3.14"
30
33
  Dynamic: license-file
31
34
 
32
35
  # docput
@@ -62,15 +65,15 @@ Install and update with [pip](https://pip.pypa.io/en/stable/getting-started/):
62
65
  $ pip install docput
63
66
  ```
64
67
 
65
- [documentation]: https://drewcassidy.me/docput/latest/
66
- [pypi]: https://pypi.org/project/docput
67
- [source]: https://git.offworld.city/drewcassidy/docput
68
-
69
68
  ## Licensing
70
69
 
71
70
  Docput is distributed under [the MIT license](LICENSE.md)
72
71
 
73
- Note that we *do not* waive the attribution requirements of our
72
+ Note that I *do not* waive the attribution requirements of my
74
73
  licenses, including for ingestion into machine learning models. If you
75
- train on and produce code derived from our work, you must uphold all
74
+ train on and produce code derived from my work, you must uphold all
76
75
  attribution requirements in produced works.
76
+
77
+ [documentation]: https://drewcassidy.me/docput/latest/
78
+ [pypi]: https://pypi.org/project/docput
79
+ [source]: https://git.offworld.city/drewcassidy/docput
@@ -31,15 +31,15 @@ Install and update with [pip](https://pip.pypa.io/en/stable/getting-started/):
31
31
  $ pip install docput
32
32
  ```
33
33
 
34
- [documentation]: https://drewcassidy.me/docput/latest/
35
- [pypi]: https://pypi.org/project/docput
36
- [source]: https://git.offworld.city/drewcassidy/docput
37
-
38
34
  ## Licensing
39
35
 
40
36
  Docput is distributed under [the MIT license](LICENSE.md)
41
37
 
42
- Note that we *do not* waive the attribution requirements of our
38
+ Note that I *do not* waive the attribution requirements of my
43
39
  licenses, including for ingestion into machine learning models. If you
44
- train on and produce code derived from our work, you must uphold all
45
- attribution requirements in produced works.
40
+ train on and produce code derived from my work, you must uphold all
41
+ attribution requirements in produced works.
42
+
43
+ [documentation]: https://drewcassidy.me/docput/latest/
44
+ [pypi]: https://pypi.org/project/docput
45
+ [source]: https://git.offworld.city/drewcassidy/docput
@@ -0,0 +1,2 @@
1
+ _build
2
+ _doctrees
@@ -4,19 +4,19 @@ set fallback
4
4
 
5
5
  # Format documentation source files
6
6
  format:
7
- black --quiet conf.py
7
+ black conf.py
8
8
  mdformat .
9
- {{ just_executable() }} --fmt --unstable
9
+ '{{ just_executable() }}' --fmt --unstable
10
10
 
11
11
  sphinx_module := "sphinx"
12
12
 
13
13
  # Build documentation.
14
14
  build *args:
15
- python -m {{ sphinx_module }} . _build {{ args }}
15
+ python -m {{ sphinx_module }} --doctree-dir=_doctrees {{ args }} . _build
16
16
 
17
17
  # Push documentation version
18
18
  push *args:
19
- docput version push {{ args }} _build
19
+ docput --log-level=DEBUG version push _build {{ args }}
20
20
 
21
21
  # Update root files for the documentation site
22
22
  update-root *args:
@@ -80,4 +80,5 @@ html_sidebars = {
80
80
  ]
81
81
  }
82
82
  ```
83
- [furo]: https://github.com/pradyunsg/furo
83
+
84
+ [furo]: https://github.com/pradyunsg/furo
@@ -107,6 +107,5 @@ with {option}`--alias <docput version push --alias>`.
107
107
  is a shortcut for
108
108
  `--alias latest`.
109
109
 
110
-
111
110
  [git-pages]: https://git-pages.org
112
111
  [git-pages auth]: https://codeberg.org/git-pages/git-pages#authorization
@@ -30,11 +30,14 @@ classifiers = [
30
30
  "Framework :: Sphinx :: Extension",
31
31
  ]
32
32
 
33
- requires-python = ">= 3.14"
33
+ requires-python = ">= 3.12"
34
34
  dependencies = [
35
35
  "click >= 8.4",
36
36
  "requests >= 2.33",
37
37
  "urlpath >= 2.0.0",
38
+ "rich >= 14.3.3",
39
+ "humanize >= 4.16.0",
40
+ "backports.zstd >= 1.8.0; python_version < '3.14'"
38
41
  ]
39
42
  dynamic = ["version"]
40
43
 
@@ -59,8 +62,7 @@ dev = [
59
62
  "zuban ~= 0.10.0",
60
63
  # test
61
64
  "pytest ~= 9.0",
62
- # build
63
- "build",
65
+ "faker ~= 40.52"
64
66
  ]
65
67
 
66
68
  [project.urls]
@@ -80,7 +82,7 @@ addopts = [
80
82
  testpaths = ['tests', 'docput']
81
83
 
82
84
  [tool.black]
83
- target-version = ["py314"]
85
+ target-version = ["py312"]
84
86
 
85
87
  [tool.zuban]
86
88
  mode = "default"
@@ -0,0 +1,169 @@
1
+ import logging
2
+ import shutil
3
+ import sys
4
+ from dataclasses import dataclass
5
+ from functools import update_wrapper
6
+ from io import Writer
7
+ from pathlib import Path
8
+ from typing import Callable, Concatenate
9
+
10
+ import click
11
+ from click import ClickException
12
+ from rich.console import Console
13
+ from rich.highlighter import NullHighlighter
14
+ from rich.logging import RichHandler
15
+
16
+ from docput.remote import open_remote
17
+ from docput.remote.exceptions import RemoteException
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ @dataclass
23
+ class State:
24
+ remote_url: str | None
25
+ log_level: str
26
+
27
+
28
+ def pass_remote_url[R, **P](f: Callable[Concatenate[str, P], R]) -> Callable[P, R]:
29
+ @click.pass_context
30
+ def new_func(ctx: click.Context, *args: P.args, **kwargs: P.kwargs) -> R:
31
+ remote_url = ctx.ensure_object(State).remote_url
32
+ if remote_url is None:
33
+ raise click.ClickException(
34
+ "No remote configured. Pass a remote URL with --remote"
35
+ )
36
+ try:
37
+ return f(remote_url, *args, **kwargs)
38
+ except RemoteException as re:
39
+ raise ClickException(str(re)) from re
40
+
41
+ return update_wrapper(new_func, f)
42
+
43
+
44
+ @click.group(context_settings={"show_default": True, "max_content_width": 120})
45
+ @click.version_option()
46
+ @click.option(
47
+ "--remote",
48
+ "-r",
49
+ "remote_url",
50
+ required=False,
51
+ type=str,
52
+ envvar="DOCPUT_REMOTE",
53
+ show_envvar=True,
54
+ help="Remote to interact with",
55
+ )
56
+ @click.option(
57
+ "--verbose",
58
+ "-v",
59
+ "log_level",
60
+ flag_value="INFO",
61
+ help="Show additional information. Shortcut for --log-level=INFO",
62
+ )
63
+ @click.option("--log-level", default="WARNING")
64
+ @click.pass_context
65
+ def main_group(ctx: click.Context, remote_url: str | None, log_level: str):
66
+ console = Console(stderr=True)
67
+ if log_level.casefold() == "debug":
68
+ handler = RichHandler(
69
+ console=console,
70
+ rich_tracebacks=True,
71
+ tracebacks_show_locals=True,
72
+ highlighter=NullHighlighter(),
73
+ )
74
+ else:
75
+ handler = RichHandler(
76
+ console=console,
77
+ rich_tracebacks=False,
78
+ tracebacks_show_locals=False,
79
+ show_time=False,
80
+ show_path=False,
81
+ highlighter=NullHighlighter(),
82
+ )
83
+ logging.basicConfig(
84
+ level=log_level.upper(),
85
+ style="{",
86
+ format="{name}: {message}",
87
+ handlers=[handler],
88
+ )
89
+ ctx.obj = State(remote_url, log_level)
90
+
91
+
92
+ @main_group.command(short_help="Download a file.")
93
+ @click.argument("source")
94
+ @click.argument("dest", type=click.File(mode="xb"))
95
+ @pass_remote_url
96
+ def download(remote_url: str, source: str, dest: Writer[bytes]):
97
+ """Download SOURCE from the remote and write it to DEST"""
98
+ with open_remote(remote_url) as remote:
99
+ try:
100
+ buff = remote.open(source, "rb")
101
+ except FileNotFoundError as fnfe:
102
+ raise ClickException(f"File '{source}' not found: {fnfe}")
103
+ shutil.copyfileobj(buff, dest)
104
+
105
+
106
+ @main_group.command(short_help="Upload a file or directory.") # type: ignore[attr-defined]
107
+ @pass_remote_url
108
+ @click.option(
109
+ "--overwrite/--merge",
110
+ "-o/-m",
111
+ default=False,
112
+ is_flag=True,
113
+ show_default=True,
114
+ help="Merge or overwrite uploaded directories.",
115
+ )
116
+ @click.argument("source", type=click.Path(exists=True, allow_dash=True, path_type=Path))
117
+ @click.argument("dest")
118
+ def upload(
119
+ remote_url: str,
120
+ overwrite: bool,
121
+ source: Path,
122
+ dest: str,
123
+ ):
124
+ """
125
+ Upload a file or directory SOURCE to the remote at DEST.
126
+
127
+ SOURCE is a path to a file or directory to upload. If SOURCE is `-`, its contents is read from standard input.
128
+
129
+ DEST is a path on the destination to write to.
130
+
131
+ If SOURCE is a file, its contents will be placed at DEST on the remote. Unlike tools like `cp` or `rsync`,
132
+ there is no special handling if DEST refers to a directory
133
+ """
134
+ with open_remote(remote_url) as remote:
135
+ if isinstance(source, Path) and str(source) == "-":
136
+ remote.write(sys.stdin.buffer.read(), dest)
137
+ else:
138
+ remote.write_tree(source, dest, overwrite)
139
+
140
+
141
+ @main_group.command(short_help="Delete a file or directory.")
142
+ @click.argument("path")
143
+ @pass_remote_url
144
+ def rm(remote_url: str, path: str):
145
+ """Delete the file or directory at PATH on the remote"""
146
+ with open_remote(remote_url) as remote:
147
+ remote.remove(path)
148
+ logger.info(f"Deleted {path}")
149
+
150
+
151
+ @main_group.command(short_help="Create a symlink.")
152
+ @click.argument("source")
153
+ @click.argument("target")
154
+ @pass_remote_url
155
+ def ln(remote_url: str, source: str, target: str):
156
+ """Create a symlink on the remote at TARGET pointing to SOURCE"""
157
+ with open_remote(remote_url) as remote:
158
+ remote.symlink(source, target)
159
+ logger.info(f"Symlinked {target} → {source}")
160
+
161
+
162
+ @main_group.command(short_help="Create a directory.")
163
+ @click.argument("path")
164
+ @pass_remote_url
165
+ def mkdir(remote_url: str, path: str):
166
+ """Create a directory on the remote at PATH. Any existing file or directory at PATH will be deleted"""
167
+ with open_remote(remote_url) as remote:
168
+ remote.mkdir(path)
169
+ logger.info(f"Made directory {path}")
@@ -7,10 +7,10 @@ import click
7
7
  from click import ClickException
8
8
  from urlpath import URL
9
9
 
10
- from .main import main_group, pass_remote
10
+ from .main import main_group, pass_remote_url
11
11
  from ..config import get_config
12
12
  from ..manifest import VersionManifest
13
- from ..remote import Remote
13
+ from ..remote import open_remote
14
14
 
15
15
 
16
16
  @main_group.group(help="Edit the version manifest.")
@@ -36,10 +36,10 @@ def manifest_group(): ...
36
36
  with "/", or a full URL like "https://example.com/docs/"). If it is not set, it is assumed to be "/".
37
37
  """,
38
38
  )
39
- @pass_remote
40
- def edit(remote: Remote, editor: str | None, url: URL | None):
39
+ @pass_remote_url
40
+ def edit(remote_url: str, editor: str | None, url: URL | None):
41
41
  """Edit the version manifest."""
42
- with remote:
42
+ with open_remote(remote_url) as remote:
43
43
  manifest = remote.read_manifest()
44
44
  if url is not None:
45
45
  manifest.base_url = url
@@ -6,10 +6,11 @@ import click
6
6
  from click import ClickException
7
7
  from urlpath import URL
8
8
 
9
- from .main import main_group, pass_remote
9
+ from docput.cli.manifest import pass_remote_url
10
+ from .main import main_group
10
11
  from ..config import get_config
11
12
  from ..manifest import VersionRecord
12
- from ..remote import Remote
13
+ from ..remote import open_remote
13
14
 
14
15
 
15
16
  @main_group.group(short_help="Create or edit versions.")
@@ -57,9 +58,9 @@ def version_group(): ...
57
58
  multiple=True,
58
59
  help="Shortcut for `--alias latest`",
59
60
  )
60
- @pass_remote
61
+ @pass_remote_url
61
62
  def push(
62
- remote: Remote,
63
+ remote_url: str,
63
64
  source: Path,
64
65
  name: str | None,
65
66
  visible: bool | None,
@@ -72,7 +73,7 @@ def push(
72
73
  URL must be a relative reference. If not provided, URL will be read from the environment variables DOCPUT_VERSION_URL, FORGEJO_REF_NAME, and
73
74
  GITHUB_REF_NAME, in that order.
74
75
  """
75
- with remote, remote.open_manifest() as manifest:
76
+ with open_remote(remote_url) as remote, remote.open_manifest() as manifest:
76
77
  config = get_config()
77
78
 
78
79
  if (version := manifest.versions.get(url)) is not None:
@@ -91,7 +92,7 @@ def push(
91
92
  assert not url.is_absolute(), f"URL {url} is not a relative reference"
92
93
 
93
94
  # write documentation files
94
- remote.copytree(source, url, overwrite=True)
95
+ remote.write_tree(source, url, overwrite=True)
95
96
 
96
97
  # write marker
97
98
  with remote.open(url / config.get("marker_url"), "w") as fb:
@@ -119,30 +120,35 @@ def push(
119
120
  default=False,
120
121
  help="Keep the corresponding documentation, just delete the manifest record.",
121
122
  )
122
- @pass_remote
123
- def delete(remote: Remote, urls: tuple[URL, ...], keep: bool):
123
+ @pass_remote_url
124
+ def delete(remote_url: str, urls: tuple[URL, ...], keep: bool):
124
125
  """Delete versions at URLs from the remote and remove them from the manifest."""
125
- with remote, remote.open_manifest() as manifest:
126
+ with open_remote(remote_url) as remote, remote.open_manifest() as manifest:
126
127
  for url in urls:
127
128
  for alias in list(manifest.aliases.keys()):
128
129
  if manifest.aliases[alias] == url:
129
130
  manifest.aliases.pop(alias)
130
131
  remote.remove(alias)
131
132
 
132
- if manifest.versions.pop(url) is None:
133
- print(f"Version {url} does not exist in the manifest")
133
+ try:
134
+ manifest.versions.pop(url)
135
+ except KeyError as ie:
136
+ raise ClickException(
137
+ f"Version '{url}' does not exist in the manifest"
138
+ ) from ie
134
139
 
135
140
  if not keep and not url.is_absolute:
136
141
  remote.remove(url)
137
142
 
138
143
 
139
144
  @version_group.command()
140
- @pass_remote
141
- def list_command(remote: Remote):
145
+ @pass_remote_url
146
+ def list_command(remote_url: str):
142
147
  """List all versions in the manifest."""
143
- for url, version in remote.read_manifest().versions.items():
144
- print(f"url: {url}")
145
- print(indent(str(version), " " * 2))
148
+ with open_remote(remote_url) as remote:
149
+ for url, version in remote.read_manifest().versions.items():
150
+ print(f"url: {url}")
151
+ print(indent(str(version), " " * 2))
146
152
 
147
153
 
148
154
  @version_group.command()
@@ -159,10 +165,10 @@ def list_command(remote: Remote):
159
165
  show_envvar=True,
160
166
  help="The name to display for this version in the version menu.",
161
167
  )
162
- @pass_remote
163
- def edit(remote: Remote, url: URL, visible: bool | None, name: str | None):
168
+ @pass_remote_url
169
+ def edit(remote_url: str, url: URL, visible: bool | None, name: str | None):
164
170
  """Edit version at URL in the manifest."""
165
- with remote, remote.open_manifest() as manifest:
171
+ with open_remote(remote_url) as remote, remote.open_manifest() as manifest:
166
172
  if (version := manifest.versions.get(url)) is None:
167
173
  raise ClickException(f"Version {url} does not exist in the manifest")
168
174
 
@@ -0,0 +1,90 @@
1
+ import importlib
2
+ import logging
3
+ from collections.abc import Callable
4
+ from contextlib import contextmanager
5
+ from typing import Concatenate, Generator
6
+
7
+ from urlpath import URL
8
+
9
+ from .base import Remote
10
+
11
+ __all__ = ["find_remote", "open_remote", "Remote"]
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ def find_remote(name) -> Callable[Concatenate[URL | str, ...], Remote]:
17
+ """
18
+ find a remote type with a given name. Searches for modules both globally and relative to docput.remote.
19
+ The module must have a ``RemoteType`` type (or alias) that extends :class:`<docput.remote.Remote> Remote`
20
+ :param name: name of the module that contains RemoteType. Hyphens will be replaced with underscores.
21
+ :return: A matching type that extends :class:`<docput.remote.Remote> Remote`
22
+ """
23
+
24
+ name = name.replace("-", "_")
25
+
26
+ for mod_name in ["." + name, name]:
27
+ try:
28
+ module = importlib.import_module(name=mod_name, package=__name__)
29
+ logger.debug(f"Module candidate found: {module}")
30
+ break
31
+ except ModuleNotFoundError:
32
+ logger.debug(f"Module candidate not found: {mod_name}")
33
+ pass
34
+ else:
35
+ raise ValueError(f"Unknown remote type {name}")
36
+
37
+ try:
38
+ return module.RemoteType
39
+ except AttributeError as ae:
40
+ raise ValueError(
41
+ f"Invalid remote type: Module {module.__name__} does not contain a `RemoteType` type."
42
+ ) from ae
43
+
44
+
45
+ @contextmanager
46
+ def open_remote(url: str | URL) -> Generator[Remote, None, None]:
47
+ """
48
+ Parse a URL, returning a context manager for a remote object. Deployment targets (other than `FilesystemTarget`)
49
+ are determined from the scheme, with a plus sign separating the target name from the scheme to pass to it. For
50
+ example the scheme `git-pages+https` would create a `GitPagesTarget` and pass it the https scheme.
51
+ """
52
+ url = URL(url)
53
+ scheme = url.scheme or "file"
54
+
55
+ logger.debug(f"Creating remote from URL {url}")
56
+ match (url.scheme or "file"):
57
+ case "file":
58
+ from .filesystem import FilesystemRemote
59
+
60
+ logger.debug("using filesystem remote")
61
+ remote = FilesystemRemote(url)
62
+ match scheme.split("+"):
63
+ case ["file"]:
64
+ from .filesystem import FilesystemRemote
65
+
66
+ logger.debug("using filesystem remote")
67
+ remote = FilesystemRemote(url)
68
+ case [name, scheme]:
69
+ kwargs: dict[str, str | bool] = {}
70
+ url = url.with_scheme(scheme)
71
+
72
+ for fragment in url.fragment.split("#"):
73
+ parts = fragment.split("=")
74
+ match parts:
75
+ case [str(key), str(value)]:
76
+ kwargs[key] = value
77
+ case [str(flag)] if flag:
78
+ kwargs[flag] = True
79
+ url = url.with_fragment("")
80
+
81
+ remote_type = find_remote(name)
82
+ logger.debug(
83
+ f"Using remote type {remote_type.__name__} with URL '{url}' and arguments {kwargs}"
84
+ )
85
+ remote = remote_type(url, **kwargs)
86
+ case _:
87
+ raise ValueError(f"Unable to parse target scheme '{scheme}'")
88
+
89
+ yield remote
90
+ remote.commit()