Git Product home page Git Product logo

Comments (2)

denian avatar denian commented on May 7, 2024 2

Hi Shuai,

The general approach that we've been following is to implement specific transformations (that can delegate on another tool/sub-process) instead of a general "black-box" transform where you can run any command.

There are several reasons for this, for example it provides a much better API in terms of the configuration. If you see a transform like (just making this up):

python.format(paths = glob(['**.py']),

it's much clear and scoped than something like:

core.run_binary('path/to/some/script.sh arg1 arg2...'),

and there's also the problem of, how do you specify the binary, how it's resolved, etc.

But the main issue is reversibility. Having a blind transform that runs some command does not offer any control on that, unless you make this transform explicitly non-reversible, or you have a reverse field.

We do have some format transformations internally, and they are implemented in this way:

public class MyFormatToolTransform implements Transformation {

  MyFormatToolTransform(Glob glob, MyFormatToolOptions formatOptions) {
    ...
  }

  @Override
  public void transform(TransformWork work) throws IOException, ValidationException {
    Iterable<FileState> files = work.getTreeState().find(glob.relativeTo(work.getCheckoutDir()));
    // Run your format tool on the files
    formatOptions.run(files);
    ...
  }

  @Override
  public Transformation reverse() {
    return new ExplicitReversal(IntentionalNoop.INSTANCE, this);
  }
}

where the MyFormatToolOptions resolves the binary to a default location (for example /usr/bin/format) but also exposes a flag so users can overwrite that.

Note that in this case we set explicitly that the format transformation reverse is noop.

Could you say more about the format tool that you want to run? Is it open source?

Also, are happy to accept contributions :)

from copybara.

hcoona avatar hcoona commented on May 7, 2024

I want support for:

Would you like to give more details about MyFormatToolTransform? I'd like to take it as an example for contributing.

from copybara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.