Skip to content

Config: build.tools.python has to be a string to avoid confusions #9719

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

Closed
webknjaz opened this issue Nov 9, 2022 · 13 comments
Closed

Config: build.tools.python has to be a string to avoid confusions #9719

webknjaz opened this issue Nov 9, 2022 · 13 comments
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code

Comments

@webknjaz
Copy link
Contributor

webknjaz commented Nov 9, 2022

Details

RTD build page presents an error message that doesn't make sense.

Expected Result

Build should start.

Actual Result

It didn't. Instead, it errored out with a banner saying:

Problem in your project's configuration. Invalid "build.tools.python": expected one of (2.7, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, pypy3.7, pypy3.8, pypy3.9, miniconda3-4.7, mambaforge-4.10, 3), got 3.11

(emphasis mine)
The message says that 3.11 is not a valid version and lists 3.11 among valid versions. That is confusing. Also, the docs page at https://docs.readthedocs.io/en/stable/config-file/v2.html#sphinx-configuration says 3.11 is allowed.

The config file used:

---

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html
# for details

version: 2

sphinx:
  builder: dirhtml
  configuration: docs/conf.py
  fail_on_warning: true

build:
  os: ubuntu-22.04
  tools:
    python: 3.11

python:
  install:
  - method: pip
    path: .
  - requirements: docs/requirements.txt
  system_packages: false

...
@webknjaz
Copy link
Contributor Author

webknjaz commented Nov 9, 2022

Playing the guessing game, I could see it not allowing a float (the fix could be quoting it as '3.11') or the selected ubuntu version not actually having it (although, why would the validator running earlier emit that message?).

@webknjaz
Copy link
Contributor Author

webknjaz commented Nov 9, 2022

Aha! So it did want an explicitly quoted string. Why not just say that in an error message?

@humitos
Copy link
Member

humitos commented Nov 9, 2022

It seems that you find the problem yourself by adding quotes to the Python version. I agree the error message can be improved. Actually, I thought we had an issue about this, but I didn't find it now.

@stsewd
Copy link
Member

stsewd commented Nov 9, 2022

I had this suggestion about this "problem" #8696 (comment).

@webknjaz
Copy link
Contributor Author

webknjaz commented Nov 9, 2022

I think it'd be reasonable to explicitly mention that the config value got parsed as a float and an explicit YAML string is expected.

@webknjaz
Copy link
Contributor Author

webknjaz commented Nov 9, 2022

Here's an idea: make a JSON schema published to SchemaStore. This would allow people to lint it in CI using https://github.com/python-jsonschema/check-jsonschema.git, plus many code editors would make use of it for autocomple. And finally, you could use the very same schema in RTD, making sure that it's the same for everyone.

@stsewd
Copy link
Member

stsewd commented Nov 9, 2022

@webknjaz we already have one https://docs.readthedocs.io/en/stable/config-file/v2.html#schema, and we are already on schemastore. There is an open issue to use it to validate the config file on the server #8549.

@humitos humitos changed the title The build page says that the requested version is bad while listing it as allowed Config: build.tools.python has to be a string to avoid confusions Jan 31, 2023
@humitos humitos added Improvement Minor improvement to code Accepted Accepted issue on our roadmap labels May 31, 2023
@humitos
Copy link
Member

humitos commented May 31, 2023

At this point we could pass what's the expected data type to validate_choice so it mentions it in the message as well:

build["tools"][tool] = validate_choice(
version,
self.settings["tools"][tool].keys(),
)

@mvorisek
Copy link

In general, yaml is not strictly typed format and configs should accept unquoted numbers in places where only strings are allowed. Examples are Github Actions, Ansible, ...

If the RTD parser does not follow schema directly and parses the yaml context-free, it should not be that hard to post-process the parsed data based on the schema, ie. cast the types to based on the schema.

@webknjaz
Copy link
Contributor Author

(with my Ansible Core Dev hat on)

@mvorisek it's not that simple. During parsing, the information about the initial input is lost (unless a custom parser is used). So an unquoted ambiguous 3.10 is parsed as a float 3.1, which will become a string "3.1" during post-processing. This is why so many apps require making such values explicit strings.
So while I agree that it looks nicer as a float, many people would be confused if they don't know the YAML's internals. This is typically solved by making the schema strict.

@humitos
Copy link
Member

humitos commented Feb 21, 2024

We've updated our error message to be more clear regarding this:

Screenshot_2024-02-21_20-12-05

Would this solve/help with the confusion and guide the reader towards the solution?

@humitos
Copy link
Member

humitos commented Feb 28, 2024

I will close this issue since I think the new notification is clear enough. However, feel free to re-open or comment here if you consider there is anything else we can do to make it clearer.

@humitos humitos closed this as completed Feb 28, 2024
@mvorisek
Copy link

mvorisek commented Feb 3, 2025

With #11081 "latest" is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code
Projects
None yet
Development

No branches or pull requests

4 participants