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

Have tidy ensure that the there are no extra files in the webidls folder #13427 #13447

Merged
merged 2 commits into from Oct 2, 2016

Conversation

@gterzian
Copy link
Member

gterzian commented Sep 27, 2016

Have tidy ensure that the there are no extra files in the webidls folder #13427


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13427 (github issue number if applicable).
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

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
Copy link

highfive commented Sep 27, 2016

Heads up! This PR modifies the following files:

@gterzian
Copy link
Member Author

gterzian commented Sep 27, 2016

WIP

@wafflespeanut
Copy link
Member

wafflespeanut commented Sep 27, 2016

Ping me once you've made the changes :)

@Manishearth
Copy link
Member

Manishearth commented Sep 27, 2016

@gterzian gterzian force-pushed the gterzian:check_webidls_folder_files branch 3 times, most recently from cb256ab to e6f7afe Sep 27, 2016
@gterzian
Copy link
Member Author

gterzian commented Sep 27, 2016

@wafflespeanut @Manishearth good for review 👍

@gterzian gterzian force-pushed the gterzian:check_webidls_folder_files branch from e6f7afe to 91262af Sep 27, 2016
@gterzian
Copy link
Member Author

gterzian commented Sep 27, 2016

@wafflespeanut @Manishearth any ideas on that build failure? It's a little hard to make out what the failure was...

@Manishearth
Copy link
Member

Manishearth commented Sep 27, 2016

Ignore it, servo's travis is broken right now. The first travis build runs tidy and that's enough for now.

@gterzian gterzian force-pushed the gterzian:check_webidls_folder_files branch from 91262af to a5fff06 Sep 27, 2016
@Ms2ger
Copy link
Contributor

Ms2ger commented Sep 27, 2016

Should DIRECTORIES_FOR_FILETYPES live in the config file?


```
./mach test-tidy --no-progress --self-test
```

This comment has been minimized.

@wafflespeanut

wafflespeanut Sep 28, 2016

Member

Have a separate commit for the changes to README

DIRECTORIES_FOR_FILETYPES = {
"components/script/dom/webidls": [".webidl"]
}

This comment has been minimized.

@wafflespeanut

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.

@wafflespeanut

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.

@wafflespeanut

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.

@gterzian

gterzian Sep 28, 2016

Author Member

@Ms2ger @wafflespeanut thank you both for your review, I have implemented the suggested changes, please take another look...

@gterzian gterzian force-pushed the gterzian:check_webidls_folder_files branch from a5fff06 to 07955ba Sep 28, 2016
@gterzian gterzian force-pushed the gterzian:check_webidls_folder_files branch 2 times, most recently from 054b5e9 to efb85e9 Sep 28, 2016
@@ -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.

@wafflespeanut

wafflespeanut Sep 28, 2016

Member

Maybe this should have a different name? (like, force_ext?)

This comment has been minimized.

@gterzian

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.

@wafflespeanut

wafflespeanut Sep 29, 2016

Member

Yeah, check_ext is better :)

'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.

@wafflespeanut

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.

@gterzian

gterzian Sep 29, 2016

Author Member

good one 👍

@@ -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.

@wafflespeanut

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.

@wafflespeanut

wafflespeanut Sep 29, 2016

Member

Yes, since we're getting {} by default anyway :)

This comment has been minimized.

@gterzian

gterzian Sep 29, 2016

Author Member

ok 👍

This comment has been minimized.

@gterzian

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.

@gterzian

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.

@gterzian

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.

@gterzian

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...

@gterzian
Copy link
Member Author

gterzian commented Oct 2, 2016

@wafflespeanut @jdm Ok, I think this was due to the fact that the order of filenames returned by os.listdir is not necessarily the same, so, now applying sorted to the names first. That should fix it. (not just to make the test pass, I guess it makes sense to sort the name for display in potential errors anyway...)

@wafflespeanut
Copy link
Member

wafflespeanut commented Oct 2, 2016

I'm surprised, because Travis didn't show a failure on that earlier.

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Oct 2, 2016

📌 Commit 62d9882 has been approved by Wafflespeanut

@bors-servo
Copy link
Contributor

bors-servo commented Oct 2, 2016

Testing commit 62d9882 with merge f9914d5...

bors-servo added a commit that referenced this pull request Oct 2, 2016
…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
Copy link
Contributor

bors-servo commented Oct 2, 2016

💔 Test failed - mac-rel-wpt2

@wafflespeanut
Copy link
Member

wafflespeanut commented Oct 2, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Oct 2, 2016

Testing commit 62d9882 with merge 277e2eb...

bors-servo added a commit that referenced this pull request Oct 2, 2016
…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
Copy link
Contributor

bors-servo commented Oct 2, 2016

💔 Test failed - mac-rel-wpt1

@highfive
Copy link

highfive commented Oct 2, 2016

  ▶ Unexpected subtest result in /html/webappapis/scripting/event-loops/microtask_after_raf.html:
  └ PASS [expected FAIL] Microtask execute immediately after script
@jdm
Copy link
Member

jdm commented Oct 2, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Oct 2, 2016

Testing commit 62d9882 with merge 3a5fd8b...

bors-servo added a commit that referenced this pull request Oct 2, 2016
…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
Copy link
Contributor

bors-servo commented Oct 2, 2016

@bors-servo bors-servo merged commit 62d9882 into servo:master Oct 2, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@gterzian gterzian deleted the gterzian:check_webidls_folder_files branch Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.