Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pyc
# Ignore all bazel symlinks
/bazel-*
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pre-installed packages for which these rules are not required, then use `pazel -
### Ignoring rules in existing BUILD files

The tag `# pazel-ignore` causes `pazel` to ignore the rule that immediately follows the tag in an
existing BUILD file. In particular, the tag can be used to skip custom rules that `pazel` does not
existing BUILD file. In particular, the tag can be used to skip custom rules that `pazel` does not
handle. `pazel` places the ignored rules at the bottom of the BUILD file. See `sample_app/foo/BUILD`
for an example using the tag.

Expand All @@ -90,6 +90,9 @@ The user can define variables `HEADER` and `FOOTER` to add custom header and foo
all BUILD files, respectively. See `sample_app/.pazelrc` and `sample_app/BUILD` for an example that
adds the same `visibility` to all BUILD files.

If you'd like to generate BUILD.bazel files, you can set the option:
`BUILD_FILE_NAME = 'BUILD.bazel'`.

If some pip package has different install name than import name, then the user
should define `EXTRA_IMPORT_NAME_TO_PIP_NAME` dictionary accordingly. `sample_app/.pazelrc` has
`{'yaml': 'pyyaml'}` as an example. In addition, the user can specify local packages and their
Expand Down
4 changes: 2 additions & 2 deletions pazel/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def app(input_path, project_root, contains_pre_installed_packages, pazelrc_path)
"""
# Parse user-defined extensions to pazel.
output_extension, custom_bazel_rules, custom_import_inference_rules, import_name_to_pip_name, \
local_import_name_to_dep, requirement_load = parse_pazel_extensions(pazelrc_path)
local_import_name_to_dep, requirement_load, build_file_name = parse_pazel_extensions(pazelrc_path)

# Handle directories.
if os.path.isdir(input_path):
Expand All @@ -41,7 +41,7 @@ def app(input_path, project_root, contains_pre_installed_packages, pazelrc_path)
build_source = ''

# Parse ignored rules in an existing BUILD file, if any.
build_file_path = get_build_file_path(dirpath)
build_file_path = get_build_file_path(dirpath, build_file_name)
ignored_rules = get_ignored_rules(build_file_path)

for filename in sorted(filenames):
Expand Down
6 changes: 3 additions & 3 deletions pazel/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def contains_python_file(directory):
return contains_py


def get_build_file_path(path):
def get_build_file_path(path, build_file_name):
"""Get path to a BUILD file next to a given path.

Args:
Expand All @@ -40,9 +40,9 @@ def get_build_file_path(path):
if os.path.isdir(path):
directory = path
else:
directory = os.path.dirpath(path)
directory = os.path.dirname(path)

build_file_path = os.path.join(directory, 'BUILD')
build_file_path = os.path.join(directory, build_file_name)

return build_file_path

Expand Down
7 changes: 6 additions & 1 deletion pazel/pazel_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@ def parse_pazel_extensions(pazelrc_path):

assert isinstance(requirement_load, str), "REQUIREMENT must be a string."

default_build_file_name = 'BUILD'
build_file_name = getattr(pazelrc, 'BUILD_FILE_NAME', default_build_file_name)
assert isinstance(build_file_name, str), "BUILD_FILE_NAME must be a string."

return output_extension, custom_bazel_rules, custom_import_inference_rules, \
import_name_to_pip_name, local_import_name_to_dep, requirement_load
import_name_to_pip_name, local_import_name_to_dep, requirement_load, \
build_file_name
3 changes: 2 additions & 1 deletion pazel/tests/test_pazel_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_invalid_pazelrc_file(self):
pazelrc_path = 'fail'

output_extension, custom_bazel_rules, custom_import_inference_rules, \
import_name_to_pip_name, local_import_name_to_dep, requirement_load \
import_name_to_pip_name, local_import_name_to_dep, requirement_load, \
build_file_name \
= parse_pazel_extensions(pazelrc_path)

self.assertEqual(output_extension.header, '')
Expand Down