Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ixmp4 platforms add from anywhere on the system #147

Open
glatterf42 opened this issue Jan 9, 2025 · 0 comments
Open

Enable ixmp4 platforms add from anywhere on the system #147

glatterf42 opened this issue Jan 9, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@glatterf42
Copy link
Member

@danielhuppmann and I discovered today that the ixmp4 platforms add command requires that it be run in the root directory of the ixmp4 repo. Running it from even just one level above that (i.e. the folder containing the ixmp4 repo) or below (e.g. ixmp4/ixmp4) causes alembic to not find the proper config file.

summary>Alembic error
╭──────────────────────────── Traceback (most recent call last) ─────────────────────────────╮
│ /home/fridolin/ixmp4/ixmp4/cli/platforms.py:93 in add                                      │
│                                                                                            │
│    90 │   │   utils.echo(                                                                  │
│    91 │   │   │   "No DSN supplied, assuming you want to add a local sqlite database..."   │
│    92 │   │   )                                                                            │
│ ❱  93 │   │   dsn = prompt_sqlite_dsn(name)                                                │
│    94 │                                                                                    │
│    95 │   settings.toml.add_platform(name, dsn)                                            │
│    96 │   utils.good("\nPlatform added successfully.")                                     │
│                                                                                            │
│ ╭──────────── locals ────────────╮                                                         │
│ │  dsn = None                    │                                                         │
│ │ name = 'to-confirm-this-works' │                                                         │
│ ╰────────────────────────────────╯                                                         │
│                                                                                            │
│ /home/fridolin/ixmp4/ixmp4/cli/platforms.py:61 in prompt_sqlite_dsn                        │
│                                                                                            │
│    58 │   │   │   f"No file at the standard filesystem location for name '{name}' exists." │
│    59 │   │   │   "Do you want to create a new database?"                                  │
│    60 │   │   ):                                                                           │
│ ❱  61 │   │   │   alembic.upgrade_database(dsn, "head")                                    │
│    62 │   │   │   return dsn                                                               │
│    63 │   │   else:                                                                        │
│    64 │   │   │   raise typer.Exit()                                                       │
│                                                                                            │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮ │
│ │  dsn = 'sqlite:////home/fridolin/.local/share/ixmp4/databases/to-confirm-this-works.s' │ │
│ │ name = 'to-confirm-this-works'                                                         │ │
│ │ path = PosixPath('/home/fridolin/.local/share/ixmp4/databases/to-confirm-this-works.s' │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                            │
│ /home/fridolin/ixmp4/ixmp4/db/utils/alembic.py:35 in upgrade_database                      │
│                                                                                            │
│   32 │   of the default `head` (newest) revision.""""                                      │
│   33 │                                                                                     │
│   34 │   alembic_config.set_main_option("sqlalchemy.url", dsn)                             │
│ ❱ 35 │   command.upgrade(alembic_config, revision)                                         │
│   36                                                                                       │
│   37                                                                                       │
│   38 def stamp_database(dsn: str, revision: str) -> None:                                  │
│                                                                                            │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮ │
│ │      dsn = 'sqlite:////home/fridolin/.local/share/ixmp4/databases/to-confirm-this-wor' │ │
│ │ revision = 'head'                                                                      │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                            │
│ /home/fridolin/ixmp4/.venv/lib/python3.12/site-packages/alembic/command.py:386 in upgrade  │
│                                                                                            │
│   383 │                                                                                    │
│   384 │   """"                                                                             │
│   385 │                                                                                    │
│ ❱ 386 │   script = ScriptDirectory.from_config(config)                                     │
│   387 │                                                                                    │
│   388 │   starting_rev = None                                                              │
│   389 │   if ":" in revision:                                                              │
│                                                                                            │
│ ╭────────────────────────── locals ───────────────────────────╮                            │
│ │   config = <alembic.config.Config object at 0x781593a6c2f0> │                            │
│ │ revision = 'head'                                           │                            │
│ │      sql = False                                            │                            │
│ │      tag = None                                             │                            │
│ ╰─────────────────────────────────────────────────────────────╯                            │
│                                                                                            │
│ /home/fridolin/ixmp4/.venv/lib/python3.12/site-packages/alembic/script/base.py:170 in      │
│ from_config                                                                                │
│                                                                                            │
│    167 │   │   """"                                                                        │
│    168 │   │   script_location = config.get_main_option("script_location")                 │
│    169 │   │   if script_location is None:                                                 │
│ ❱  170 │   │   │   raise util.CommandError(                                                │
│    171 │   │   │   │   "No 'script_location' key " "found in configuration."               │
│    172 │   │   │   )                                                                       │
│    173 │   │   truncate_slug_length: Optional[int]                                         │
│                                                                                            │
│ ╭────────────────────────────── locals ──────────────────────────────╮                     │
│ │             cls = <class 'alembic.script.base.ScriptDirectory'>    │                     │
│ │          config = <alembic.config.Config object at 0x781593a6c2f0> │                     │
│ │ script_location = None                                             │                     │
│ ╰────────────────────────────────────────────────────────────────────╯                     │
╰────────────────────────────────────────────────────────────────────────────────────────────╯
CommandError: No 'script_location' key found in configuration.

It would be nice to pass the location of the alembic config to ixmp4 platforms add such that it works from anywhere on the system.

@glatterf42 glatterf42 added the enhancement New feature or request label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant