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

Fix license scripts #207

Merged
merged 6 commits into from
Apr 15, 2019
Merged

Conversation

dtaniwaki
Copy link
Contributor

I found the current license scripts don't work if we have other top directories like cmd because the patter matching *[!vendor] is not correct syntax for the expected behavior of excluding vendor directory.

Copy link
Collaborator

@ordovicia ordovicia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I overlooked that example directory is being ignored by the current script.
The change looks great except some points I commented.

"git rev-parse --show-toplevel".split()).strip().decode("utf-8"))
PROJECT_ROOT = subprocess.check_output(
"git rev-parse --show-toplevel".split()).strip().decode("utf-8")
target_dirs = [os.path.join(PROJECT_ROOT, d) for d in os.listdir(PROJECT_ROOT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_dirs is used only in main(). Please consider moving target_dirs into main() to minimize the scope.

PROJECT_ROOT = subprocess.check_output(
"git rev-parse --show-toplevel".split()).strip().decode("utf-8")
target_dirs = [os.path.join(PROJECT_ROOT, d) for d in os.listdir(PROJECT_ROOT)
if d != "vendor" and os.path.isdir(os.path.join(PROJECT_ROOT, d))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a matter of taste, but using pathlib would make the code easier to read and write. Also, it would maintain consistency with other parts that are using pathlib.

for d in target_dirs:
add(Path(d).glob("**/*_k8s.go"), license_header("//", modification=True), verbose)
add([p for p in Path(d).glob("**/*.go")
if p.name[-7:] != "_k8s.go"], license_header("//"), verbose)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For avoiding a magic number ..

Suggested change
if p.name[-7:] != "_k8s.go"], license_header("//"), verbose)
if not p.name.endswith("_k8s.go")], license_header("//"), verbose)

(I wrote the original code 😉 )

ok &= check(Path(PROJECT_ROOT).glob("*.go"), license_header("//"), verbose)
ok &= check(Path(PROJECT_ROOT).glob("*.py"), license_header("#"), verbose)
ok &= check(Path(PROJECT_ROOT).glob("*.sh"), license_header("#"), verbose)
ok &= check(PROJECT_ROOT.glob("*.go"), license_header("//"), verbose)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move this into the loop below, but maybe the current code is easier to read?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine, but I personally prefer the current code.

add(PROJECT_ROOT.glob("*.py"), license_header("#"), verbose)
add(PROJECT_ROOT.glob("*.sh"), license_header("#"), verbose)

for p in PROJECT_ROOT.glob("*"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you can use iterdir instead of glob("*").

ok &= check(Path(PROJECT_ROOT).glob("*.go"), license_header("//"), verbose)
ok &= check(Path(PROJECT_ROOT).glob("*.py"), license_header("#"), verbose)
ok &= check(Path(PROJECT_ROOT).glob("*.sh"), license_header("#"), verbose)
ok &= check(PROJECT_ROOT.glob("*.go"), license_header("//"), verbose)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine, but I personally prefer the current code.

@ordovicia ordovicia added the bug Category: Something isn't working label Apr 14, 2019
@ordovicia ordovicia merged commit 55e4108 into pfnet-research:master Apr 15, 2019
@ordovicia ordovicia added the infra Area: Issues and PRs related to the development infrastructure (e.g. CI, license scripts) label Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Category: Something isn't working infra Area: Issues and PRs related to the development infrastructure (e.g. CI, license scripts)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants