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

Build: pass api_client down to environment/builders/etc #10390

Merged
merged 5 commits into from
Jun 7, 2023

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jun 6, 2023

For #10289 we won't have the credentials hardcoded in our settings anymore, but instead we will be provided with a dynamic token for the build to use, for this reason we now have to pass the api client object around.

We were using the DONT_HIT_API just for testing, instead of doing that, I'm just mocking the api client.

stsewd added 2 commits June 5, 2023 19:47
For #10289
we won't have the credentials hardcoded in our settings anymore,
but instead we will be provided with a dynamic token for the
build to use, for this reason we now have to pass the api client
object around.
@stsewd stsewd requested a review from a team as a code owner June 6, 2023 00:58
@stsewd stsewd requested a review from humitos June 6, 2023 00:58
@readthedocs readthedocs deleted a comment from web-apply Jun 6, 2023
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks like a great first integration. Definitely interesting to see classmethods getting turned into instance methods, but it seems like not a huge amount of data to pass around.

readthedocs/doc_builder/base.py Show resolved Hide resolved
self.api_client = api_client

if self.record and not self.api_client:
raise ValueError("api_client is required when record=True")
Copy link
Member

Choose a reason for hiding this comment

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

Solid defensive programming 👍

readthedocs/projects/models.py Show resolved Hide resolved
@@ -167,33 +166,23 @@ def get_config_params(self):
versions = []
downloads = []
subproject_urls = []
# Avoid hitting database and API if using Docker build environment
if settings.DONT_HIT_API:
Copy link
Member

Choose a reason for hiding this comment

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

We have DONT_HIT_API and DONT_HIT_DB settings, which seem like inverses of the same value 🙃

Does it make sense to try to remove the DONT_HIT_API & DONT_HIT_DB settings as a later refactor here, or are they still needed in other places in the codebase?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think we should just always assume that builders hit our API, and the rest of our code the DB.

Looks like we can just remove DONT_HIT_API, I can try to remove DONT_HIT_DB in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. I think these variables where only useful when we didn't have Docker development setup.

readthedocs/projects/models.py Outdated Show resolved Hide resolved
readthedocs/doc_builder/backends/sphinx.py Outdated Show resolved Hide resolved
@@ -227,7 +226,7 @@ def get_command(self):
return ' '.join(self.command)
return self.command

def save(self):
def save(self, api_client):
Copy link
Member

Choose a reason for hiding this comment

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

I assume it's easier to pass it in here, than to put the client on the BuildCommand when it's created?

Copy link
Member Author

Choose a reason for hiding this comment

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

it touches less code, and the API client is scoped to where is needed (just this method), since commands can be optionally saved.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks like a great first integration. Definitely interesting to see classmethods getting turned into instance methods, but it seems like not a huge amount of data to pass around.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks like a solid change to me 👍

@stsewd stsewd merged commit 60b4133 into main Jun 7, 2023
@stsewd stsewd deleted the pass-api-client-around branch June 7, 2023 23:04
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.

3 participants