Skip to content

[viewcfg] Add Python code header, prevent execution when importing #808

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

Merged
merged 2 commits into from
Dec 29, 2015

Conversation

modocache
Copy link
Contributor

What's in this pull request?

This adds the standard Python code header to viewcfg. It also adds an idiomatic Python check that prevents code from being run if the file is imported by another Python script.

Why merge this pull request?

  • It makes the script more consistent with the rest of the Python code in the Swift codebase.
  • It allows the script to be imported and used by other scripts, if that ever becomes desirable.
  • It adds the proper copyright to the file.

What downsides are there to merging this pull request?

One could argue that a code header should be added to all Python files in the codebase at once, in a single commit. I'm not doing so here because I happened upon this file when using it, and decided to send a quick pull request, instead of trying to find all the remaining Python in this repository.

Add code headers missing from utils/viewcfg, as per the template from swiftlang#762.
In order to prevent the Python interpreter from running code that is
meant to be executed directly, the convention is to check the context
in which the code is being interpreted.

Add a check for the context stored in the `__name__` variable, and only
execute the viewcfg script if it is being run as a command-line
script (that is, `__main__`).
gribozavr added a commit that referenced this pull request Dec 29, 2015
[viewcfg] Add Python code header, prevent execution when importing
@gribozavr gribozavr merged commit f96a116 into swiftlang:master Dec 29, 2015
@gribozavr
Copy link
Contributor

@modocache Thanks!

@modocache modocache deleted the viewcfg branch December 29, 2015 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants