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

Tidy config file #12877

Merged
merged 2 commits into from Aug 21, 2016
Merged

Tidy config file #12877

merged 2 commits into from Aug 21, 2016

Conversation

@UK992
Copy link
Contributor

UK992 commented Aug 15, 2016

This is wip workaround for #10841
Adds servo-tidy.toml with configs and ignored dirs, files and packages.
This will allow to set custom configuration per repo.
It's an example how could config file looks like.
I want opinion on that, if this is right approaches and how to improve it.

cc @edunham


This change is Reviewable

@highfive
Copy link

highfive commented Aug 15, 2016

Heads up! This PR modifies the following files:

@UK992 UK992 force-pushed the UK992:tidy-toml branch from fdafa75 to 82dc399 Aug 15, 2016
import toml

# Load configs from servo-tidy.toml if config file exists
if os.path.exists("./servo-tidy.toml"):

This comment has been minimized.

Copy link
@edunham

edunham Aug 15, 2016

Contributor

Please catch the case in which the config file does not exist, as well. Printing "./servo-tidy.toml config file is required but was not found" and exiting would be fine.

A user who naively deletes the config file will get a confusing pile of errors later when the code tries to read from a var like exclude that only exists if the config file exists and was read successfully, so let's save them from that.

This comment has been minimized.

Copy link
@edunham

edunham Aug 15, 2016

Contributor

Also, why have you split the config-file-reading logic between the top level here and the set_configs function down at L86?

This comment has been minimized.

Copy link
@UK992

UK992 Aug 15, 2016

Author Contributor

set_config was meant for override default configs. Top-level logic was to set constants for ignored files/dirs, But now its added to config under ignore.

@@ -104,6 +76,23 @@
" accessible to\n// web pages."
]

# Default configs
config = {

This comment has been minimized.

Copy link
@edunham

edunham Aug 15, 2016

Contributor

Why do you have a default config dict, but no default for exclude or ignored_dirs? (up on L25, see other line note)

@edunham
Copy link
Contributor

edunham commented Aug 15, 2016

Thank you for the PR! The config file looks great to me.

However, it looks like you're taking two separate approaches to how the config file should be treated, and I'd personally find the code much easier to read and debug if you standardized on one or the other. The approaches that I'm seeing you take are:

  1. for exclude and ignored_dirs, you're only setting them if servo_tidy.toml exists. The config file is mandatory, for if it's absent, code like L290 of tidy.py will blow up on the undefined variables.

  2. For config, you're setting a default value (L80 of tidy.py) and gracefully failing back to the default if nothing is set in the config file or if the config file doesn't even exist. This makes the config file optional and places more importance on the hardcoded defaults.

Either approach would be ok -- (1) would probably be easier to implement, requiring fewer lines of code and less reasoning about defaults, whereas (2) would make tidy behave more gracefully (though perhaps in a silently wrong manner, depending on the project) if it was used without a config file or with a malformed config.

For tidy's current usage, I think the config file is mandatory. Regardless of whether you implement default values for missing configs, the absence of a config file should cause tidy to exit with a helpful error message.

@UK992
Copy link
Contributor Author

UK992 commented Aug 15, 2016

Now its unified to config defaults, more simplified.

@edunham
Copy link
Contributor

edunham commented Aug 16, 2016

Looks great to me! Thanks for making those changes.

@wafflespeanut, want to take a quick look too, since highfive picked you for this one?

@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 16, 2016

Of course! This is in my queue. I'll look into it :)

@UK992
Copy link
Contributor Author

UK992 commented Aug 16, 2016

Last commit adds checking for wrong keys or tables in tidy config file. This will prevent adding wrong keys/tables.

@edunham edunham mentioned this pull request Aug 16, 2016
@UK992 UK992 force-pushed the UK992:tidy-toml branch 4 times, most recently from 28a59fe to 6add322 Aug 17, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2016

The latest upstream changes (presumably #11756) made this pull request unmergeable. Please resolve the merge conflicts.

@UK992 UK992 force-pushed the UK992:tidy-toml branch from 6add322 to 070f6ef Aug 17, 2016
@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 18, 2016

Sorry I let this bitrot. I'll look into this tonight 😄

@@ -706,11 +737,16 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
continue
with open(filename, "r") as f:
contents = f.read()
lines = contents.splitlines(True)
if filename.endswith(os.path.join(os.sep, "servo-tidy.toml")):

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Aug 18, 2016

Member

This may not be the correct place to check the config file, since that's probably the first thing that we should be doing. Let's move check_config_file to scan, have a separate variable binding config_errors for this thing, and chain with the other iterators in such a way that this is done first.

This comment has been minimized.

Copy link
@UK992

UK992 Aug 18, 2016

Author Contributor

done.

}

# Load configs from servo-tidy.toml
if os.path.exists("./servo-tidy.toml"):

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Aug 18, 2016

Member

Looks like we're using "servo-tidy.toml" throughout the code - maybe put that as a constant at the top (say, CONFIG_FILE_PATH?)

This comment has been minimized.

Copy link
@UK992

UK992 Aug 18, 2016

Author Contributor

done.

@@ -694,6 +695,36 @@ def check_spec(file_name, lines):
brace_count -= 1


def check_config_file(lines):
current_table = ""
for idx, line in enumerate(lines):

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Aug 18, 2016

Member

Since we've planned to prioritize this check, instead of relying on collect_errors_for_files, we should initially check whether the config file exists, get the contents, and begin tidying.

This comment has been minimized.

Copy link
@UK992

UK992 Aug 18, 2016

Author Contributor

done.

@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 20, 2016

Can you please squash the commits appropriately?

@UK992 UK992 force-pushed the UK992:tidy-toml branch from 69a4342 to ad94d04 Aug 20, 2016
@UK992 UK992 changed the title WIP: Tidy config file Tidy config file Aug 20, 2016
@UK992
Copy link
Contributor Author

UK992 commented Aug 20, 2016

done.

@UK992 UK992 force-pushed the UK992:tidy-toml branch from ad94d04 to 74dba5c Aug 20, 2016
@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 21, 2016

I still have a few nits, but I don't wanna be nitpicky about those. I'll take care of it later. Thanks for doing this! :)

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Aug 21, 2016

📌 Commit 74dba5c has been approved by Wafflespeanut

@bors-servo
Copy link
Contributor

bors-servo commented Aug 21, 2016

Testing commit 74dba5c with merge 1c9650c...

bors-servo added a commit that referenced this pull request Aug 21, 2016
Tidy config file

This is wip workaround for #10841
Adds ``servo-tidy.toml`` with configs and ignored dirs, files and packages.
This will allow to set custom configuration per repo.
It's an example how could config file looks like.
I want opinion on that, if this is right approaches and how to improve it.

cc @edunham

<!-- 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/12877)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 21, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 21, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-table-007.htm
  └   → /css-transforms-1_dev/html/transform-table-007.htm a5c014b20ef1363bea6f24eda28c7efb7c45698a
/css-transforms-1_dev/html/reference/transform-blank-ref.htm fa6407b1acbbfea27e27061e7d1bdeca98e4a728
Testing a5c014b20ef1363bea6f24eda28c7efb7c45698a == fa6407b1acbbfea27e27061e7d1bdeca98e4a728
@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 21, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 21, 2016

Previous build results for arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Aug 21, 2016

@bors-servo bors-servo merged commit 74dba5c into servo:master Aug 21, 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
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.

None yet

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