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

Fixes part of #4374: Update docstrings in the python backend code. #6028

Merged
merged 18 commits into from
Jan 6, 2019
Merged

Fixes part of #4374: Update docstrings in the python backend code. #6028

merged 18 commits into from
Jan 6, 2019

Conversation

YashJipkate
Copy link
Contributor

@YashJipkate YashJipkate commented Dec 24, 2018

Updated docstrings in Python Backend code for core.storage.base_model.gae_models_test, core.storage.base_model.gae_models, core.storage.user.gae_models, core.tests.test_utils, core.tests.performance_tests.base, core.tests.performance_framework.perf_services, core.tests.performance_framework.perf_domain, core.domain.summary_services, core.domain.email_jobs_one_off_test, core.domain.visualization_registry

Explanation

Fixes part of #4374

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue.

Updated docstrings in Python Backend code for core.storage.base_model.gae_models_test, core.storage.base_model.gae_models, core.storage.user.gae_models, core.tests.test_utils, core.tests.performance_tests.base, core.tests.performance_framework.perf_services, core.tests.performance_framework.perf_domain, core.domain.summary_services, core.domain.email_jobs_one_off_test, core.domain.visualization_registry
@bansalnitish
Copy link
Contributor

HI @YashJipkate, Thanks for the PR.
Could you change the PR title as Fixes part of #4374: Explanation ? Thanks

@YashJipkate YashJipkate changed the title Fixes part of #4374 Fixes part of #4374: Update docstrings in the python backend code. Dec 24, 2018
@YashJipkate
Copy link
Contributor Author

@bansalnitish Done! PTAL!

@codecov-io
Copy link

codecov-io commented Dec 24, 2018

Codecov Report

Merging #6028 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6028   +/-   ##
========================================
  Coverage    45.21%   45.21%           
========================================
  Files          523      523           
  Lines        30722    30722           
  Branches      4605     4605           
========================================
  Hits         13892    13892           
  Misses       16830    16830

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd22391...e048099. Read the comment docs.

Copy link
Contributor

@vibhor98 vibhor98 left a comment

Choose a reason for hiding this comment

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

Hi @YashJipkate, Took a pass, PTAL!

core/domain/email_jobs_one_off_test.py Show resolved Hide resolved
core/domain/summary_services.py Show resolved Hide resolved
core/storage/user/gae_models.py Show resolved Hide resolved
core/storage/user/gae_models.py Outdated Show resolved Hide resolved
core/storage/user/gae_models.py Outdated Show resolved Hide resolved
core/tests/performance_tests/base.py Outdated Show resolved Hide resolved
core/tests/test_utils.py Outdated Show resolved Hide resolved
headers: dict. Extra headers to send.

Returns:
json_response: webtest.TestResponse instance. The response of the
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove var name here (json_response)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also is it a general practice to not mention variable name in the return?
Thanks!
Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah!

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 Thanks for the info!

core/tests/test_utils.py Outdated Show resolved Hide resolved
upload_files: list. A list of (fieldname, filename, file_content).
You can also use just (fieldname, filename) and the file contents
will be read from disk.
headers: dict. Extra headers to send.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto. Write type info like dict(str, *) for both key-value pairs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

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

Just a minor nit @YashJipkate, Please fix it. Thanks!

core/tests/performance_framework/perf_services.py Outdated Show resolved Hide resolved
Copy link
Contributor

@vibhor98 vibhor98 left a comment

Choose a reason for hiding this comment

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

@YashJipkate there are few minor nits that you missed. PTAL, else LGTM! Thanks!

Args:
user_id: str. The id of the user.
exploration_id: str. The id of the exploration.
Returns:
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to be done. Add blank line before Returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Sorry for missing it.

@@ -406,6 +418,15 @@ class ExplorationUserDataModel(base_models.BaseModel):

@classmethod
def _generate_id(cls, user_id, exploration_id):
"""Generates key for the instance of ExplorationUserDataModel class in
the required format with the arguments provided.
Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Args:
user_id: str. The id of the user.
exploration_id: str. The id of the exploration.
Returns:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -173,6 +173,16 @@ def get_total_page_size_bytes(self):
return total_size

def _get_duration_millisecs(self, event_end, event_initial):
"""Get page load duration.
Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

# Waits for the complete page to load, otherwise XHR requests
# made post initial page load will not be recorded.
time.sleep(time_duration_secs or self.DEFAULT_WAIT_DURATION_SECS)

def _setup_proxy_server(self, downstream_kbps=None, upstream_kbps=None,
latency=None):
"""Sets up a browsermobproxy server.
Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -294,6 +334,10 @@ def _is_current_user_logged_in(self, driver):
return True

def _login_user(self, driver):
"""Logs in a user and gets the cookie of the current session.
Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto. Add blank line before Args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -79,6 +103,13 @@ def _record_average_page_timings_from_uncached_session(

def _record_average_page_timings_from_cached_session(
self, session_count=DEFAULT_SESSION_SAMPLE_COUNT):
"""Record average page timings from cached session.
Copy link
Contributor

Choose a reason for hiding this comment

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

Records (for consistency).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Minor fix
Minor fixes
Minor fixes

Merge branch 'docstrings-backend' of https://github.com/YashJipkate/oppia into docstrings-backend
Copy link
Contributor

@vibhor98 vibhor98 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @YashJipkate! 👍

@YashJipkate
Copy link
Contributor Author

YashJipkate commented Dec 25, 2018

@vibhor98 Thanks for your time and guidance and the approval!

@YashJipkate
Copy link
Contributor Author

@ankita240796 Thanks for your review!!

@vibhor98
Copy link
Contributor

Hi @apb7, Can you review this PR also being one of the code owners? Thanks!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

Hi @YashJipkate, this looks good! Left a few comments. Also, can you please ensure that we do not cutoff any line before the 80 character limit? Thanks!

Returns:
str. Empty if recipient_id is 'recipient_id2',
None if 'recipient_id1' and 'Email Hash'
otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we shift otherwise to the above line without exceeding the 80 characters limit? If yes, then please go ahead and shift it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -429,6 +430,7 @@ def _compute_snapshot(self):
return self.to_dict(exclude=['created_on', 'last_updated'])

def _reconstitute(self, snapshot_dict):
"""Populates the model instance with the snapshot."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @vibhor98, don't we require Args for snapshot_dict here?

Copy link
Contributor Author

@YashJipkate YashJipkate Dec 26, 2018

Choose a reason for hiding this comment

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

Hi @apb7 I have added it for now; will remove if turns out to be unnecesary.
Also, I am skeptical about the way I wrote the return type. PTAL. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's optional in test files. Else, we need to write them. @YashJipkate, thanks for adding them here!

self.data_fetcher.load_url(self.page_url)

def _record_page_metrics_from_uncached_session(self):
"""Records the page metrics from uncached session for a given page
URL.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move URL to the above line as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it exceeds the limit in this case...
Thanks!

self.page_metrics = (
self.data_fetcher.get_page_metrics_from_uncached_session(
self.page_url))

def _record_page_metrics_from_cached_session(self):
"""Records the page metrics from cached session for a given page
URL.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apb7 Done!!

Args:
page_config: dict. The page configuration parameters.
append_username: bool. Whether to append username to the
page URL.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apb7 Done!!

@YashJipkate
Copy link
Contributor Author

@apb7 just a gentle reminder. Kindly review.
Thanks!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @YashJipkate!

@vibhor98
Copy link
Contributor

Hi @BenHenning, can you review this PR being one of the code owners? Thanks!

@YashJipkate
Copy link
Contributor Author

Hi @BenHenning, just a gentle reminder. Kindly review.
Thanks!

@YashJipkate
Copy link
Contributor Author

Hi @BenHenning, A reminder again. Kindly review.
Thanks!

@vibhor98
Copy link
Contributor

vibhor98 commented Jan 4, 2019

Hi @seanlip, can you review this PR once since you're one of the code owners? Thanks!

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

Hi @YashJipkate, thanks for this PR. Just a few comments but otherwise it looks great!

"""Get page load duration.

Args:
event_end: str. The event upto which duration measurement is
Copy link
Member

Choose a reason for hiding this comment

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

Nit: upto --> up to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

downstream_kbps: int. The downstream speed in kbps. Defaults to
None.
upstream_kbps: int. The upstream speed in kbps. Defaults to None.
latency: int. The latency of the server. Defaults to None.
Copy link
Member

Choose a reason for hiding this comment

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

In what unit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in milliseconds.
Done!

latency: int. The latency of the server. Defaults to None.

Returns:
tuple(server, proxy): A tuple consisting of the server and the
Copy link
Member

Choose a reason for hiding this comment

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

I don't think "server" and "proxy" are the actual type names; ditto for "driver" below and throughout the remainder of this file. Could you please make sure the types are correct? For instances of classes it should be the class name (so, in this case, it should be Server for the first arg, since it's an instance of browsermobproxy.Server).

Don't just change everything to start with uppercase, though -- make sure to actually figure out what class it is an instance of. When resolving this comment, please also include (in your comment) a reference to where the driver class is defined.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The driver class is defined as here
Changed Server type name and updated proxy type to dict.
PTAL. Thanks!

headers: dict(str, *). Extra headers to send.

Returns:
webtest.TestResponse instance: The response of the
Copy link
Member

Choose a reason for hiding this comment

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

webtest.TestResponse. The response of the POST request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

self, app, url, data, expect_errors=False, expected_status_int=200,
upload_files=None, headers=None):
"""Sends a post request with the data provided to the url specified.

Args:
Copy link
Contributor Author

@YashJipkate YashJipkate Jan 5, 2019

Choose a reason for hiding this comment

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

@seanlip I had to add the disable pylint statement here because it was saying missing-param-doc for parameter "app" but it was clearly there. Also I noticed that changing Args to Params solved the issue but I didnt went ahead with it as it would break the style. PTAL!
Thanks.

@YashJipkate
Copy link
Contributor Author

@nithusha21 @seanlip I just saw it is showing 140 changed files changed. I recently pulled the latest develop branch in my current docstrings-backend branch which has caused this. But the changes in all the files except the 10 I have changed myself are already there in the main develop branch of oppia. I even ran git diff between this branch and the main develop branch of Oppia and found the changes in only the 10 files I modified. I have experienced this same issue earlier and think this is some kind of bug in github's method of displaying diff in the PR where it doesn't compare correctly with the current master branch. PTAL and let me know if there are any suggestions regarding this.

@seanlip
Copy link
Member

seanlip commented Jan 5, 2019

Hi @YashJipkate, I think @apb7 is the person you'll need to talk to for both these issues. The pylint-disable statement should not be added; instead, please try to figure out why missing-param-doc is arising erroneously. If it works correctly for other functions but not for yours, then it might actually be a problem with your code. (In general, don't use pylint pragmas and other similar "escape hatches" to get out of understanding an issue.)

For the 140 files changed, I think this is a dev workflow issue and that @apb7 or @nithusha21 might be able to advise. But, generally, if you follow the steps on the PR instructions page, I believe that this shouldn't happen.

Note that @apb7 is currently travelling so you might want to try and take a stab at resolving these on your own first. For the second one it's fine to create a new PR from scratch if that is easier.

@kevinlee12 kevinlee12 assigned YashJipkate and unassigned BenHenning Jan 5, 2019
Params:
app: WSGI application. The WSGI application which receives the
Args:
app: TestApp. The WSGI application which receives the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seanlip Thanks for your advice! Will keep that in mind next time!
Well thanks to you, I figured out the cause, it was caused since I named the type as WSGI Application and pylint was not happy with the space in between the type. So I set the type to TestApp which is the class as is clear from the piece of code here and also from the source code of TestApp
PTAL. Thanks!

@seanlip
Copy link
Member

seanlip commented Jan 6, 2019

@YashJipkate, the PR looks good, but I noticed you force pushed. We generally discourage that because it overwrites history and makes diffs between successive commits harder to review. Instead perhaps reverting the merge commit (or whatever caused all the new files to be added) might have been a better way to go -- though it might be a good idea to try and figure out how you got into this state in the first place, so that we can avoid this happening to other folks in the future.

Otherwise, the PR looks good, except that it fails Travis lint checks. Did these not run locally on your machine before you pushed?

Once the Travis checks are fixed, this is good to merge. Thanks!

@YashJipkate
Copy link
Contributor Author

YashJipkate commented Jan 6, 2019

@seanlip Thanks for the info. I actually used git reset and then force-pushed my repo (as you saw) at a previous time at a different repo when I encountered this issue, and they were fine with it so I went ahead with it here too.
Wasn't aware of the hardship it causes to reviewers.
And the linting check did run on my local since I used the terminal, don't know how it passed there, might be because my local branch is behind oppia/develop. I have pushed again with the fix.
Thanks!

@seanlip
Copy link
Member

seanlip commented Jan 6, 2019

OK, thanks. No worries.

I'm a bit concerned, though, that this issue seems to be recurring repeatedly for you. If it happens in the future can you document exactly what steps you took locally and file a bug against the dev workflow team so that they can look into it?

@YashJipkate
Copy link
Contributor Author

@seanlip Yeah sure I will keep that in mind the next time I encounter this type of issue.
Thanks!

@apb7
Copy link
Contributor

apb7 commented Jan 6, 2019

@YashJipkate, glad that you've figured out the above issues! Also, as Sean suggested, feel free to file an issue if you face any recurring problem. Thanks!

@YashJipkate
Copy link
Contributor Author

@apb7 Sure. Thanks for your help!

@YashJipkate
Copy link
Contributor Author

@seanlip The checks have passed. Please take a final look.
Thanks!

@seanlip
Copy link
Member

seanlip commented Jan 6, 2019

LGTM. Thanks!

@seanlip seanlip merged commit 25da701 into oppia:develop Jan 6, 2019
@YashJipkate YashJipkate deleted the docstrings-backend branch February 11, 2019 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants