Skip to content

Commit

Permalink
feat: add ruby backend (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewthauer authored and jdx committed Nov 26, 2024
1 parent f7d5fdd commit c46ccc3
Show file tree
Hide file tree
Showing 56 changed files with 468 additions and 207 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,5 @@ jobs:
retry_wait_seconds: 30
max_attempts: 2
command: mise test-tool --all
env:
MISE_USE_VERSIONS_HOST: 0
# env:
# MISE_USE_VERSIONS_HOST: 0
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CHANGELOG.md
.venv
registry/
aqua-registry/
docs/cli
docs/environments.md
docs/registry.md
Expand Down
2 changes: 2 additions & 0 deletions .python-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3.12
3.13
2 changes: 1 addition & 1 deletion docs/cache-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ to be updating, this is a good place to start.
## Plugin/Runtime Cache

Each plugin has a cache that's stored in `~/$MISE_CACHE_DIR/<PLUGIN>`. It stores
the list of versions available for that plugin (`mise ls-remote <PLUGIN>`), the legacy filenames (see below),
the list of versions available for that plugin (`mise ls-remote <PLUGIN>`), the idiomatic filenames (see below),
the list of aliases, the bin directories within each runtime installation, and the result of
running `exec-env` after the runtime was installed.

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/direnv.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Output direnv function to use mise inside direnv

See <https://mise.jdx.dev/direnv.html> for more information

Because this generates the legacy files based on currently installed plugins,
Because this generates the idiomatic files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change.
direnv may not know to update environment variables when idiomatic file versions change.

## Subcommands

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/direnv/activate.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Output direnv function to use mise inside direnv

See <https://mise.jdx.dev/direnv.html> for more information

Because this generates the legacy files based on currently installed plugins,
Because this generates the idiomatic files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change.
direnv may not know to update environment variables when idiomatic file versions change.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/settings/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Use the local config file instead of the global one

Examples:

$ mise settings get legacy_version_file
$ mise settings get idiomatic_version_file
true
2 changes: 1 addition & 1 deletion docs/cli/settings/ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Only display key names for each setting
Examples:

$ mise settings ls
legacy_version_file = false
idiomatic_version_file = false
...

$ mise settings ls python
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/settings/set.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Use the local config file instead of the global one

Examples:

mise settings legacy_version_file=true
mise settings idiomatic_version_file=true
2 changes: 1 addition & 1 deletion docs/cli/settings/unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Use the local config file instead of the global one

Examples:

mise settings unset legacy_version_file
mise settings unset idiomatic_version_file
22 changes: 11 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ python = ['3.10', '3.11']
[settings]
# plugins can read the versions files used by other version managers (if enabled by the plugin)
# for example, .nvmrc in the case of node's nvm
legacy_version_file = true # enabled by default (unlike asdf)
legacy_version_file_disable_tools = ['python'] # disable for specific tools
idiomatic_version_file = true # enabled by default (unlike asdf)
idiomatic_version_file_disable_tools = ['python'] # disable for specific tools

# configure `mise install` to always keep the downloaded archive
always_keep_download = false # deleted after install by default
Expand Down Expand Up @@ -240,38 +240,38 @@ Both `.mise.toml` and `.tool-versions` support "scopes" which modify the behavio
be used to express something like "2 versions behind lts" such as `sub-2:lts`. Or 1 minor
version behind the latest version: `sub-0.1:latest`.

## Legacy version files
## Idiomatic version files

mise supports "legacy version files" just like asdf. They're language-specific files
mise supports "idiomatic version files" just like asdf. They're language-specific files
like `.node-version`
and `.python-version`. These are ideal for setting the runtime version of a project without forcing
other developers to use a specific tool like mise/asdf.

They support aliases, which means you can have an `.nvmrc` file with `lts/hydrogen` and it will work
in mise and nvm. Here are some of the supported legacy version files:
in mise and nvm. Here are some of the supported idiomatic version files:

| Plugin | "Legacy" (Idiomatic) Files |
| Plugin | Idiomatic Files |
| --------- | -------------------------------------------------- |
| crystal | `.crystal-version` |
| elixir | `.exenv-version` |
| go | `.go-version`, `go.mod` |
| java | `.java-version`, `.sdkmanrc` |
| node | `.nvmrc`, `.node-version` |
| python | `.python-version` |
| python | `.python-version`, `.python-versions` |
| ruby | `.ruby-version`, `Gemfile` |
| terraform | `.terraform-version`, `.packer-version`, `main.tf` |
| yarn | `.yarnrc` |

In mise these are enabled by default. You can disable them
with `mise settings legacy_version_file=false`.
with `mise settings idiomatic_version_file=false`.
There is a performance cost to having these when they're parsed as it's performed by the plugin in
`bin/parse-version-file`. However these are [cached](/cache-behavior) so it's not a huge deal.
`bin/parse-version-file`. However, these are [cached](/cache-behavior) so it's not a huge deal.
You may not even notice.

::: info
asdf calls these "legacy version files" so we do too. I think this is a bad name since it implies
asdf called these "legacy version files". I think this was a bad name since it implies
that they shouldn't be used—which is definitely not the case IMO. I prefer the term "idiomatic"
version files since they're version files not specific to asdf/mise and can be used by other tools.
version files since they are version files not specific to asdf/mise and can be used by other tools.
(`.nvmrc` being a notable exception, which is tied to a specific tool.)
:::

Expand Down
52 changes: 52 additions & 0 deletions docs/dev-tools/backends/gem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# gem Backend

mise can be used to install CLIs from RubyGems. The code for this is inside of the mise repository at [`./src/backend/gem.rs`](https://github.com/jdx/mise/blob/main/src/backend/pipx.rs).

## Dependencies

This relies on having `gem` (provided with ruby) installed. You can install it with or without mise.
Here is how to install `ruby` with mise:

```sh
mise use -g ruby
```

## Usage

The following installs the latest version of [rubocop](https://rubygems.org/gems/rubocop) and sets it as the active version on PATH:

```sh
mise use -g gem:rubocop
rubocop --version
```

The version will be set in `~/.config/mise/config.toml` with the following format:

```toml
[tools]
"gem:rubocop" = "latest"
```

## Ruby upgrades

If the ruby version used by a gem package changes, (by mise or system ruby), you may need to
reinstall the gem. This can be done with:

```sh
mise install -f gem:rubocop
```

Or you can reinstall all gems with:

```sh
mise install -f "gem:*"
```

## Settings

Set these with `mise settings set [VARIABLE] [VALUE]` or by setting the environment variable listed.

<script setup>
import Settings from '/components/settings.vue';
</script>
<Settings child="gem" :level="3" />
15 changes: 15 additions & 0 deletions docs/dev-tools/backends/pipx.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ The version will be set in `~/.config/mise/config.toml` with the following forma
"pipx:psf/black" = "latest"
```

## Python upgrades

If the python version used by a pipx package changes, (by mise or system python), you may need to
reinstall the package. This can be done with:

```sh
mise install -f pipx:psf/black
```

Or you can reinstall all pipx packages with:

```sh
mise install -f "pipx:*"
```

### Supported Pipx Syntax

| Description | Usage |
Expand Down
4 changes: 2 additions & 2 deletions docs/lang/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ sudo ln -s ~/.local/share/mise/installs/java/openjdk-21/Contents /Library/Java/J

> Note: Not all distributions of the Java SDK support this integration (e.g liberica).
## Legacy version files
## Idiomatic version files

The Java core plugin supports the legacy version files `.java-version` and `.sdkmanrc`.
The Java core plugin supports the idiomatic version files `.java-version` and `.sdkmanrc`.

For `.sdkmanrc` files, mise will try to map the vendor and version to the appropriate version
string. For example, the version `20.0.2-tem` will be mapped to `temurin-20.0.2`. Due to Azul's Zulu
Expand Down
2 changes: 1 addition & 1 deletion docs/mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ cmd "direnv" help="Output direnv function to use mise inside direnv" {

See https://mise.jdx.dev/direnv.html for more information

Because this generates the legacy files based on currently installed plugins,
Because this generates the idiomatic files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change."
cmd "envrc" hide=true help="[internal] This is an internal command that writes an envrc file\nfor direnv to consume."
Expand Down
4 changes: 4 additions & 0 deletions e2e/backend/test_gem_slow
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

mise use ruby
assert "mise x gem:rubocop@1.69.0 -- rubocop --version" "1.69.0"
7 changes: 4 additions & 3 deletions e2e/plugins/core/test_ruby_build_slow
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# Install and build ruby using ruby-build

export MISE_RUBY_INSTALL=0
latest=$(mise latest ruby)
assert_contains "mise x ruby@$latest -- ruby --version" "ruby $latest"
# tested in test_gem_slow
#export MISE_RUBY_INSTALL=0
#latest=$(mise latest ruby)
#assert_contains "mise x ruby@$latest -- ruby --version" "ruby $latest"
16 changes: 8 additions & 8 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ cmd "direnv" help="Output direnv function to use mise inside direnv" {

See https://mise.jdx.dev/direnv.html for more information

Because this generates the legacy files based on currently installed plugins,
Because this generates the idiomatic files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change."
direnv may not know to update environment variables when idiomatic file versions change."
cmd "envrc" hide=true help="[internal] This is an internal command that writes an envrc file\nfor direnv to consume."
cmd "exec" hide=true help="[internal] This is an internal command that writes an envrc file\nfor direnv to consume."
cmd "activate" help="Output direnv function to use mise inside direnv" {
long_help r"Output direnv function to use mise inside direnv

See https://mise.jdx.dev/direnv.html for more information

Because this generates the legacy files based on currently installed plugins,
Because this generates the idiomatic files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change."
direnv may not know to update environment variables when idiomatic file versions change."
after_long_help r"Examples:

$ mise direnv activate > ~/.config/direnv/lib/use_mise.sh
Expand Down Expand Up @@ -1030,7 +1030,7 @@ Note that aliases are also stored in this file
but managed separately with `mise aliases get`"
after_long_help r"Examples:

$ mise settings get legacy_version_file
$ mise settings get idiomatic_version_file
true
"
flag "-l --local" help="Use the local config file instead of the global one"
Expand All @@ -1047,7 +1047,7 @@ but managed separately with `mise aliases`"
after_long_help r#"Examples:

$ mise settings ls
legacy_version_file = false
idiomatic_version_file = false
...

$ mise settings ls python
Expand All @@ -1065,7 +1065,7 @@ but managed separately with `mise aliases`"
This modifies the contents of ~/.config/mise/config.toml"
after_long_help r"Examples:

$ mise settings legacy_version_file=true
$ mise settings idiomatic_version_file=true
"
flag "-l --local" help="Use the local config file instead of the global one"
arg "<KEY>" help="The setting to set"
Expand All @@ -1078,7 +1078,7 @@ This modifies the contents of ~/.config/mise/config.toml"
This modifies the contents of ~/.config/mise/config.toml"
after_long_help r"Examples:

$ mise settings unset legacy_version_file
$ mise settings unset idiomatic_version_file
"
flag "-l --local" help="Use the local config file instead of the global one"
arg "<KEY>" help="The setting to remove"
Expand Down
15 changes: 15 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@
"description": "Timeout in seconds for all HTTP requests in mise.",
"type": "string"
},
"idiomatic_version_file": {
"default": true,
"description": "Set to false to disable the idiomatic version files such as .node-version, .ruby-version, etc.",
"type": "boolean"
},
"idiomatic_version_file_disable_tools": {
"default": [],
"description": "Specific tools to disable idiomatic version files for.",
"type": "array",
"items": {
"type": "string"
}
},
"ignored_config_paths": {
"default": [],
"description": "This is a list of config paths that mise will ignore.",
Expand All @@ -301,11 +314,13 @@
"legacy_version_file": {
"default": true,
"description": "Set to false to disable the idiomatic version files such as .node-version, .ruby-version, etc.",
"deprecated": "Use idiomatic_version_file instead.",
"type": "boolean"
},
"legacy_version_file_disable_tools": {
"default": [],
"description": "Specific tools to disable idiomatic version files for.",
"deprecated": "Use idiomatic_version_file_disable_tools instead.",
"type": "array",
"items": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion schema/mise.plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"additionalProperties": false,
"properties": {
"data": {
"description": "list of legacy filenames to check for",
"description": "list of idiomatic filenames to check for",
"type": "string"
}
}
Expand Down
Loading

0 comments on commit c46ccc3

Please sign in to comment.