FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

coursier: additional_dependencies with non-default channel · Issue #2986 · pre-commit/pre-commit · GitHub

Repository navigation

coursier: additional_dependencies with non-default channel #2986

Description

search you tried in the issue tracker

#2702

describe your actual problem

Description

Currently, coursier's additional_dependencies only supports the default channel.
This means it can't pull dependencies from repositories like central.

AS-IS
repos:
- repo: https://github.com/junghoon-vans/pre-coursier
  rev: v0.2.0
  hooks:
  - id: scalafmt
    args: ["--config-str", "version = 2.4.2, runner.dialect = scala3"]
    additional_dependencies: ["scalafmt:2.4.2"] # This is available

  - id: checkstyle
    args: [".", "-c", "./checkstyle.xml"]
    additional_dependencies: ["checkstyle:10.8.0"] # This is not avaliable

Solution

How about changing central to the default repository for more dependencies?
In fact, coursier's default repository also fetches files from central.

TO-BE
repos:
- repo: https://github.com/junghoon-vans/pre-coursier
  rev: v0.2.0
  hooks:
  - id: scalafmt
    args: ["--config-str", "version = 2.4.2, runner.dialect = scala3"]
    additional_dependencies: ["org.scalameta::scalafmt-cli:2.4.2"]

  - id: checkstyle
    args: [".", "-c", "./checkstyle.xml"]
    additional_dependencies: ["com.puppycrawl.tools:checkstyle:10.8.0"]

But the library must be explicitly marked in additional_dependencies.

pre-commit --version

pre-commit:3.4.0

Activity

  1. changed the title [-]coursier: additional_dependencies with custom channel[/-] [+]coursier: additional_dependencies with non-default channel[/+] on Sep 3, 2023
  2. asottile commented on Sep 3, 2023

    Member

    you can already put --channel, ... in additional_dependencies to accomplish what you want

  3. junghoon-vans commented on Sep 3, 2023

    Author

    @asottile Thank you for your advice.
    Am I correct that you are referring to running something like this?

    repos:
    - repo: https://github.com/junghoon-vans/pre-coursier
      rev: v0.2.0
      hooks:
          - id: checkstyle
            args: [".", "-c", "./sun_checks.xml"]
            additional_dependencies: ["--channel", "central", "com.puppycrawl.tools:checkstyle:10.8.0"]

    However, this will result in an error when executed.

    ❯ pre-commit run --all-files -v
    [INFO] Installing environment for https://github.com/junghoon-vans/pre-coursier.
    [INFO] Once installed this environment will be reused.
    [INFO] This may take a few minutes...
    An unexpected error has occurred: CalledProcessError: command: ('/opt/homebrew/bin/cs', 'install', '--dir', '/Users/jeonghun/.cache/pre-commit/repodauna3u9/coursier-default', '--channel', 'central', 'com.puppycrawl.tools:checkstyle:10.8.0')
    return code: 1
    stdout: (none)
    stderr:
        Downloading https://repo1.maven.org/maven2/io/get-coursier/apps/maven-metadata.xml
        Downloaded https://repo1.maven.org/maven2/io/get-coursier/apps/maven-metadata.xml
        Downloading https://repo1.maven.org/maven2/io/get-coursier/apps/1.0.40/apps-1.0.40.pom
        Downloaded https://repo1.maven.org/maven2/io/get-coursier/apps/1.0.40/apps-1.0.40.pom
        Downloading https://repo1.maven.org/maven2/io/get-coursier/apps/1.0.40/apps-1.0.40.jar
        Downloaded https://repo1.maven.org/maven2/io/get-coursier/apps/1.0.40/apps-1.0.40.jar
        Cannot find app com.puppycrawl.tools in channels /Users/jeonghun/.cache/pre-commit/repodauna3u9/central, io.get-coursier:apps
    Check the log at /Users/jeonghun/.cache/pre-commit/pre-commit.log
    

    I was wondering if I should pass --default-channel=false, so I put it in, but I still get the error.

    ❯ pre-commit run --all-files -v
    [INFO] Initializing environment for https://github.com/junghoon-vans/pre-coursier:--default-channels=false --channel central com.puppycrawl.tools:checkstyle:10.8.0.
    [INFO] Installing environment for https://github.com/junghoon-vans/pre-coursier.
    [INFO] Once installed this environment will be reused.
    [INFO] This may take a few minutes...
    An unexpected error has occurred: CalledProcessError: command: ('/opt/homebrew/bin/cs', 'fetch', '--default-channels=false --channel central com.puppycrawl.tools:checkstyle:10.8.0')
    return code: 1
    stdout: (none)
    stderr:
        Argument --default-channels: Unrecognized flag value: false --channel central com.puppycrawl.tools:checkstyle:10.8.0
    Check the log at /Users/jeonghun/.cache/pre-commit/pre-commit.log
    
  4. asottile commented on Sep 3, 2023

    Member

    yeah I'm not super familiar with coursier myself -- if you can show me commands to install checkstyle using coursier outside of pre-commit I can tell you what the pre-commit config should look like

  5. junghoon-vans commented on Sep 4, 2023

    Author

    @asottile sure this is two way to install checkstyle using coursier.

    General

    cs install com.puppycrawl.tools:checkstyle:latest.release

    Since checkstyle is an application that is not in coursier's default channel, it must be explicitly specified.

    Application descriptors

    {
        "mainClass": "com.puppycrawl.tools.checkstyle.Main",
        "repositories": [
          "central"
        ],
        "dependencies": [
          "com.puppycrawl.tools:checkstyle:latest.release"
        ]
    }

    Once you've registered your checkstyle.json in your .pre-commit-channel as above, you can use it as shown below.

    cs install --default-channels=false --channel=.pre-commit-channel checkstyle:latest.release

    Since it's registered to a custom channel, you don't need to explicitly show the library.

  6. asottile commented on Sep 10, 2023

    Member

    sorry took me a while to get back to this -- I think given that it needs additional metadata since it's not traditionally packaged via coursier then it's not possible with additional_dependencies unfortunately

  7. junghoon-vans commented on Sep 11, 2023

    Author

    @asottile
    So why not specify the repositories specified inside the application descriptors as the repositories for additional_dependencies?

    Currently, pre-commit seems to use the channel in the application descriptors with disable default channel.

    https://github.com/pre-commit/pre-commit/blob/5f4b82899929ffdaf94f81ed01dec4e9a1d98636/pre_commit/languages/coursier.py#L51C17-L51C25

    so it makes more sense that the channels in additional dependencies follow those defined in the application descriptors.

    Example

    .pre-commit-channel/checkstyle.json

    {
        "mainClass": "com.puppycrawl.tools.checkstyle.Main",
        "repositories": [
          "central",
          "https://some.custom.maven/repository"
        ],
        "dependencies": [
          "com.puppycrawl.tools:checkstyle:latest.release"
        ]
    }

    Define two repositories.

    .pre-commit-config.yaml

    repos:
    - repo: https://github.com/junghoon-vans/pre-coursier
      rev: v0.2.0
      hooks:
          - id: checkstyle
            args: [".", "-c", "./sun_checks.xml"]
            additional_dependencies: ["com.puppycrawl.tools:checkstyle:10.8.0"] # from central or https://some.custom.maven/repository

    Additional dependencies are pulled from the repositories that defined in .pre-commit-channel/checkstyle.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL