Skip to content

Commit

Permalink
Add BuildStep.run_ksconf()
Browse files Browse the repository at this point in the history
- Create new convenience method for ksconf invocation during app builds.
- Update the ksconf splunk app to use this new functionality.
- Make 'python -m ksconf.cli' work (same as '-m ksconf', just without python
  version checking)
- Add more typing hints.
  • Loading branch information
lowell80 committed Oct 5, 2023
1 parent 792e8de commit 106b193
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
12 changes: 12 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ Ksconf 0.12
In many cases, this really isn't a new dependency, since pluggy requires it as well.


Ksconf v0.12.2 (DRAFT)
~~~~~~~~~~~~~~~~~~~~~~~~~~~


**App building with Ksconf**

- Added a convenience method to allow running ksconf commands more easily during the build process.
You can now invoke ksconf using :py:meth:`~ksconf.build.BuildStep.run_ksconf` method which allows direct execution of a ksconf command.
Previously this was accomplished by using :py:meth:`~ksconf.build.BuildStep.run`, using Python interpreter internal path as the executable, launching the ksconf in "module" mode.
So this approach is simpler and in the future it may be invoked internally, removing the need for launching an additional Python process.


Ksconf v0.12.1 (2023-10-03)
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
13 changes: 13 additions & 0 deletions ksconf/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ def run(self, executable, *args, cwd=None):
raise BuildExternalException(f"Exit code of {process.returncode} "
f"while executing {executable}")

def run_ksconf(self, *args, cwd=None):
""" Execute 'ksconf' command in the build folder.
Currently this runs as a separate process, but in the future is may be
optimized to run from within the same python process. This is an
implementation detail the caller shouldn't care about.
:param str args: Additional argument(s) for the ksconf command.
:param str cwd: Optional kw arg to change the working directory. This
defaults to the build folder.
"""
# Historically '-m ksconf' was used, but here safely skip python version check
return self.run(sys.executable, "-m", "ksconf.cli", *args, cwd=cwd)


from ksconf.builder.core import BuildManager # noqa

Expand Down
4 changes: 4 additions & 0 deletions ksconf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,7 @@ def check_py():
sys.exit(EXIT_CODE_ENV_BUSTED)
# Okay, now NEVER call this code again.... (helpful for unit-testing & nested calls)
globals()["check_py"] = lambda: None


if __name__ == "__main__": # pragma: no cover
cli()
37 changes: 19 additions & 18 deletions splunk_app/build.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
REQUIREMENTS = "requirements-app.txt"


def make_wheel(step):
def make_wheel(step: BuildStep):
log = step.get_logger()
step.run(sys.executable, "setup.py", "bdist_wheel",
"-d", str(step.dist_path),
Expand All @@ -52,7 +52,7 @@ def make_wheel(step):
return wheel


def make_docs(step):
def make_docs(step: BuildStep):
log = step.get_logger()

log("Build dynamic doc content")
Expand Down Expand Up @@ -94,7 +94,7 @@ def filter_requirements(step: BuildStep, src: Path, re_block: str, *extras: str)

# XXX: this breaks when cache is enabled. Figured this out, some path handling is busted
# @manager.cache(["requirements.txt"], ["bin/lib/"], timeout=7200)
def python_packages(step):
def python_packages(step: BuildStep):
# Reuse shared function from ksconf.build.steps
pip_install(step, REQUIREMENTS, APP_FOLDER / "bin/lib",
handle_dist_info="rename",
Expand All @@ -103,33 +103,34 @@ def python_packages(step):
dependencies=False) # managing dependencies manually


def package_spl(step):
def package_spl(step: BuildStep):
top_dir = step.dist_path.parent
release_path = top_dir / ".release_path"
release_name = top_dir / ".release_name"
build_no = 0
if "GITHUB_RUN_NUMBER" in os.environ:
build_no = 1000 + int(os.environ["GITHUB_RUN_NUMBER"])
step.run(sys.executable, "-m", "ksconf", "package",
"--file", step.dist_path / SPL_NAME,
"--set-version", "{{git_tag}}",
"--set-build", build_no,
"--blocklist", "fonts", # From build docs
"--blocklist", ".buildinfo", # From build docs
"--blocklist", ".doctrees", # From build docs
"--blocklist", "build.py", # docs; AppInspect triggers manual_check / code review
"--blocklist", REQUIREMENTS,
"--block-local",
"--layer-method=disable",
"--release-file", str(release_path),
APP_FOLDER)
step.run_ksconf(
"package",
"--file", step.dist_path / SPL_NAME,
"--set-version", "{{git_tag}}",
"--set-build", build_no,
"--blocklist", "fonts", # From build docs
"--blocklist", ".buildinfo", # From build docs
"--blocklist", ".doctrees", # From build docs
"--blocklist", "build.py", # docs; AppInspect triggers manual_check / code review
"--blocklist", REQUIREMENTS,
"--block-local",
"--layer-method=disable",
"--release-file", str(release_path),
APP_FOLDER)
# Provide the dist file as a short name too (used by some CI/CD tools)
path = release_path.read_text()
short_name = Path(path).name
release_name.write_text(short_name)


def build(step, args):
def build(step: BuildStep, args):
""" Build process """

# Cleanup build folder
Expand Down

0 comments on commit 106b193

Please sign in to comment.