-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Creating one py_binary per main module (#1584)
Many existing Python repos don't use `__main__.py` to indicate the the main module. Instead, they put something like below in any Python files: ```python if __name__ == "__main__": main() ``` This PR makes the Gazelle extension able to recognize main modules like this, when `__main__.py` doesn't exist. This reduces the need to create `__main__.py` when enabling Gazelle extensions in existing Python repos. The current behavior of creating single `py_binary` for `__main__.py` is preserved and takes precedence. So this is a backward-compatible change. Closes #1566.
- Loading branch information
Showing
17 changed files
with
253 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
import parse | ||
|
||
class TestParse(unittest.TestCase): | ||
def test_not_has_main(self): | ||
content = "a = 1\nb = 2" | ||
self.assertFalse(parse.parse_main(content)) | ||
|
||
def test_has_main_in_function(self): | ||
content = """ | ||
def foo(): | ||
if __name__ == "__main__": | ||
a = 3 | ||
""" | ||
self.assertFalse(parse.parse_main(content)) | ||
|
||
def test_has_main(self): | ||
content = """ | ||
import unittest | ||
from lib import main | ||
class ExampleTest(unittest.TestCase): | ||
def test_main(self): | ||
self.assertEqual( | ||
"", | ||
main([["A", 1], ["B", 2]]), | ||
) | ||
if __name__ == "__main__": | ||
unittest.main() | ||
""" | ||
self.assertTrue(parse.parse_main(content)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.