Merge ~brad-figg/+git/kteam-tools:better-nocards into ~canonical-kernel/+git/kteam-tools:master

Proposed by Brad Figg
Status: Needs review
Proposed branch: ~brad-figg/+git/kteam-tools:better-nocards
Merge into: ~canonical-kernel/+git/kteam-tools:master
Diff against target: 20 lines (+1/-1)
1 file modified
stable/create-kernel-tasks (+1/-1)
Reviewer Review Type Date Requested Status
Cory Todd (community) Needs Fixing
Brad Figg Pending
Review via email: mp+433807@code.launchpad.net

This proposal supersedes a proposal from 2022-11-24.

Description of the change

The commit message says it all

To post a comment you must log in.
Revision history for this message
Cory Todd (corytodd) wrote :

comments inline

review: Needs Fixing
Revision history for this message
Brad Figg (brad-figg) wrote :

Cory,

If you read the commit message you would see an explanation of why I moved the import. I do not have the jira module. I can not access your Jira when I run this command from outside the company. I moved it down inside the check for dryrun and self.board because I have to invoke with --nocards and it won't run if it tries to import the SRUBoard class.

Revision history for this message
Cory Todd (corytodd) wrote :

Brad,

Hello, nice to meet you!

Yes I did read the commit message and it makes sense. I understand these tools have not been thoroughly tested for use outside the Canonical so I appreciate your help in getting things fixed up.

My suggestion included a code snippet that supports your use case and keeps the imports all at the top. The problem is that moving imports inside classes and function calls makes it hard to know when a module is actually available.

Would you mind trying this out for me? In case that snippet got list, here it is again:

try:
    from ktl.sruboard import SRUBoard, SRUBoardError
except ModuleNotFoundError:
    print("WW: sruboard module not found, you will not be able to use Jira integration")
    SRUBoard = None
    SRUBoardError = None

The import will fail, warn the user, then move on safely.

Revision history for this message
Brad Figg (brad-figg) wrote :

If i've specified --no-cards on the command line and I don't have the module I'm going to get that warning/error message anyway. There is nothing wrong with moving the import into the code. It's rarely done but in some cases it makes the most sense to do. Having the imports at the top of the file is a good, general, rule of thumb.

Revision history for this message
Jose Ogando Justo (joseogando) wrote :

Hello Brad,

For this particular MP, we are deciding that the proper way to do it is to include the library within the try sentence.

Although there is nothing technically wrong with moving the import code, this will help us to keep maintainability, I hope you understand.

Please resubmit the MP with the requested changes. In this way we can have both clean code and the functionality required.

Thanks

Unmerged commits

8047edf... by Brad Figg

create-kernel-tasks: if --nocards is specified then don't import the
SRUBoard class.

The SRUBoard class imports the jira module and not all users of
create-kernel-tasks has that module. If no jira cards are to be created
there is no need to import SRUBoard.

Signed-off-by: Brad Figg <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/stable/create-kernel-tasks b/stable/create-kernel-tasks
2index c62b6db..14839ee 100755
3--- a/stable/create-kernel-tasks
4+++ b/stable/create-kernel-tasks
5@@ -13,7 +13,6 @@ sys.path.append(os.path.realpath(
6 from ktl.log import Clog, cerror, cwarn, cinfo, cdebug
7 from ktl.kernel_series import KernelSeries
8 from ktl.tracking_bug2 import TrackingBugs, TrackingBugError
9-from ktl.sruboard import SRUBoard, SRUBoardError
10
11 class Task():
12 def __init__(self, taskset, ks_source, ks_snap=None):
13@@ -436,6 +435,7 @@ class TaskSet():
14 def CreateCards(self, boardname, dryrun=False, cve=False):
15 if dryrun is False and self.board is None:
16 try:
17+ from ktl.sruboard import SRUBoard, SRUBoardError
18 self.board = SRUBoard(self.cycletag, cve=cve)
19 except SRUBoardError as e:
20 cerror(e)

Subscribers

People subscribed via source and target branches