hop3-server 0.4.0__py3-none-any.whl

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 (239) hide show
  1. hop3/.DS_Store +0 -0
  2. hop3/__init__.py +1 -0
  3. hop3/alembic/README +1 -0
  4. hop3/alembic/env.py +99 -0
  5. hop3/alembic/script.py.mako +28 -0
  6. hop3/alembic/versions/0d21c362f66d_add_app_state_machine_and_error_message.py +66 -0
  7. hop3/alembic/versions/961bfd2ecce5_add_runtime_field_to_app_model.py +40 -0
  8. hop3/alembic/versions/d20dd80dafca_initial_schema.py +33 -0
  9. hop3/alembic.ini +147 -0
  10. hop3/commands/__init__.py +7 -0
  11. hop3/commands/_base.py +96 -0
  12. hop3/commands/_errors.py +206 -0
  13. hop3/commands/_helpers.py +136 -0
  14. hop3/commands/_response.py +107 -0
  15. hop3/commands/admin.py +635 -0
  16. hop3/commands/app.py +1055 -0
  17. hop3/commands/apps.py +103 -0
  18. hop3/commands/auth.py +310 -0
  19. hop3/commands/backup.py +431 -0
  20. hop3/commands/config.py +667 -0
  21. hop3/commands/git.py +229 -0
  22. hop3/commands/help.py +217 -0
  23. hop3/commands/misc.py +313 -0
  24. hop3/commands/services.py +726 -0
  25. hop3/commands/system.py +955 -0
  26. hop3/config.py +405 -0
  27. hop3/core/__init__.py +10 -0
  28. hop3/core/artifacts.py +156 -0
  29. hop3/core/backup.py +767 -0
  30. hop3/core/credentials.py +122 -0
  31. hop3/core/env.py +108 -0
  32. hop3/core/events.py +78 -0
  33. hop3/core/git.py +159 -0
  34. hop3/core/hooks.py +17 -0
  35. hop3/core/hookspecs.py +149 -0
  36. hop3/core/manifest.py +158 -0
  37. hop3/core/plugins.py +540 -0
  38. hop3/core/protocols.py +577 -0
  39. hop3/deployers/__init__.py +6 -0
  40. hop3/deployers/addon_provisioning.py +168 -0
  41. hop3/deployers/deployer.py +465 -0
  42. hop3/deployers/env_provisioning.py +97 -0
  43. hop3/deployers/git_based_deployer.py +204 -0
  44. hop3/di/__init__.py +36 -0
  45. hop3/di/container.py +120 -0
  46. hop3/di/providers.py +167 -0
  47. hop3/lib/__init__.py +14 -0
  48. hop3/lib/archives.py +188 -0
  49. hop3/lib/args.py +203 -0
  50. hop3/lib/backports.py +56 -0
  51. hop3/lib/config.py +161 -0
  52. hop3/lib/console.py +406 -0
  53. hop3/lib/datetime.py +16 -0
  54. hop3/lib/decision_log.py +244 -0
  55. hop3/lib/decorators.py +10 -0
  56. hop3/lib/freeze.py +40 -0
  57. hop3/lib/logging.py +199 -0
  58. hop3/lib/multi_tail.py +136 -0
  59. hop3/lib/path.py +37 -0
  60. hop3/lib/registry.py +87 -0
  61. hop3/lib/scanner.py +39 -0
  62. hop3/lib/settings.py +67 -0
  63. hop3/lib/sysinfo.py +266 -0
  64. hop3/lib/templating.py +29 -0
  65. hop3/lib/types.py +12 -0
  66. hop3/lib/util.py +461 -0
  67. hop3/orm/__init__.py +44 -0
  68. hop3/orm/addon_credential.py +86 -0
  69. hop3/orm/app.py +1015 -0
  70. hop3/orm/backup.py +54 -0
  71. hop3/orm/env.py +34 -0
  72. hop3/orm/repositories.py +418 -0
  73. hop3/orm/revoked_token.py +49 -0
  74. hop3/orm/security.py +115 -0
  75. hop3/orm/session.py +132 -0
  76. hop3/platform/__init__.py +1 -0
  77. hop3/platform/certificates.py +303 -0
  78. hop3/plugins/__init__.py +1 -0
  79. hop3/plugins/addons/__init__.py +21 -0
  80. hop3/plugins/addons/cli.py +36 -0
  81. hop3/plugins/addons/secrets.py +97 -0
  82. hop3/plugins/build/__init__.py +1 -0
  83. hop3/plugins/build/language_toolchains/__init__.py +15 -0
  84. hop3/plugins/build/language_toolchains/plugin.py +32 -0
  85. hop3/plugins/build/local_build/__init__.py +12 -0
  86. hop3/plugins/build/local_build/builder.py +258 -0
  87. hop3/plugins/build/local_build/plugin.py +25 -0
  88. hop3/plugins/deploy/__init__.py +1 -0
  89. hop3/plugins/deploy/static/__init__.py +6 -0
  90. hop3/plugins/deploy/static/deployer.py +195 -0
  91. hop3/plugins/deploy/static/plugin.py +25 -0
  92. hop3/plugins/deploy/uwsgi/__init__.py +1 -0
  93. hop3/plugins/deploy/uwsgi/deployer.py +222 -0
  94. hop3/plugins/deploy/uwsgi/plugin.py +25 -0
  95. hop3/plugins/docker/__init__.py +3 -0
  96. hop3/plugins/docker/builder.py +351 -0
  97. hop3/plugins/docker/deployer.py +881 -0
  98. hop3/plugins/docker/dockerfiles/Dockerfile-clojure +40 -0
  99. hop3/plugins/docker/dockerfiles/Dockerfile-go +35 -0
  100. hop3/plugins/docker/dockerfiles/Dockerfile-gradle +40 -0
  101. hop3/plugins/docker/dockerfiles/Dockerfile-maven +40 -0
  102. hop3/plugins/docker/dockerfiles/Dockerfile-node +43 -0
  103. hop3/plugins/docker/dockerfiles/Dockerfile-php +41 -0
  104. hop3/plugins/docker/dockerfiles/Dockerfile-python +58 -0
  105. hop3/plugins/docker/dockerfiles/Dockerfile-ruby +44 -0
  106. hop3/plugins/docker/dockerfiles/Dockerfile-rust +34 -0
  107. hop3/plugins/docker/dockerfiles/readme.md +7 -0
  108. hop3/plugins/docker/plugin.py +46 -0
  109. hop3/plugins/mysql/__init__.py +3 -0
  110. hop3/plugins/mysql/admin.py +197 -0
  111. hop3/plugins/mysql/cli.py +375 -0
  112. hop3/plugins/mysql/mysql.py +443 -0
  113. hop3/plugins/mysql/plugin.py +148 -0
  114. hop3/plugins/oses/README.md +336 -0
  115. hop3/plugins/oses/__init__.py +11 -0
  116. hop3/plugins/oses/arch.py +169 -0
  117. hop3/plugins/oses/base.py +168 -0
  118. hop3/plugins/oses/bsd.py +198 -0
  119. hop3/plugins/oses/debian_base.py +37 -0
  120. hop3/plugins/oses/debian_family.py +179 -0
  121. hop3/plugins/oses/macos.py +217 -0
  122. hop3/plugins/oses/redhat_base.py +42 -0
  123. hop3/plugins/oses/redhat_family.py +174 -0
  124. hop3/plugins/postgresql/__init__.py +1 -0
  125. hop3/plugins/postgresql/admin.py +196 -0
  126. hop3/plugins/postgresql/cli.py +435 -0
  127. hop3/plugins/postgresql/plugin.py +144 -0
  128. hop3/plugins/postgresql/postgres.py +582 -0
  129. hop3/plugins/proxy/__init__.py +1 -0
  130. hop3/plugins/proxy/caddy/__init__.py +9 -0
  131. hop3/plugins/proxy/caddy/_setup.py +321 -0
  132. hop3/plugins/proxy/caddy/_templates.py +92 -0
  133. hop3/plugins/proxy/caddy/plugin.py +26 -0
  134. hop3/plugins/proxy/nginx/__init__.py +10 -0
  135. hop3/plugins/proxy/nginx/_setup.py +421 -0
  136. hop3/plugins/proxy/nginx/_templates.py +158 -0
  137. hop3/plugins/proxy/nginx/plugin.py +26 -0
  138. hop3/plugins/proxy/traefik/__init__.py +9 -0
  139. hop3/plugins/proxy/traefik/_setup.py +328 -0
  140. hop3/plugins/proxy/traefik/_templates.py +137 -0
  141. hop3/plugins/proxy/traefik/plugin.py +26 -0
  142. hop3/plugins/redis/__init__.py +1 -0
  143. hop3/plugins/redis/cli.py +168 -0
  144. hop3/plugins/redis/factory.py +103 -0
  145. hop3/plugins/redis/plugin.py +133 -0
  146. hop3/plugins/redis/redis.py +398 -0
  147. hop3/project/__init__.py +3 -0
  148. hop3/project/config.py +275 -0
  149. hop3/project/hop3_config.py +515 -0
  150. hop3/project/procfile.py +132 -0
  151. hop3/project/schema.py +350 -0
  152. hop3/run/__init__.py +4 -0
  153. hop3/run/spawn.py +595 -0
  154. hop3/run/uwsgi/__init__.py +7 -0
  155. hop3/run/uwsgi/settings.py +70 -0
  156. hop3/run/uwsgi/worker.py +417 -0
  157. hop3/server/__init__.py +1 -0
  158. hop3/server/asgi.py +194 -0
  159. hop3/server/cli/__init__.py +7 -0
  160. hop3/server/cli/_base.py +25 -0
  161. hop3/server/cli/admin.py +458 -0
  162. hop3/server/cli/cli.py +202 -0
  163. hop3/server/cli/git.py +217 -0
  164. hop3/server/cli/help.py +161 -0
  165. hop3/server/cli/local.py +240 -0
  166. hop3/server/cli/plugins.py +388 -0
  167. hop3/server/cli/serve.py +45 -0
  168. hop3/server/cli/setup.py +297 -0
  169. hop3/server/controllers/__init__.py +37 -0
  170. hop3/server/controllers/auth.py +203 -0
  171. hop3/server/controllers/dashboard/__init__.py +32 -0
  172. hop3/server/controllers/dashboard/addons.py +87 -0
  173. hop3/server/controllers/dashboard/apps.py +330 -0
  174. hop3/server/controllers/dashboard/backups.py +147 -0
  175. hop3/server/controllers/dashboard/env_vars.py +58 -0
  176. hop3/server/controllers/dashboard/helpers.py +75 -0
  177. hop3/server/controllers/dashboard/index.py +45 -0
  178. hop3/server/controllers/dashboard/logs.py +163 -0
  179. hop3/server/controllers/marketplace.py +335 -0
  180. hop3/server/controllers/root.py +47 -0
  181. hop3/server/controllers/rpc.py +541 -0
  182. hop3/server/controllers/stream.py +83 -0
  183. hop3/server/guards.py +74 -0
  184. hop3/server/health.py +106 -0
  185. hop3/server/lib/__init__.py +1 -0
  186. hop3/server/lib/database.py +30 -0
  187. hop3/server/lib/scanner.py +37 -0
  188. hop3/server/lib/types.py +6 -0
  189. hop3/server/marketplace/__init__.py +18 -0
  190. hop3/server/marketplace/loader.py +109 -0
  191. hop3/server/marketplace/models.py +138 -0
  192. hop3/server/marketplace/service.py +165 -0
  193. hop3/server/marketplace/taxonomy.py +160 -0
  194. hop3/server/middleware/__init__.py +5 -0
  195. hop3/server/security/__init__.py +9 -0
  196. hop3/server/security/tokens.py +289 -0
  197. hop3/server/state_sync.py +222 -0
  198. hop3/server/static/favicon.png +0 -0
  199. hop3/server/static/readme.md +1 -0
  200. hop3/server/streaming.py +253 -0
  201. hop3/server/templates/auth/login.html +87 -0
  202. hop3/server/templates/auth/profile.html +86 -0
  203. hop3/server/templates/base.html +176 -0
  204. hop3/server/templates/dashboard/_app_status.html +88 -0
  205. hop3/server/templates/dashboard/addon_detail.html +247 -0
  206. hop3/server/templates/dashboard/addons.html +127 -0
  207. hop3/server/templates/dashboard/app_create.html +145 -0
  208. hop3/server/templates/dashboard/app_create_pending.html +62 -0
  209. hop3/server/templates/dashboard/app_detail.html +366 -0
  210. hop3/server/templates/dashboard/backup_info.html +278 -0
  211. hop3/server/templates/dashboard/backups.html +114 -0
  212. hop3/server/templates/dashboard/env_vars.html +288 -0
  213. hop3/server/templates/dashboard/index.html +181 -0
  214. hop3/server/templates/dashboard/logs.html +235 -0
  215. hop3/server/templates/dashboard/marketplace/_app_card.html +49 -0
  216. hop3/server/templates/dashboard/marketplace/category.html +102 -0
  217. hop3/server/templates/dashboard/marketplace/detail.html +245 -0
  218. hop3/server/templates/dashboard/marketplace/index.html +131 -0
  219. hop3/server/templates/dashboard/marketplace/list.html +161 -0
  220. hop3/server/templates/term-ws.j2 +155 -0
  221. hop3/server/templates/term.j2 +49 -0
  222. hop3/toolchains/__init__.py +40 -0
  223. hop3/toolchains/_base.py +342 -0
  224. hop3/toolchains/clojure.py +136 -0
  225. hop3/toolchains/dotnet.py +55 -0
  226. hop3/toolchains/elixir.py +69 -0
  227. hop3/toolchains/generic.py +82 -0
  228. hop3/toolchains/go.py +91 -0
  229. hop3/toolchains/java.py +75 -0
  230. hop3/toolchains/node.py +187 -0
  231. hop3/toolchains/php.py +141 -0
  232. hop3/toolchains/python.py +325 -0
  233. hop3/toolchains/ruby.py +132 -0
  234. hop3/toolchains/rust.py +97 -0
  235. hop3/toolchains/static.py +85 -0
  236. hop3_server-0.4.0.dist-info/METADATA +160 -0
  237. hop3_server-0.4.0.dist-info/RECORD +239 -0
  238. hop3_server-0.4.0.dist-info/WHEEL +4 -0
  239. hop3_server-0.4.0.dist-info/entry_points.txt +3 -0
hop3/.DS_Store ADDED
Binary file
hop3/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # Copyright (c) 2023-2025, Abilian SAS
hop3/alembic/README ADDED
@@ -0,0 +1 @@
1
+ Generic single-database configuration.
hop3/alembic/env.py ADDED
@@ -0,0 +1,99 @@
1
+ # Copyright (c) 2025, Abilian SAS
2
+ from __future__ import annotations
3
+
4
+ from logging.config import fileConfig
5
+
6
+ from alembic import context
7
+ from sqlalchemy import engine_from_config, pool
8
+
9
+ # Import Hop3's configuration and models
10
+ from hop3 import config as hop3_config
11
+ from hop3.orm.app import App
12
+
13
+ # this is the Alembic Config object, which provides
14
+ # access to the values within the .ini file in use.
15
+ config = context.config
16
+
17
+ # Get database URL from Hop3 config, falling back to alembic.ini
18
+ database_url = config.get_main_option("sqlalchemy.url")
19
+ if not database_url or database_url == "driver://user:pass@localhost/dbname":
20
+ # Use Hop3's default database path
21
+ database_url = f"sqlite:///{hop3_config.HOP3_ROOT}/hop3.db"
22
+
23
+ # Override the sqlalchemy.url in the config
24
+ config.set_main_option("sqlalchemy.url", database_url)
25
+
26
+ # Interpret the config file for Python logging.
27
+ # This line sets up loggers basically.
28
+ if config.config_file_name is not None:
29
+ fileConfig(config.config_file_name)
30
+
31
+ # add your model's MetaData object here
32
+ # for 'autogenerate' support
33
+ target_metadata = App.metadata
34
+
35
+ # other values from the config, defined by the needs of env.py,
36
+ # can be acquired:
37
+ # my_important_option = config.get_main_option("my_important_option")
38
+ # ... etc.
39
+
40
+
41
+ def run_migrations_offline() -> None:
42
+ """Run migrations in 'offline' mode.
43
+
44
+ This configures the context with just a URL
45
+ and not an Engine, though an Engine is acceptable
46
+ here as well. By skipping the Engine creation
47
+ we don't even need a DBAPI to be available.
48
+
49
+ Calls to context.execute() here emit the given string to the
50
+ script output.
51
+
52
+ """
53
+ url = config.get_main_option("sqlalchemy.url")
54
+ context.configure(
55
+ url=url,
56
+ target_metadata=target_metadata,
57
+ literal_binds=True,
58
+ dialect_opts={"paramstyle": "named"},
59
+ )
60
+
61
+ with context.begin_transaction():
62
+ context.run_migrations()
63
+
64
+
65
+ def run_migrations_online() -> None:
66
+ """Run migrations in 'online' mode.
67
+
68
+ In this scenario we need to create an Engine
69
+ and associate a connection with the context.
70
+
71
+ """
72
+ # Check if we're being called programmatically with a connection
73
+ connectable = config.attributes.get("connection", None)
74
+
75
+ if connectable is None:
76
+ # CLI mode: create engine from config
77
+ connectable = engine_from_config(
78
+ config.get_section(config.config_ini_section, {}),
79
+ prefix="sqlalchemy.",
80
+ poolclass=pool.NullPool,
81
+ )
82
+
83
+ with connectable.connect() as connection:
84
+ context.configure(connection=connection, target_metadata=target_metadata)
85
+
86
+ with context.begin_transaction():
87
+ context.run_migrations()
88
+ else:
89
+ # Programmatic mode: use provided connection
90
+ context.configure(connection=connectable, target_metadata=target_metadata)
91
+
92
+ with context.begin_transaction():
93
+ context.run_migrations()
94
+
95
+
96
+ if context.is_offline_mode():
97
+ run_migrations_offline()
98
+ else:
99
+ run_migrations_online()
@@ -0,0 +1,28 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ """Upgrade schema."""
23
+ ${upgrades if upgrades else "pass"}
24
+
25
+
26
+ def downgrade() -> None:
27
+ """Downgrade schema."""
28
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2025, Abilian SAS
2
+ """add_app_state_machine_and_error_message
3
+
4
+ Revision ID: 0d21c362f66d
5
+ Revises: d20dd80dafca
6
+ Create Date: 2025-11-24 15:20:32.212565
7
+
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING
13
+
14
+ import sqlalchemy as sa
15
+ from alembic import op
16
+
17
+ if TYPE_CHECKING:
18
+ from collections.abc import Sequence
19
+
20
+ # revision identifiers, used by Alembic.
21
+ revision: str = "0d21c362f66d"
22
+ down_revision: str | Sequence[str] | None = "d20dd80dafca"
23
+ branch_labels: str | Sequence[str] | None = None
24
+ depends_on: str | Sequence[str] | None = None
25
+
26
+
27
+ def upgrade() -> None:
28
+ """Upgrade schema to add error_message column and update state enum values.
29
+
30
+ Changes:
31
+ - Add error_message column to app table
32
+ - Update run_state enum values (remove PAUSED, add STARTING, STOPPING, FAILED)
33
+ - STOPPED=1, STARTING=2, RUNNING=3, STOPPING=4, FAILED=5
34
+ """
35
+ # Add error_message column
36
+ op.add_column(
37
+ "app",
38
+ sa.Column(
39
+ "error_message", sa.String(length=1024), server_default="", nullable=False
40
+ ),
41
+ )
42
+
43
+ # Note: SQLite doesn't support ALTER TYPE for enums
44
+ # The new state values will work because we're using integers (1-5)
45
+ # Old states: RUNNING=1, STOPPED=2, PAUSED=3
46
+ # New states: STOPPED=1, STARTING=2, RUNNING=3, STOPPING=4, FAILED=5
47
+ # We need to update existing state values:
48
+ # - RUNNING (1) stays as 1, but becomes STOPPED (will be handled by application logic)
49
+ # - STOPPED (2) stays as 2, which becomes STARTING (will fix below)
50
+ # - PAUSED (3) becomes RUNNING (3)
51
+
52
+ # Actually, let's keep it simple for this migration:
53
+ # Old RUNNING (1) -> New RUNNING (3) - needs update
54
+ # Old STOPPED (2) -> New STOPPED (1) - needs update
55
+ # Old PAUSED (3) -> New STOPPED (1) - needs update
56
+
57
+ # For safety, we'll transition all apps to STOPPED state (1)
58
+ op.execute("UPDATE app SET run_state = 1")
59
+
60
+
61
+ def downgrade() -> None:
62
+ """Downgrade schema."""
63
+ # Remove error_message column
64
+ op.drop_column("app", "error_message")
65
+
66
+ # Note: State values will need manual intervention if downgrading
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2025, Abilian SAS
2
+ """add runtime field to app model
3
+
4
+ Revision ID: 961bfd2ecce5
5
+ Revises: 0d21c362f66d
6
+ Create Date: 2025-11-24 22:19:14.012460
7
+
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING
13
+
14
+ import sqlalchemy as sa
15
+ from alembic import op
16
+
17
+ if TYPE_CHECKING:
18
+ from collections.abc import Sequence
19
+
20
+ # revision identifiers, used by Alembic.
21
+ revision: str = "961bfd2ecce5"
22
+ down_revision: str | Sequence[str] | None = "0d21c362f66d"
23
+ branch_labels: str | Sequence[str] | None = None
24
+ depends_on: str | Sequence[str] | None = None
25
+
26
+
27
+ def upgrade() -> None:
28
+ """Upgrade schema to add runtime field."""
29
+ # Add runtime column with default value 'uwsgi' for existing apps
30
+ op.add_column(
31
+ "app",
32
+ sa.Column(
33
+ "runtime", sa.String(length=64), server_default="uwsgi", nullable=False
34
+ ),
35
+ )
36
+
37
+
38
+ def downgrade() -> None:
39
+ """Downgrade schema to remove runtime field."""
40
+ op.drop_column("app", "runtime")
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2025, Abilian SAS
2
+ """Initial schema
3
+
4
+ Revision ID: d20dd80dafca
5
+ Revises:
6
+ Create Date: 2025-11-13 19:00:17.208093
7
+
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Sequence
16
+
17
+ # revision identifiers, used by Alembic.
18
+ revision: str = "d20dd80dafca"
19
+ down_revision: str | Sequence[str] | None = None
20
+ branch_labels: str | Sequence[str] | None = None
21
+ depends_on: str | Sequence[str] | None = None
22
+
23
+
24
+ def upgrade() -> None:
25
+ """Upgrade schema."""
26
+ # ### commands auto generated by Alembic - please adjust! ###
27
+ # ### end Alembic commands ###
28
+
29
+
30
+ def downgrade() -> None:
31
+ """Downgrade schema."""
32
+ # ### commands auto generated by Alembic - please adjust! ###
33
+ # ### end Alembic commands ###
hop3/alembic.ini ADDED
@@ -0,0 +1,147 @@
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts.
5
+ # this is typically a path given in POSIX (e.g. forward slashes)
6
+ # format, relative to the token %(here)s which refers to the location of this
7
+ # ini file
8
+ script_location = %(here)s/alembic
9
+
10
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
11
+ # Uncomment the line below if you want the files to be prepended with date and time
12
+ # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
13
+ # for all available tokens
14
+ # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
15
+
16
+ # sys.path path, will be prepended to sys.path if present.
17
+ # defaults to the current working directory. for multiple paths, the path separator
18
+ # is defined by "path_separator" below.
19
+ prepend_sys_path = .
20
+
21
+
22
+ # timezone to use when rendering the date within the migration file
23
+ # as well as the filename.
24
+ # If specified, requires the tzdata library which can be installed by adding
25
+ # `alembic[tz]` to the pip requirements.
26
+ # string value is passed to ZoneInfo()
27
+ # leave blank for localtime
28
+ # timezone =
29
+
30
+ # max length of characters to apply to the "slug" field
31
+ # truncate_slug_length = 40
32
+
33
+ # set to 'true' to run the environment during
34
+ # the 'revision' command, regardless of autogenerate
35
+ # revision_environment = false
36
+
37
+ # set to 'true' to allow .pyc and .pyo files without
38
+ # a source .py file to be detected as revisions in the
39
+ # versions/ directory
40
+ # sourceless = false
41
+
42
+ # version location specification; This defaults
43
+ # to <script_location>/versions. When using multiple version
44
+ # directories, initial revisions must be specified with --version-path.
45
+ # The path separator used here should be the separator specified by "path_separator"
46
+ # below.
47
+ # version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
48
+
49
+ # path_separator; This indicates what character is used to split lists of file
50
+ # paths, including version_locations and prepend_sys_path within configparser
51
+ # files such as alembic.ini.
52
+ # The default rendered in new alembic.ini files is "os", which uses os.pathsep
53
+ # to provide os-dependent path splitting.
54
+ #
55
+ # Note that in order to support legacy alembic.ini files, this default does NOT
56
+ # take place if path_separator is not present in alembic.ini. If this
57
+ # option is omitted entirely, fallback logic is as follows:
58
+ #
59
+ # 1. Parsing of the version_locations option falls back to using the legacy
60
+ # "version_path_separator" key, which if absent then falls back to the legacy
61
+ # behavior of splitting on spaces and/or commas.
62
+ # 2. Parsing of the prepend_sys_path option falls back to the legacy
63
+ # behavior of splitting on spaces, commas, or colons.
64
+ #
65
+ # Valid values for path_separator are:
66
+ #
67
+ # path_separator = :
68
+ # path_separator = ;
69
+ # path_separator = space
70
+ # path_separator = newline
71
+ #
72
+ # Use os.pathsep. Default configuration used for new projects.
73
+ path_separator = os
74
+
75
+ # set to 'true' to search source files recursively
76
+ # in each "version_locations" directory
77
+ # new in Alembic version 1.10
78
+ # recursive_version_locations = false
79
+
80
+ # the output encoding used when revision files
81
+ # are written from script.py.mako
82
+ # output_encoding = utf-8
83
+
84
+ # database URL. This is consumed by the user-maintained env.py script only.
85
+ # other means of configuring database URLs may be customized within the env.py
86
+ # file.
87
+ sqlalchemy.url = driver://user:pass@localhost/dbname
88
+
89
+
90
+ [post_write_hooks]
91
+ # post_write_hooks defines scripts or Python functions that are run
92
+ # on newly generated revision scripts. See the documentation for further
93
+ # detail and examples
94
+
95
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
96
+ # hooks = black
97
+ # black.type = console_scripts
98
+ # black.entrypoint = black
99
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
100
+
101
+ # lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
102
+ # hooks = ruff
103
+ # ruff.type = module
104
+ # ruff.module = ruff
105
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
106
+
107
+ # Alternatively, use the exec runner to execute a binary found on your PATH
108
+ # hooks = ruff
109
+ # ruff.type = exec
110
+ # ruff.executable = ruff
111
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
112
+
113
+ # Logging configuration. This is also consumed by the user-maintained
114
+ # env.py script only.
115
+ [loggers]
116
+ keys = root,sqlalchemy,alembic
117
+
118
+ [handlers]
119
+ keys = console
120
+
121
+ [formatters]
122
+ keys = generic
123
+
124
+ [logger_root]
125
+ level = WARNING
126
+ handlers = console
127
+ qualname =
128
+
129
+ [logger_sqlalchemy]
130
+ level = WARNING
131
+ handlers =
132
+ qualname = sqlalchemy.engine
133
+
134
+ [logger_alembic]
135
+ level = INFO
136
+ handlers =
137
+ qualname = alembic
138
+
139
+ [handler_console]
140
+ class = StreamHandler
141
+ args = (sys.stderr,)
142
+ level = NOTSET
143
+ formatter = generic
144
+
145
+ [formatter_generic]
146
+ format = %(levelname)-5.5s [%(name)s] %(message)s
147
+ datefmt = %H:%M:%S
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2023-2025, Abilian SAS
2
+ from __future__ import annotations
3
+
4
+ from ._base import Command
5
+ from ._errors import CommandError, command_context, handle_command_error
6
+
7
+ __all__ = ["Command", "CommandError", "command_context", "handle_command_error"]
hop3/commands/_base.py ADDED
@@ -0,0 +1,96 @@
1
+ # Copyright (c) 2023-2025, Abilian SAS
2
+
3
+ """
4
+ Command Docstring Convention
5
+ ============================
6
+
7
+ When writing CLI commands, follow this docstring convention:
8
+
9
+ - **First Line**: A brief one-line summary (shown in ``hop --help`` overview)
10
+ - **Blank Line**: Separate the summary from detailed help
11
+ - **Detailed Help**: Usage instructions, examples, and detailed description (shown when asking for specific command help)
12
+
13
+ Example:
14
+
15
+ .. code-block:: python
16
+
17
+ class MyCmd(Command):
18
+ '''Brief one-line summary of what this command does.
19
+
20
+ This is the detailed help that includes usage instructions,
21
+ examples, and more detailed explanations.
22
+
23
+ Usage: hop mycommand <arg1> <arg2>
24
+
25
+ Examples:
26
+ hop mycommand foo bar
27
+ hop mycommand --option value
28
+ '''
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ from typing import ClassVar
34
+
35
+ from hop3.lib.registry import lookup
36
+
37
+ from ._response import text
38
+
39
+
40
+ class Command:
41
+ name: ClassVar[str] = ""
42
+ # Command aliases (alternative names for this command)
43
+ # E.g., aliases = ["destroy"] allows "hop destroy" to invoke "hop app:destroy"
44
+ aliases: ClassVar[list[str]] = []
45
+ # Authentication metadata (default: requires auth, doesn't need username)
46
+ requires_auth: ClassVar[bool] = True
47
+ pass_username: ClassVar[bool] = False
48
+ # Destructive action metadata (default: not destructive)
49
+ # Set to True for commands that delete/destroy data (requires confirmation)
50
+ destructive: ClassVar[bool] = False
51
+ # Hidden commands are not shown in help output (for internal/technical commands)
52
+ hidden: ClassVar[bool] = False
53
+
54
+ def call(self, *args, **kwargs):
55
+ return self.get_help()
56
+
57
+ def get_help(self):
58
+ output = [
59
+ "USAGE",
60
+ f" $ hop {self.name} <subcommand>",
61
+ "",
62
+ "SUBCOMMANDS",
63
+ ]
64
+ commands = lookup(Command)
65
+ commands.sort(key=lambda cmd: cmd.name)
66
+ for cmd in commands:
67
+ cmd_name = cmd.name
68
+
69
+ if ":" not in cmd_name:
70
+ # Skip commands that are not subcommands
71
+ continue
72
+ primary_name = cmd_name.split(":")[0]
73
+ if primary_name != self.name:
74
+ continue
75
+
76
+ help_text = _get_first_line(cmd.__doc__)
77
+ output.append(f" {cmd_name:<28} {help_text}")
78
+
79
+ output.append("")
80
+ output.append(f"Use 'hop {self.name}:<subcommand> --help' for details.")
81
+
82
+ return [text("\n".join(output))]
83
+
84
+ def subcommands(self):
85
+ return []
86
+
87
+
88
+ def _get_first_line(docstring: str | None) -> str:
89
+ """Extract the first non-empty line from a docstring."""
90
+ if not docstring:
91
+ return ""
92
+ for line in docstring.strip().split("\n"):
93
+ stripped = line.strip()
94
+ if stripped:
95
+ return stripped
96
+ return ""