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

feat(all): Add global parameters #4

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions kci-dev/kci-dev.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Copy link
Member

@aliceinwire aliceinwire Sep 10, 2024

Choose a reason for hiding this comment

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

python2 as been deprecated years ago
python2 shebang is "#!/usr/bin/env python2"

python is usually just a symlink to your distribution python version
your distribution should be able to decide the correct python version for you

Copy link
Member Author

Choose a reason for hiding this comment

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

According to PEP 394, For Python script publishers:

"Older Linux distributions will provide a python command that refers to Python 2, and will likely not provide a python2 command."
"Some Linux distributions will not provide a python command at all by default, but will provide a python3 command by default."

In my case (Debian bookworm) python is not provided at all (unless i install python-is-python3), so it is preferable to point to python3 which is supposed to work for all.

Copy link
Member

@aliceinwire aliceinwire Sep 11, 2024

Choose a reason for hiding this comment

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

we should change all the python file not just this one file

Copy link
Member Author

Choose a reason for hiding this comment

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

we should change all the python file not just this one file

Good point, will change all.


import click
from libs.common import *
from subcommands import commit, patch


@click.group(
help="Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel changes on a enabled KernelCI server"
)
@click.version_option("0.0.1", prog_name="kci-dev")
def cli():
@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file")
@click.pass_context
def cli(ctx, settings):
ctx.obj = {"CFG": load_toml(settings)}
pass


Expand Down
Empty file added kci-dev/libs/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions kci-dev/libs/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import toml


def load_toml(settings):
with open(settings) as fp:
config = toml.load(fp)
return config
14 changes: 4 additions & 10 deletions kci-dev/subcommands/commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
Expand Down Expand Up @@ -41,12 +41,6 @@ def send_build(url, patch, branch, treeurl, token):
click.secho(response.json(), fg="green")


def load_toml(settings):
with open(settings) as fp:
config = toml.load(fp)
return config


@click.command(help="Test commits from a local Kernel repository")
@click.option(
"--repository",
Expand All @@ -65,9 +59,9 @@ def load_toml(settings):
default=".",
help="define the directory of the local tree with local changes",
)
@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file")
def commit(repository, branch, private, path, settings):
config = load_toml(settings)
@click.pass_context
def commit(ctx, repository, branch, private, path):
config = ctx.obj.get("CFG")
url = api_connection(config["connection"]["host"])
diff = find_diff(path, branch, repository)
send_build(url, diff, branch, repository, config["connection"]["token"])
Expand Down
14 changes: 4 additions & 10 deletions kci-dev/subcommands/patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
Expand Down Expand Up @@ -31,12 +31,6 @@ def send_build(url, patch, branch, treeurl, token):
click.secho(response.json(), fg="green")


def load_toml(settings):
with open(settings) as fp:
config = toml.load(fp)
return config


@click.command(help="Test a patch or a mbox file")
@click.option(
"--repository",
Expand All @@ -51,9 +45,9 @@ def load_toml(settings):
help="define if the test results will be published",
)
@click.option("--patch", required=True, help="mbox or patch file path")
@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file")
def patch(repository, branch, private, patch, settings):
config = load_toml(settings)
@click.pass_context
def patch(ctx, repository, branch, private, patch):
config = ctx.obj.get("CFG")
url = api_connection(config["connection"]["host"])
patch = open(patch, "rb")
send_build(url, patch, branch, repository, config["connection"]["token"])
Expand Down
Loading