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

Use pants.toml internally #9090

Merged
merged 8 commits into from
Feb 11, 2020
Merged

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Feb 7, 2020

This allows us to dogfood TOML support.

We make several changes to land this:

  • Fix when an option overrides a DEFAULT value.
  • Fix migrate_to_toml_config.py to work with :, e.g. src/python:target.
  • Add config.TomlSerializer to convert a parsed Python dictionary of option-scopes -> options into a TOML representation.
  • Update all tests to use TOML.

We do not change any public-facing documentation or user-messages - those still refer to INI.

@Eric-Arellano Eric-Arellano force-pushed the use-toml branch 4 times, most recently from df446ce to d0433e1 Compare February 10, 2020 21:41
@Eric-Arellano Eric-Arellano changed the title WIP: Use pants.toml internally Use pants.toml internally Feb 11, 2020
@Eric-Arellano Eric-Arellano marked this pull request as ready for review February 11, 2020 00:15
Copy link
Contributor Author

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Reviewers: each commit is distinct and they're generally ordered logically (although it looks like GitHub swapped the order of the last two commits?)

@@ -83,7 +83,7 @@ def generate_new_config(config: Path) -> List[str]:
for i, line in enumerate(original_text_lines):
option_regex = r"(?P<option>[a-zA-Z0-9_]+)"
before_value_regex = rf"\s*{option_regex}\s*[:=]\s*"
valid_value_characters = r"a-zA-Z0-9_.@!%\=\>\<\-\(\)\/"
valid_value_characters = r"a-zA-Z0-9_.@!:%\=\>\<\-\(\)\/"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, we weren't properly converting options with : in the value, such as target: src/python:example.

# --remote-oauth-bearer-token-path=<(gcloud auth application-default print-access-token | perl -p -e 'chomp if eof')
# --no-v1 --v2 test tests/python/pants_test/util:strutil
#
# Remoting does not work for every goal, so you should not permanently point to this ini file, e.g.
# via an env var; only point to it when you want to remote a specific invocation.

[DEFAULT]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to GLOBAL. It works to be DEFAULT but is not very idiomatic. DEFAULT is useful when you want to use string interpolation or apply an option to multiple sections.

Comment on lines -393 to +396
if option in self.defaults:
return self._stringify_val(self.defaults[option])
if option not in section_values:
raise configparser.NoOptionError(option, section)
if option not in self.defaults:
raise configparser.NoOptionError(option, section)
return self._stringify_val(self.defaults[option])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes were necessary to get it working when an option overrides a DEFAULT option with the same name.



@dataclass(frozen=True)
class TomlSerializer:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we only use this for PantsRunIntegrationTest, but I imagine we might have some use down the road so I put it in config.py.

Copy link
Contributor

@codealchemy codealchemy left a comment

Choose a reason for hiding this comment

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

✔️

@cosmicexplorer
Copy link
Contributor

This allows us to dogfood TOML support.

I'm not sure this description covers the change to also using e.g. pants.toml instead of pants.ini in all documentation, and deleting pants.ini. Is the plan to remove ini support entirely? Where is that documented?

@Eric-Arellano
Copy link
Contributor Author

Is the plan to remove ini support entirely?

I was planning in a followup to propose deprecating INI so that we can consolidate around one sane config file. I first mentioned my intention to propose doing this in the original TOML PR: #9052. It's also why it was so important to me that we have migrate_to_toml_config.py, so that the deprecation doesn't take more than 3-10 minutes for a Pants admin to address.

Good point about not updating any public-facing deprecation warnings, though! You're right that it doesn't belong here and I was being lazy including here.

….toml. Stick with pants.ini

We do still update all tests to refer to TOML, though, as this PR makes that change.
Copy link
Contributor

@cosmicexplorer cosmicexplorer left a comment

Choose a reason for hiding this comment

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

Awesome!

@Eric-Arellano
Copy link
Contributor Author

I had canceled the CI run on this last commit because it only made 3 small changes to docstring / user-messages. The prior commit was green.

Thanks for the reviews!

@Eric-Arellano Eric-Arellano merged commit e13ae3f into pantsbuild:master Feb 11, 2020
@Eric-Arellano Eric-Arellano deleted the use-toml branch February 11, 2020 21:27
Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

"%(buildroot)s/contrib/thrifty/src/python",
"%(buildroot)s/pants-plugins/src/python",
]
backend_packages.add = [
Copy link
Member

Choose a reason for hiding this comment

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

Can toml keys contain any useful special characters? If so, it might actually be desirable to have the ".add"/".remove" syntaxes jump out even more than they do as magical... strawman:

backend_packages.++ = [
  ..
]

(related: @illicitonion recently pointed out a convention of using # keys in json to add comments, which made me think about this.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good idea! Unfortunately, with the current spec, you'd have to wrap it in quotes:

backend_packages."++" = [
  "..",
]

But they're considering loosening the spec to allow any unicode symbol for a key name (particularly helpful for other languages). toml-lang/toml#687

Copy link
Contributor

@blorente blorente left a comment

Choose a reason for hiding this comment

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

I didn't submit the review the first time :(

"\n\nTo prepare, set `skip: True` in your `pants.ini` under the section "
"`python-eval`. If you still need to use this tool, set `skip: False`. In "
"Pants 1.27.0.dev0, the default will change from `skip: False` to `skip: True`, "
"\n\nTo prepare, set `skip = true` in your `pants.toml` under the section "
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure there's cases of this old ini syntax still hanging around in the codebase, even if the comments don't specifically refer to pants.ini. It's probably out of the scope of this change, but would it make sense to open a follow-up issue to search and change those?

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.

6 participants