Skip to content

Refactor BaseEnvironment #3687

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
wants to merge 15 commits into from

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 27, 2018

This will close #3643
Also related to #3665

@stsewd
Copy link
Member Author

stsewd commented Feb 27, 2018

I have removed the record dependency from BaseEnvironment and BuildCommand, but still there is code repetition, I will continue refactoring it later. For now, all tests pass :)

kwargs['warn_only'] = True
return super(LocalEnvironment, self).run(*cmd, **kwargs)

# record, force_success, warn_only
Copy link
Member Author

@stsewd stsewd Feb 27, 2018

Choose a reason for hiding this comment

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

I see that there is some magic with the parameters on the run_command_class (change according to other parameters). So I was thinking to use different parameters: record, force_success, warn_only that are independent from each other and play nice together.

@stsewd stsewd force-pushed the refactor-base-environment branch from f6aaab3 to 443b0e0 Compare March 2, 2018 06:08
@stsewd
Copy link
Member Author

stsewd commented Mar 2, 2018

What I done so far:

  • Remove record dependency from BuildCommand and BaseEnvironment
  • Use pre_run_command and post_run_command to extend the behavior of the run method.
  • Use a mixin to add the record command behavior.
  • Previous run accepted record=True, record_as_success=False and warn_only=False. This variables had a dependence between each other. What I propose is to use only record=True and warn_only=False.

What is missing:

  • Change method calls to new vars (record=True and warn_only=False).
  • See a way to remove build_env from pre_run_command
  • Maybe update/add tests.

@RichardLitt RichardLitt added the PR: work in progress Pull request is not ready for full review label Mar 2, 2018
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! The code looks good. Althouhg, I think it needs more work on the logic/usage of the record, record_as_success and friends.

The builders are complex, so we will want to merge #3764 first to cover some scenarios.

Also, we will need to do some manual QA to be sure that this code is working and the builders are building the documentation properly. This code is escential for the build process, it's complex to see the errors, and it's tricky to test (we had many problems each time we touch it :) ) --so, I'd like to be more careful this time.

:param warn_only: don't raise an exception on command failure
:param record_as_success: force command ``exit_code`` to be saved as
Copy link
Member

Choose a reason for hiding this comment

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

We are lossing the documentation for these attributes here. It should be added where it fit.

@@ -348,12 +328,7 @@ def run_command_class(
build_cmd = cls(cmd, **kwargs)
self.commands.append(build_cmd)
build_cmd.run()
Copy link
Member

Choose a reason for hiding this comment

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

self.pre_run_command shuold be before this line and should receive only the build_cmd, warn_only and **kwargs

'build_env': self,
})
self.record = kwargs.pop('record', True)
self.record_as_success = warn_only
Copy link
Member

Choose a reason for hiding this comment

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

record_as_success and warn_only are not the same.

(take a look at my previous comment where the logic to calculate these is defined)

if not record:
warn_only = True

if record_as_success:
Copy link
Member

Choose a reason for hiding this comment

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

We do need this logic to calculate these values to decide later if we want to record or just warn or both.

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 know, that's because I want to eliminate those parameters and just use record and warn_only #3687 (comment)

@stsewd
Copy link
Member Author

stsewd commented Mar 28, 2018

I just update this PR to the current master, but I want to wait until #3842 is fixed to continue, and also to this tests #3764.

@humitos humitos added this to the Refactoring milestone Dec 3, 2018
@humitos
Copy link
Member

humitos commented Dec 3, 2018

@stsewd issues mentioned "as blocking" this PR are already closed/merged.

Do you want to continue with this PR? I think it was close enough to be merged.

@codecov
Copy link

codecov bot commented Dec 6, 2018

Codecov Report

Merging #3687 into master will decrease coverage by 2.06%.
The diff coverage is 70%.

@@            Coverage Diff             @@
##           master    #3687      +/-   ##
==========================================
- Coverage    76.8%   74.74%   -2.07%     
==========================================
  Files         158      158              
  Lines        9937     9933       -4     
  Branches     1241     1239       -2     
==========================================
- Hits         7632     7424     -208     
- Misses       1973     2177     +204     
  Partials      332      332
Impacted Files Coverage Δ
readthedocs/doc_builder/environments.py 80.38% <70%> (-6.69%) ⬇️
readthedocs/vcs_support/backends/git.py 46.2% <0%> (-36.08%) ⬇️
readthedocs/core/symlink.py 78.65% <0%> (-15.86%) ⬇️
readthedocs/builds/forms.py 83.33% <0%> (-12.5%) ⬇️
readthedocs/doc_builder/backends/sphinx.py 57.42% <0%> (-12.38%) ⬇️
readthedocs/vcs_support/backends/hg.py 53.22% <0%> (-11.3%) ⬇️
readthedocs/vcs_support/base.py 83.01% <0%> (-7.55%) ⬇️
readthedocs/projects/tasks.py 64.2% <0%> (-7%) ⬇️
readthedocs/doc_builder/backends/mkdocs.py 83.16% <0%> (-6.94%) ⬇️
readthedocs/projects/validators.py 75.38% <0%> (-3.08%) ⬇️
... and 6 more

1 similar comment
@codecov
Copy link

codecov bot commented Dec 6, 2018

Codecov Report

Merging #3687 into master will decrease coverage by 2.06%.
The diff coverage is 70%.

@@            Coverage Diff             @@
##           master    #3687      +/-   ##
==========================================
- Coverage    76.8%   74.74%   -2.07%     
==========================================
  Files         158      158              
  Lines        9937     9933       -4     
  Branches     1241     1239       -2     
==========================================
- Hits         7632     7424     -208     
- Misses       1973     2177     +204     
  Partials      332      332
Impacted Files Coverage Δ
readthedocs/doc_builder/environments.py 80.38% <70%> (-6.69%) ⬇️
readthedocs/vcs_support/backends/git.py 46.2% <0%> (-36.08%) ⬇️
readthedocs/core/symlink.py 78.65% <0%> (-15.86%) ⬇️
readthedocs/builds/forms.py 83.33% <0%> (-12.5%) ⬇️
readthedocs/doc_builder/backends/sphinx.py 57.42% <0%> (-12.38%) ⬇️
readthedocs/vcs_support/backends/hg.py 53.22% <0%> (-11.3%) ⬇️
readthedocs/vcs_support/base.py 83.01% <0%> (-7.55%) ⬇️
readthedocs/projects/tasks.py 64.2% <0%> (-7%) ⬇️
readthedocs/doc_builder/backends/mkdocs.py 83.16% <0%> (-6.94%) ⬇️
readthedocs/projects/validators.py 75.38% <0%> (-3.08%) ⬇️
... and 6 more

@stsewd
Copy link
Member Author

stsewd commented Dec 6, 2018

@humitos turns out I forgot everything about the current state of this PR 😢 but I have read all the related code again, and there is a part blocking this. We were relying on the record param to change the value of warn_only and friends, but now BaseEnvironment shouldn't have any idea about record, so we need to remove that magical dependency and not change any other parameters based on record. I was doing that here but looks like it's big, so I'm going to do another PR.

@stsewd
Copy link
Member Author

stsewd commented Dec 7, 2018

Ok, I think I got it, after reading #3520, but I'm not sure. We are lying to the users when saving the result to something else. But I understand that would make the build to appear like a failure... But, if the command failed, then something isn't right. Also, we are just using that to execute some commands in the VCS, actually we don't use record_as_success on git anymore.

@stsewd
Copy link
Member Author

stsewd commented Dec 7, 2018

I was checking, we still need that for svn and bzr :/, I guess I'll continue here

@stale
Copy link

stale bot commented Jan 21, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Jan 21, 2019
@stale stale bot closed this Jan 28, 2019
@stsewd stsewd deleted the refactor-base-environment branch April 11, 2019 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: work in progress Pull request is not ready for full review Status: stale Issue will be considered inactive soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove record dependency from BaseEnvironment
3 participants