Skip to content

Conversation

Eunoia1729
Copy link
Contributor

Refs #24783

@Eunoia1729 Eunoia1729 changed the title linnt: convert submodule linter test to Python lint: convert submodule linter test to Python Apr 7, 2022
@Eunoia1729 Eunoia1729 force-pushed the lint-submodule-py branch 2 times, most recently from 9d6d07e to 1b324cf Compare April 7, 2022 21:25
@DrahtBot DrahtBot added the Tests label Apr 7, 2022
try:
submodules_list = subprocess.check_output(submodule_check_args, stderr = subprocess.STDOUT)
except subprocess.CalledProcessError:
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think python already returns an exit code of 1 when it raises an exception

Copy link
Member

Choose a reason for hiding this comment

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

I do think it's neater not to have a Python exception in the output, especially if the subprocess already prints its own self-evident errors.

Copy link
Member

Choose a reason for hiding this comment

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

This should never happen, and when it happens, the process won't print it's own errors, so the exception seems better?

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure that git prints its own error when it fails. But ok, no strong opinion here.

Copy link
Member

Choose a reason for hiding this comment

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

check_output will eat the output. With stderr = subprocess.STDOUT it will also eat the error.

Copy link
Member

Choose a reason for hiding this comment

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

I hadn't noticed the stderr = subprocess.STDOUT. Pretty sure we don't need it. The original script doesn't redirect the stderr either.

Copy link
Contributor Author

@Eunoia1729 Eunoia1729 Apr 13, 2022

Choose a reason for hiding this comment

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

Thank you @laanwj , @KevinMusgrave and @MarcoFalke for your review and points which led me to dig further.

I second @MarcoFalke .
From my understanding, 2 cases are:

  1. Without stderr = subprocess.STDOUT, the error is printed onto the console and is not piped to Python.
  2. With stderr = subprocess.STDOUT, if we want to access the error message, we can access it using e.output in the exception block (where e is CalledProcessError object). Without explicit printing, error is not printed onto console.

I'll update the PR to print errors to keep the behaviour consistent with older version. Additionally, I don't see any cases where this command will return exit code = 1. Should I remove try exception block ?

Kindly let me know your views too.

Edit: I removed try exception block.

@KevinMusgrave
Copy link
Contributor

Concept/approach ACK

@laanwj laanwj mentioned this pull request Apr 8, 2022
25 tasks
@Eunoia1729
Copy link
Contributor Author

Before change:
Screenshot from 2022-04-14 00-40-38

After change:
Screenshot from 2022-04-14 00-39-54

@KevinMusgrave
Copy link
Contributor

Tested ACK 3289688

@Eunoia1729 Eunoia1729 requested a review from laanwj April 13, 2022 21:34
return subprocess.check_output(command).decode('utf-8').splitlines()

def main():
submodules_list = get_submodules_list()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
submodules_list = get_submodules_list()
submodules_list = subprocess.check_output(

no need for a function, you can call the stdlib directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done !

submodules_list = get_submodules_list()
if submodules_list:
print("These submodules were found, delete them:")
for submodule in submodules_list:
Copy link
Member

Choose a reason for hiding this comment

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

what is the point of first splitting by newline and then joining the array by newline again when printing? Just leave it as string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, that was unnecessary. Updated the PR. Thanks for pointing it out !

@laanwj
Copy link
Member

laanwj commented Apr 21, 2022

Tested ACK 4a9e36d

$ git submodule add https://github.com/bitcoin-core/HWI.git  HWI
$ test/lint/lint-submodule.py
These submodules were found, delete them:
  2c757c8306be929714760ddba01d8ab6b0457d99 HWI (2.1.0-rc.1-4-g2c757c8306be929714760ddba01d8ab6b0457d99)

@laanwj laanwj merged commit 2513499 into bitcoin:master Apr 21, 2022
@Eunoia1729 Eunoia1729 deleted the lint-submodule-py branch April 21, 2022 15:46
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 22, 2022
4a9e36d lint: convert submodule linter test to Python (Eunoia)

Pull request description:

  Refs bitcoin#24783

ACKs for top commit:
  laanwj:
    Tested ACK 4a9e36d

Tree-SHA512: ca25b59acf75cebc79588a6c51dc5c313c8d0bd1d492127815d7b81b36aaffd02815a515d97b355582002f71efc33d46435d0b28fce24497bb99799d9ba57228
@bitcoin bitcoin locked and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants