Skip to content

Commit

Permalink
Refactor FileContent to use default argument for is_executable (p…
Browse files Browse the repository at this point in the history
…antsbuild#8682)

Over 90% of our usages set the value to `False`. We only didn't use a default because we couldn't until recently using `@dataclass` over `datatype()`.
  • Loading branch information
Eric-Arellano authored Nov 22, 2019
1 parent d652105 commit a681690
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/rules/pex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def create_pex_and_get_pex_info(

def test_generic_pex_creation(self) -> None:
input_files_content = InputFilesContent((
FileContent(path='main.py', content=b'print("from main")', is_executable=False),
FileContent(path='subdir/sub.py', content=b'print("from sub")', is_executable=False),
FileContent(path='main.py', content=b'print("from main")'),
FileContent(path='subdir/sub.py', content=b'print("from sub")'),
))

input_files, = self.scheduler.product_request(Digest, [input_files_content])
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/engine/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FileContent:
"""The content of a file."""
path: str
content: bytes
is_executable: bool
is_executable: bool = False

def __repr__(self):
return 'FileContent(path={}, content=(len:{}), is_executable={})'.format(
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/fs/fs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def rules(cls):
def test(self):
with temporary_dir() as tmp_dir:
input_files_content = InputFilesContent((
FileContent(path='a.txt', content=b'hello', is_executable=False),
FileContent(path='a.txt', content=b'hello'),
))

msg = MessageToConsoleRule(tmp_dir=tmp_dir, input_files_content=input_files_content)
Expand All @@ -75,8 +75,8 @@ def test_workspace_materialize_directories_result(self):
workspace = Workspace(self.scheduler)

input_files_content = InputFilesContent((
FileContent(path='a.txt', content=b'hello', is_executable=False),
FileContent(path='subdir/b.txt', content=b'goodbye', is_executable=False),
FileContent(path='a.txt', content=b'hello'),
FileContent(path='subdir/b.txt', content=b'goodbye'),
))

digest, = self.scheduler.product_request(Digest, [input_files_content])
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/rules/core/cloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run_cloc(console: Console, options: CountLinesOfCode.Options, cloc_script: D
report_filename = 'report.txt'
ignore_filename = 'ignored.txt'

input_file_list = InputFilesContent(FilesContent((FileContent(path=input_files_filename, content=file_content, is_executable=False),)))
input_file_list = InputFilesContent(FilesContent((FileContent(path=input_files_filename, content=file_content),)))
input_file_digest = yield Get(Digest, InputFilesContent, input_file_list)
cloc_script_digest = cloc_script.digest
digests_to_merge.extend([cloc_script_digest, input_file_digest])
Expand Down
2 changes: 1 addition & 1 deletion tests/python/pants_test/engine/test_build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_empty(self):
MockGet(
product_type=FilesContent,
subject_type=Digest,
mock=lambda _: FilesContent([FileContent('/dev/null/BUILD', b'', False)]),
mock=lambda _: FilesContent([FileContent(path='/dev/null/BUILD', content=b'')]),
),
],
)
Expand Down
4 changes: 2 additions & 2 deletions tests/python/pants_test/engine/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ def test_materialize_directories(self):

def test_add_prefix(self):
input_files_content = InputFilesContent((
FileContent(path='main.py', content=b'print("from main")', is_executable=False),
FileContent(path='subdir/sub.py', content=b'print("from sub")', is_executable=False),
FileContent(path='main.py', content=b'print("from main")'),
FileContent(path='subdir/sub.py', content=b'print("from sub")'),
))

digest, = self.scheduler.product_request(Digest, [input_files_content])
Expand Down
10 changes: 5 additions & 5 deletions tests/python/pants_test/engine/test_isolated_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_input_file_creation(self):
file_name = 'some.filename'
file_contents = b'some file contents'

input_file = InputFilesContent((FileContent(path=file_name, content=file_contents, is_executable=False),))
input_file = InputFilesContent((FileContent(path=file_name, content=file_contents),))
digest, = self.scheduler.product_request(Digest, [input_file])

req = ExecuteProcessRequest(
Expand All @@ -227,8 +227,8 @@ def test_input_file_creation(self):

def test_multiple_file_creation(self):
input_files_content = InputFilesContent((
FileContent(path='a.txt', content=b'hello', is_executable=False),
FileContent(path='b.txt', content=b'goodbye', is_executable=False),
FileContent(path='a.txt', content=b'hello'),
FileContent(path='b.txt', content=b'goodbye'),
))

digest, = self.scheduler.product_request(Digest, [input_files_content])
Expand All @@ -246,7 +246,7 @@ def test_file_in_directory_creation(self):
path = 'somedir/filename'
content = b'file contents'

input_file = InputFilesContent((FileContent(path=path, content=content, is_executable=False),))
input_file = InputFilesContent((FileContent(path=path, content=content),))
digest, = self.scheduler.product_request(Digest, [input_file])

req = ExecuteProcessRequest(
Expand All @@ -262,7 +262,7 @@ def test_not_executable(self):
file_name = 'echo.sh'
file_contents = b'#!/bin/bash -eu\necho "Hello"\n'

input_file = InputFilesContent((FileContent(path=file_name, content=file_contents, is_executable=False),))
input_file = InputFilesContent((FileContent(path=file_name, content=file_contents),))
digest, = self.scheduler.product_request(Digest, [input_file])

req = ExecuteProcessRequest(
Expand Down
2 changes: 1 addition & 1 deletion tests/python/pants_test/option/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,5 +1517,5 @@ def _create_config_from_strings(self, config):
fp.seek(0)
payload = fp.read()
return Config.load_file_contents(
config_payloads=[FileContent('blah', payload, is_executable=False)],
config_payloads=[FileContent(path='blah', content=payload)],
)

0 comments on commit a681690

Please sign in to comment.