autopub 1.0.0a19__py3-none-any.whl → 1.0.0a21__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
autopub/__init__.py CHANGED
@@ -2,11 +2,12 @@ from __future__ import annotations
2
2
 
3
3
  import hashlib
4
4
  import json
5
- from collections.abc import Iterable
5
+ from functools import cached_property
6
6
  from pathlib import Path
7
- from typing import Mapping, TypeAlias
7
+ from typing import Iterable, Mapping, TypeAlias
8
8
 
9
9
  import frontmatter
10
+ import tomlkit
10
11
  from pydantic import ValidationError
11
12
 
12
13
  from autopub.exceptions import (
@@ -21,6 +22,7 @@ from autopub.exceptions import (
21
22
  ReleaseTypeInvalid,
22
23
  ReleaseTypeMissing,
23
24
  )
25
+ from autopub.plugin_loader import load_plugins
24
26
  from autopub.plugins import (
25
27
  AutopubPackageManagerPlugin,
26
28
  AutopubPlugin,
@@ -35,12 +37,27 @@ ConfigType = Mapping[str, ConfigValue]
35
37
 
36
38
 
37
39
  class Autopub:
38
- config: ConfigType = {}
39
40
  RELEASE_FILE_PATH = "RELEASE.md"
41
+ plugins: list[AutopubPlugin]
40
42
 
41
43
  def __init__(self, plugins: Iterable[type[AutopubPlugin]] = ()) -> None:
42
44
  self.plugins = [plugin_class() for plugin_class in plugins]
43
45
 
46
+ self.load_plugins()
47
+
48
+ @cached_property
49
+ def config(self) -> ConfigType:
50
+ pyproject_path = Path.cwd() / "pyproject.toml"
51
+
52
+ if not Path("pyproject.toml").exists():
53
+ return {}
54
+
55
+ content = pyproject_path.read_text()
56
+
57
+ data = tomlkit.parse(content)
58
+
59
+ return data.get("tool", {}).get("autopub", {}) # type: ignore
60
+
44
61
  @property
45
62
  def release_file(self) -> Path:
46
63
  return Path.cwd() / self.RELEASE_FILE_PATH
@@ -69,6 +86,17 @@ class Autopub:
69
86
 
70
87
  return ReleaseInfo.from_dict(release_info)
71
88
 
89
+ def load_plugins(self, default_plugins: list[str] | None = None) -> None:
90
+ default_plugins = default_plugins or []
91
+
92
+ additional_plugins: list[str] = self.config.get("plugins", []) # type: ignore
93
+
94
+ all_plugins = default_plugins + additional_plugins
95
+
96
+ plugins = load_plugins(all_plugins)
97
+
98
+ self.plugins += [plugin_class() for plugin_class in plugins]
99
+
72
100
  def check(self) -> None:
73
101
  release_file = Path(self.RELEASE_FILE_PATH)
74
102
 
autopub/cli/__init__.py CHANGED
@@ -9,7 +9,6 @@ from rich.panel import Panel
9
9
  from typing_extensions import Annotated
10
10
 
11
11
  from autopub import Autopub
12
- from autopub.cli.plugins import find_plugins
13
12
  from autopub.exceptions import AutopubException, InvalidConfiguration
14
13
 
15
14
  app = typer.Typer()
@@ -19,14 +18,15 @@ class State(TypedDict):
19
18
  plugins: list[str]
20
19
 
21
20
 
22
- state: State = {"plugins": []}
21
+ class AutoPubCLI(typer.Context):
22
+ obj: Autopub
23
23
 
24
24
 
25
25
  @app.command()
26
- def check():
26
+ def check(context: AutoPubCLI):
27
27
  """This commands checks if the current PR has a valid release file."""
28
28
 
29
- autopub = Autopub(plugins=find_plugins(state["plugins"]))
29
+ autopub = context.obj
30
30
 
31
31
  try:
32
32
  autopub.validate_config()
@@ -38,7 +38,8 @@ def check():
38
38
  for id_ in e.validation_errors:
39
39
  error = e.validation_errors[id_]
40
40
  parts.append("")
41
- parts.append(f"[bold]Plugin:[/] {id_}")
41
+ parts.append(f"[bold on bright_magenta] Plugin: [/] {id_}")
42
+ parts.append("")
42
43
 
43
44
  errors: list[RenderableType] = []
44
45
 
@@ -46,7 +47,8 @@ def check():
46
47
  location = " -> ".join(map(str, error["loc"]))
47
48
  message = error["msg"]
48
49
 
49
- errors.append(f"[bold blue]{location}[/]: {message}")
50
+ errors.append(f"[bold on blue] {location} [/]: {message}")
51
+ errors.append("")
50
52
 
51
53
  parts.append(Padding(Group(*errors), (0, 2)))
52
54
 
@@ -82,8 +84,8 @@ def check():
82
84
 
83
85
 
84
86
  @app.command()
85
- def build():
86
- autopub = Autopub(plugins=find_plugins(state["plugins"]))
87
+ def build(context: AutoPubCLI):
88
+ autopub = context.obj
87
89
 
88
90
  try:
89
91
  autopub.build()
@@ -96,8 +98,8 @@ def build():
96
98
 
97
99
 
98
100
  @app.command()
99
- def prepare():
100
- autopub = Autopub(plugins=find_plugins(state["plugins"]))
101
+ def prepare(context: AutoPubCLI):
102
+ autopub = context.obj
101
103
 
102
104
  try:
103
105
  autopub.prepare()
@@ -111,12 +113,13 @@ def prepare():
111
113
 
112
114
  @app.command()
113
115
  def publish(
116
+ context: AutoPubCLI,
114
117
  repository: Annotated[
115
118
  Optional[str],
116
119
  typer.Option("--repository", "-r", help="Repository to publish to"),
117
120
  ] = None,
118
121
  ):
119
- autopub = Autopub(plugins=find_plugins(state["plugins"]))
122
+ autopub = context.obj
120
123
 
121
124
  try:
122
125
  autopub.publish(repository=repository)
@@ -130,28 +133,20 @@ def publish(
130
133
 
131
134
  @app.callback(invoke_without_command=True)
132
135
  def main(
133
- plugins: list[str] = typer.Option(
134
- [],
135
- "--plugin",
136
- "-p",
137
- help="List of plugins to use",
138
- ),
136
+ context: AutoPubCLI,
139
137
  should_show_version: Annotated[
140
138
  Optional[bool], typer.Option("--version", is_eager=True)
141
139
  ] = None,
142
140
  ):
143
- state["plugins"] = plugins
144
- state["plugins"].extend(
145
- [
146
- "git",
147
- "update_changelog",
148
- "bump_version",
149
- ]
150
- )
151
-
152
141
  if should_show_version:
153
142
  from importlib.metadata import version
154
143
 
155
144
  print(version("autopub"))
156
145
 
157
146
  raise typer.Exit()
147
+
148
+ autopub = Autopub()
149
+ # default plugins we always want to load (?)
150
+ autopub.load_plugins(["git", "update_changelog", "bump_version"])
151
+
152
+ context.obj = autopub
@@ -60,7 +60,7 @@ def _find_plugin(plugin: str) -> type[AutopubPlugin] | None:
60
60
  return None
61
61
 
62
62
 
63
- def find_plugins(names: list[str]) -> list[type[AutopubPlugin]]:
63
+ def load_plugins(names: list[str]) -> list[type[AutopubPlugin]]:
64
64
  sys.path.append(os.getcwd())
65
65
 
66
66
  plugins: list[type] = []
autopub/plugins/uv.py ADDED
@@ -0,0 +1,34 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from autopub.plugins import AutopubPackageManagerPlugin, AutopubPlugin
6
+
7
+
8
+ class UvPlugin(AutopubPlugin, AutopubPackageManagerPlugin):
9
+ def build(self) -> None:
10
+ self.run_command(["uv", "build"])
11
+
12
+ def publish(self, repository: str | None = None, **kwargs: Any) -> None:
13
+ additional_args: list[str] = []
14
+
15
+ if repository:
16
+ raise ValueError("Not yet implemented")
17
+
18
+ if publish_url := kwargs.get("publish_url"):
19
+ additional_args.append("--publish-url")
20
+ additional_args.append(publish_url)
21
+
22
+ if username := kwargs.get("username"):
23
+ additional_args.append("--username")
24
+ additional_args.append(username)
25
+
26
+ if password := kwargs.get("password"):
27
+ additional_args.append("--password")
28
+ additional_args.append(password)
29
+
30
+ if token := kwargs.get("token"):
31
+ additional_args.append("--token")
32
+ additional_args.append(token)
33
+
34
+ self.run_command(["uv", "publish", *additional_args])
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.1
2
+ Name: autopub
3
+ Version: 1.0.0a21
4
+ Summary: Automatic package release upon pull request merge
5
+ Home-page: https://github.com/autopub/autopub
6
+ Author: Justin Mayer
7
+ Author-email: entroP@gmail.com
8
+ Requires-Python: >=3.9.0,<4.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Provides-Extra: github
16
+ Requires-Dist: dunamai (>=1.23.0,<2.0.0)
17
+ Requires-Dist: pydantic (>=2.10.5,<3.0.0)
18
+ Requires-Dist: python-frontmatter (>=1.1.0,<2.0.0)
19
+ Requires-Dist: tomlkit (>=0.13.2,<0.14.0)
20
+ Project-URL: Issue Tracker, https://github.com/autopub/autopub/issues
21
+ Project-URL: Repository, https://github.com/autopub/autopub
@@ -1,17 +1,18 @@
1
- autopub/__init__.py,sha256=6yGwsfgoPJlAPQxRLdLU9h1jNwW98_ozKCEiGR8WRUA,6219
2
- autopub/cli/__init__.py,sha256=TULWztc0PpEjVh8HWGxWptO_9R_9729f5YvFwLwTSpI,3961
3
- autopub/cli/plugins.py,sha256=mEAsY2_OSsc-56ZH_x6pcP4mrTKBbyhze3uVPY39Ntk,1813
1
+ autopub/__init__.py,sha256=7u8F9STpmbbuMyfFx7piaICsAAQ4hd9z4Qjqq78wkfE,7057
2
+ autopub/cli/__init__.py,sha256=GZ1YNC0UDZqdMfQyNMD4D_D2ItTLcaiJLhPtsLwpH4s,3860
4
3
  autopub/exceptions.py,sha256=gNUbiG3_fVmNjhk2kyueQHPSifNgQf0Bl6IDNvkVhxQ,1534
4
+ autopub/plugin_loader.py,sha256=i8nz0cmu5eaSRJ2Hx5KxbA-tOMR2mjcz8fdRg4zkGLE,1813
5
5
  autopub/plugins/__init__.py,sha256=57ewn1lhZYKKuVL49l3cgqAN9LQfCRzdsgSZimIAkls,2030
6
6
  autopub/plugins/bump_version.py,sha256=Z6UKEJKdZVn6kACN4nQTJ3253kwAnSm1HpOxq1zHWpw,1413
7
7
  autopub/plugins/git.py,sha256=GeXcvlDEDOVb0cerebkfz8YruK7JYK6IyV872hBIqis,856
8
8
  autopub/plugins/pdm.py,sha256=Pczye06fKg8_HMJDkEfMXQyvao9rZ7sqzTHFd6lLEpU,532
9
9
  autopub/plugins/poetry.py,sha256=d2LvW9RI7ZB3reBOXbcp1mqWmzQ06Uyg_T-MxTvlSBg,517
10
10
  autopub/plugins/update_changelog.py,sha256=g_6flOP5wocZbjOaYSayWxobL3ld8f0wT78nFtAIkFc,1586
11
+ autopub/plugins/uv.py,sha256=goo8QxaD3FVJ1c3xOSmN1hikZTCUXN8jWNac1S5uDDY,1089
11
12
  autopub/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
13
  autopub/types.py,sha256=gY1WR93XZVFS7vf5JMSmL_h5z7zO51-rtmZ6MYsh3so,1043
13
- autopub-1.0.0a19.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
14
- autopub-1.0.0a19.dist-info/METADATA,sha256=vTL2SsABGIEg94ncUDcwDRzHQPU_pkcn-3e12ry633k,3788
15
- autopub-1.0.0a19.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
16
- autopub-1.0.0a19.dist-info/entry_points.txt,sha256=oeTav5NgCxif6mcZ_HeVGgGv5LzS4DwdI01nr4bO1IM,43
17
- autopub-1.0.0a19.dist-info/RECORD,,
14
+ autopub-1.0.0a21.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
15
+ autopub-1.0.0a21.dist-info/METADATA,sha256=1o1828nJpXm7QGldNkEd8a3HyKWKxClzHmjhhFy5YZw,872
16
+ autopub-1.0.0a21.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
+ autopub-1.0.0a21.dist-info/entry_points.txt,sha256=oeTav5NgCxif6mcZ_HeVGgGv5LzS4DwdI01nr4bO1IM,43
18
+ autopub-1.0.0a21.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.7.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,94 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: autopub
3
- Version: 1.0.0a19
4
- Summary: Automatic package release upon pull request merge
5
- Home-page: https://github.com/autopub/autopub
6
- License: AGPL-3.0
7
- Keywords: automatic,packaging,publish,release,version
8
- Author: Justin Mayer
9
- Author-email: entroP@gmail.com
10
- Requires-Python: >=3.8,<4.0
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Environment :: Console
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.8
18
- Classifier: Programming Language :: Python :: 3.9
19
- Classifier: Programming Language :: Python :: 3.10
20
- Classifier: Programming Language :: Python :: 3.11
21
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Classifier: Topic :: System :: Software Distribution
23
- Classifier: Topic :: System :: Systems Administration
24
- Provides-Extra: github
25
- Requires-Dist: build (>=0.10.0,<0.11.0)
26
- Requires-Dist: dunamai (>=1.17.0,<2.0.0)
27
- Requires-Dist: githubrelease (>=1.5.9,<2.0.0) ; extra == "github"
28
- Requires-Dist: httpx (==0.16.1) ; extra == "github"
29
- Requires-Dist: pydantic (>=2)
30
- Requires-Dist: python-frontmatter (>=1.0.0,<2.0.0)
31
- Requires-Dist: rich (>=12.5.1,<13.0.0)
32
- Requires-Dist: time-machine (>=2.13.0,<3.0.0)
33
- Requires-Dist: tomlkit (>=0.5,<2.0)
34
- Requires-Dist: twine (>=4.0.2,<5.0.0)
35
- Requires-Dist: typer (>=0.9.0,<0.10.0)
36
- Project-URL: Issue Tracker, https://github.com/autopub/autopub/issues
37
- Project-URL: Repository, https://github.com/autopub/autopub
38
- Description-Content-Type: text/markdown
39
-
40
- # AutoPub
41
-
42
- [![Build Status](https://img.shields.io/circleci/build/github/autopub/autopub)](https://circleci.com/gh/autopub/autopub) [![PyPI Version](https://img.shields.io/pypi/v/autopub)](https://pypi.org/project/autopub/)
43
-
44
- AutoPub enables project maintainers to release new package versions to PyPI by merging pull requests.
45
-
46
- ## Environment
47
-
48
- AutoPub is intended for use with continuous integration (CI) systems such as [GitHub Actions][], [CircleCI][], or [Travis CI][]. Projects used with AutoPub are built via [build][] and published via [Twine][]. Contributions that add support for other CI and build systems are welcome.
49
-
50
- ## Configuration
51
-
52
- AutoPub settings can be configured via the `[tool.autopub]` table in the target project’s `pyproject.toml` file. Required settings include Git username and email address:
53
-
54
- ```toml
55
- [tool.autopub]
56
- git-username = "Your Name"
57
- git-email = "your_email@example.com"
58
- ```
59
-
60
- ## Release Files
61
-
62
- Contributors should include a `RELEASE.md` file in their pull requests with two bits of information:
63
-
64
- * Release type: major, minor, or patch
65
- * Description of the changes, to be used as the changelog entry
66
-
67
- Example:
68
-
69
- Release type: patch
70
-
71
- Add function to update version strings in multiple files.
72
-
73
- ## Usage
74
-
75
- The following `autopub` sub-commands can be used as steps in your CI flows:
76
-
77
- * `autopub check`: Check whether release file exists.
78
- * `autopub prepare`: Update version strings and add entry to changelog.
79
- * `autopub build`: Build the project.
80
- * `autopub commit`: Add, commit, and push incremented version and changelog changes.
81
- * `autopub githubrelease`: Create a new release on GitHub.
82
- * `autopub publish`: Publish a new release.
83
-
84
- For systems such as Travis CI in which only one deployment step is permitted, there is a single command that runs the above steps in sequence:
85
-
86
- * `autopub deploy`: Run `prepare`, `build`, `commit`, `githubrelease`, and `publish` in one invocation.
87
-
88
-
89
- [GitHub Actions]: https://github.com/features/actions
90
- [CircleCI]: https://circleci.com
91
- [Travis CI]: https://travis-ci.org
92
- [build]: https://pypa-build.readthedocs.io
93
- [Twine]: https://twine.readthedocs.io/
94
-