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

Skylark style guide #63

Closed
davidzchen opened this issue Mar 26, 2015 · 7 comments
Closed

Skylark style guide #63

davidzchen opened this issue Mar 26, 2015 · 7 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) type: documentation (cleanup)
Milestone

Comments

@davidzchen
Copy link
Member

While Skylark is a Python subset, there are slight differences between Skylark/BUILD style vs. the Google Python conventions. For example (from the Skylark cookbook:

def macro(name, visibility=None):
  # Creating a native genrule.
  native.genrule(
      name = name,
      outs = [name + '.txt'],
      cmd = 'echo hello > $@',
      visibility = visibility,
  )

Rule invocations such as native.genrule() follow the BUILD style rather than the standard Python function call style.

I think it would be good to write a Skylark Style Guide that defines a convention for Skylark code and lists some best practices.

@damienmg damienmg assigned damienmg and laurentlb and unassigned damienmg Mar 26, 2015
@damienmg damienmg added the P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) label Mar 26, 2015
@kjiwa
Copy link
Contributor

kjiwa commented Jul 4, 2015

A tool like Chromium's gn format or Closure's fixjsstyle that can automatically clean up BUILD and *.bzl files would be nice along with this. e.g. find -name BUILD -exec gn format {} \;.

See https://code.google.com/p/chromium/codesearch#chromium/src/tools/gn/command_format.cc as an example of a tool that uses a BUILD-like syntax.

@dslomov dslomov added P2 We'll consider working on this in future. (Assignee optional) and removed P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) labels Dec 8, 2016
@dslomov dslomov added this to the 0.6 milestone Dec 8, 2016
@jbduncan
Copy link
Contributor

I'm not sure that this is an issue anymore, given that a BUILD file formatter apparently exists.

@softprops
Copy link

Are there any differences between build file formatting and .bzl files?

@jbduncan
Copy link
Contributor

Good question. I'm new to Bazel, so I didn't realise that there was a difference between the two.

From my current understanding, both BUILD and .bzl files follow the Skylark syntax, so I'd be a little surprised if the BUILD file formatter couldn't format .bzl files as well.

@jbduncan
Copy link
Contributor

Ah, I'm probably mistaken, as there seem to be different style guides for BUILD and .bzl files, which implies to me that there's a difference that is not too obvious.

@laurentlb
Copy link
Contributor

Style guide and formatter are different things.

You don't put the same things in BUILD files and in bzl files, so it's better to have separate style guides.
Buildifier cannot format .bzl files yet (it will skip function definitions).

@laurentlb
Copy link
Contributor

Closing this issue. We have now much more information in the documentation (see Best practices) and a code formatter.

https://docs.bazel.build/versions/master/skylark/bzl-style.html
https://github.com/bazelbuild/buildtools

tomaszstrejczek pushed a commit to tomaszstrejczek/bazel that referenced this issue Oct 20, 2019
The signature of Args.add seems to have changed, now expecting a
positional argument.

See: https://docs.bazel.build/versions/master/skylark/lib/Args.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: documentation (cleanup)
Projects
None yet
Development

No branches or pull requests

8 participants