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

Code sharing between crawl and runspider command #4552

Merged
merged 11 commits into from
Jun 3, 2020

Conversation

jay24rajput
Copy link
Contributor

@jay24rajput jay24rajput commented May 7, 2020

Implemented a new file common_commands for reusing the add_options and process_option command previously used in crawl.py and runspider.py

Fixes #4548

@Gallaecio
Copy link
Member

Instead of creating a new file, what about using commands/__init__.py?

@jay24rajput
Copy link
Contributor Author

jay24rajput commented May 7, 2020

Instead of creating a new file, what about using commands/__init__.py?

There is actually same function i.e add_options and process_options in commands/__init__.py file. And these functions initialize the parser with some common options.

In case we add the code to the __init__.py file, the options will be displayed for each file, which might not be relevant there. Thus, I created a new file so has to avoid the above redundancy.

@codecov
Copy link

codecov bot commented May 7, 2020

Codecov Report

Merging #4552 into master will increase coverage by 0.19%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master    #4552      +/-   ##
==========================================
+ Coverage   84.55%   84.74%   +0.19%     
==========================================
  Files         164      164              
  Lines        9923    10011      +88     
  Branches     1475     1513      +38     
==========================================
+ Hits         8390     8484      +94     
+ Misses       1266     1263       -3     
+ Partials      267      264       -3     
Impacted Files Coverage Δ
scrapy/commands/__init__.py 62.31% <68.75%> (+1.20%) ⬆️
scrapy/commands/crawl.py 35.00% <100.00%> (+6.42%) ⬆️
scrapy/commands/runspider.py 89.13% <100.00%> (+5.52%) ⬆️
scrapy/robotstxt.py 90.19% <0.00%> (-7.34%) ⬇️
scrapy/cmdline.py 68.00% <0.00%> (+0.25%) ⬆️
scrapy/item.py 100.00% <0.00%> (+1.42%) ⬆️
scrapy/shell.py 72.32% <0.00%> (+4.10%) ⬆️
scrapy/spiders/crawl.py 97.24% <0.00%> (+4.77%) ⬆️

@Gallaecio
Copy link
Member

There is actually same function i.e add_options and process_options in commands/__init__.py file. And these functions initialize the parser with some common options.

In case we add the code to the __init__.py file, the options will be displayed for each file, which might not be relevant there. Thus, I created a new file so has to avoid the above redundancy.

I’m not sure what you mean by “the options will be displayed for each file”.

Those two objects are methods of a class, not module-level functions. If you rename your new CommonCommands class to something else (e.g. BaseRunSpiderCommand), you could just move that class to the __init__.py file without any conflict.

@jay24rajput
Copy link
Contributor Author

Alright! I sort of had a confusion. I will move the entire class to __init__.py and will make both the crawl.py and runspider.py call the newly created class.

@jay24rajput
Copy link
Contributor Author

@Gallaecio codecov for the patch is failing. Can you please guide me as to how I can fix it.

Also please let me know if anything else needs to be rectified in the previous commit.

Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

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

Style comments.

scrapy/commands/__init__.py Outdated Show resolved Hide resolved
scrapy/commands/__init__.py Outdated Show resolved Hide resolved
scrapy/commands/__init__.py Outdated Show resolved Hide resolved
scrapy/commands/crawl.py Outdated Show resolved Hide resolved
@Gallaecio
Copy link
Member

Feel free to ignore codecov in this case. You are modifying lines that are not covered by unit tests, so obviously your changes include lines not covered by unit tests, but given how straightforward these changes are, I don’t think we should consider test coverage part of the scope of these changes.

@jay24rajput
Copy link
Contributor Author

@Gallaecio is there anything else that needs to be done here?

Co-authored-by: Adrián Chaves <adrian@chaves.io>
Copy link
Member

@elacuesta elacuesta left a comment

Choose a reason for hiding this comment

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

Many thanks @jay24rajput! I left a suggestion to simplify a docstring, but it's not a blocker.

scrapy/commands/__init__.py Outdated Show resolved Hide resolved
Changed typo in a comment for BaseRunSpiderCommand

Co-authored-by: Eugenio Lacuesta <1731933+elacuesta@users.noreply.github.com>
@jay24rajput
Copy link
Contributor Author

@elacuesta @Gallaecio the checks haven't completed yet! Any solutions?

@noviluni
Copy link
Member

Hi @jay24rajput it is working, the error is not related to the code but to connection errors. However, if you want to relaunch the check you can close and open again this PR.

@wRAR wRAR merged commit 63929e7 into scrapy:master Jun 3, 2020
@Laerte Laerte mentioned this pull request Nov 10, 2022
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.

Increase code sharing between the crawl and runspider commands
5 participants