Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHave tidy ensure that the there are no extra files in the webidls folder #13427 #13447
Conversation
highfive
commented
Sep 27, 2016
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. |
highfive
commented
Sep 27, 2016
|
Heads up! This PR modifies the following files:
|
|
WIP |
|
Ping me once you've made the changes :) |
cb256ab
to
e6f7afe
|
@wafflespeanut @Manishearth good for review |
e6f7afe
to
91262af
|
@wafflespeanut @Manishearth any ideas on that build failure? It's a little hard to make out what the failure was... |
|
Ignore it, servo's travis is broken right now. The first travis build runs tidy and that's enough for now. |
91262af
to
a5fff06
|
Should |
|
|
||
| ``` | ||
| ./mach test-tidy --no-progress --self-test | ||
| ``` |
This comment has been minimized.
This comment has been minimized.
| DIRECTORIES_FOR_FILETYPES = { | ||
| "components/script/dom/webidls": [".webidl"] | ||
| } | ||
|
|
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Sep 28, 2016
Member
Like @Ms2ger said, this should live in the config file (servo-tidy.toml in the root dir), and the dict should be obtained from the config variable.
| @@ -730,6 +734,19 @@ def parse_config(content): | |||
| config[pref] = user_configs[pref] | |||
|
|
|||
|
|
|||
| def check_directory_files(directories_for_files): | |||
| for directory, file_extensions in directories_for_files.items(): | |||
| files = get_file_list(directory, only_changed_files=False, exclude_dirs=[]) | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Sep 28, 2016
Member
only_changed_files and exclude_dirs should be brought in as an argument, same as how we do for other functions.
| files = get_file_list(directory, only_changed_files=False, exclude_dirs=[]) | ||
| for filename in files: | ||
| expected = [True for possible in file_extensions if filename.endswith(possible)] | ||
| if not expected: |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Sep 28, 2016
Member
This could be changed to,
if not any(filename.endswith(ext) for ext in file_extensions):
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 28, 2016
Author
Member
@Ms2ger @wafflespeanut thank you both for your review, I have implemented the suggested changes, please take another look...
a5fff06
to
07955ba
054b5e9
to
efb85e9
| @@ -46,3 +46,8 @@ directories = [ | |||
| "./target", | |||
| "./ports/cef", | |||
| ] | |||
|
|
|||
| # Directories that are checked for correct file types | |||
| [check_dirs_for_exts] | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 29, 2016
Author
Member
good one, and maybe check_ext is really the best description of what it does?
This comment has been minimized.
This comment has been minimized.
| 'wrong': filename.split('/')[-1], | ||
| 'dir': directory | ||
| } | ||
| yield (filename, 1, "found file with unexpected extension: {wrong} in {dir}".format(**error_details)) |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Sep 28, 2016
Member
This could be more generic like,
"... unexpected extension found for {name}. We only expect {ext} in {dir_name}".format(name=os.path.basename(filename), ext=', '.join(file_extensions), dir_name=os.path.dirname(filename)"Maybe put those stuff in that dictionary before formatting the error?
This comment has been minimized.
This comment has been minimized.
| @@ -723,13 +725,32 @@ def parse_config(content): | |||
| config['ignore']['directories'] = map(lambda path: os.path.join(*path.split('/')), | |||
| config['ignore']['directories']) | |||
|
|
|||
| # Add dict of dir, list of expected ext to config | |||
| dirs_for_ext = config_file.get("check_dirs_for_exts", {}) | |||
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Sep 28, 2016
Member
Since we're using get with defaults, maybe we don't want it in the default config?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 29, 2016
•
Author
Member
By the way, the get with default {} is when accessing the parsed toml file (see this line),
as opposed to the python config object that is declared here
If I remove the check_ext key from the default python config object at the top of the page, then at some point in parse_config I will have to do a config['check_ext'] = {}.
Perhaps actually 'declaring' this key at the top of the page, is more explicit than adding it later elsewhere in the code? Someone later might wonder where that key is coming from, thinking the object on top of the page is the proper 'template' for the config object...
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 29, 2016
•
Author
Member
I also have another small problem :)
Currently I pass the directories to check as an argument to the check_directory_files function, inside the main scan function, by actually grabbing from the config(see). This makes testing that function very easy, as in the test I just pass another list of directories (see)
The funny thing is that, at this point in the scan function, the config hasn't been parsed yet. The parsing only occurs later, during the first iteration of the generators :)
So if I remove the default key on top, I get a KeyError at that point.
If I keep the default key, it works, because the initially empty dict is later mutated during parsing, so by the time the exectution gets to here we have the value we expect.
So the question is, should I move the access to config to inside check_directory_files? If I do, it makes for harder testing of that function, since I would have to mock the config object. Actually, since the object is defined in the same module as the function, and not imported, I'm not sure it could be mocked in testing... (well I guess I could mock toml.loads)
What do you think?
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 30, 2016
Author
Member
OK I have found a solution, I think, I'll push the code and we'll be able to discuss in more concrete way :)
This comment has been minimized.
This comment has been minimized.
gterzian
Sep 30, 2016
Author
Member
Ok, ready for review
I removed the default key in the config, and I'm mocking the config in the tests... Other suggested changes have been implemented as well...
|
@wafflespeanut @jdm Ok, I think this was due to the fact that the order of filenames returned by |
|
I'm surprised, because Travis didn't show a failure on that earlier. @bors-servo r+ |
|
|
…peanut Have tidy ensure that the there are no extra files in the webidls folder #13427 <!-- Please describe your changes on the following line: --> Have tidy ensure that the there are no extra files in the webidls folder #13427 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #13427 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13447) <!-- Reviewable:end -->
|
|
|
@bors-servo retry #13535 |
…peanut Have tidy ensure that the there are no extra files in the webidls folder #13427 <!-- Please describe your changes on the following line: --> Have tidy ensure that the there are no extra files in the webidls folder #13427 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #13427 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13447) <!-- Reviewable:end -->
|
|
highfive
commented
Oct 2, 2016
|
|
@bors-servo: retry |
…peanut Have tidy ensure that the there are no extra files in the webidls folder #13427 <!-- Please describe your changes on the following line: --> Have tidy ensure that the there are no extra files in the webidls folder #13427 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #13427 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13447) <!-- Reviewable:end -->
|
|
gterzian commentedSep 27, 2016
•
edited by wafflespeanut
Have tidy ensure that the there are no extra files in the webidls folder #13427
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is