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: deprecate .uccignore and upgrade additional_package #1415

Merged
merged 25 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a38e532
feat(.uccignore): add functionality in additional_packaging.py to cle…
hetangmodi-crest Oct 29, 2024
0b6d1c5
chore: uncomment the code of .uccignore
hetangmodi-crest Oct 30, 2024
59071ef
test(smoke): update smoke tests
hetangmodi-crest Oct 30, 2024
df1cbed
doc: update doc of additional_packaging.py with example
hetangmodi-crest Oct 30, 2024
60d7e3d
chore: fix lint failures
hetangmodi-crest Oct 30, 2024
63407dc
Merge branch 'develop' into fix/update-uccignore-impl
hetangmodi-crest Oct 30, 2024
0729239
fix: generate basic authentication fields for OpenAPI integration (#1…
hetangmodi-crest Oct 30, 2024
9a0238c
feat: print warning when entity does not have validators (#1409)
kkedziak-splunk Oct 30, 2024
9f0eeca
feat: require splunktaucclib 6.4.0 during the build phase (#1412)
sgoral-splunk Oct 30, 2024
2dc75a8
docs: fix warning panels (#1418)
kkedziak-splunk Oct 30, 2024
6970f33
chore(release): 5.52.0
srv-rr-github-token Oct 30, 2024
36ad940
chore: single select with default empty string value (#1416)
soleksy-splunk Oct 31, 2024
926d086
refactor: add types for Splunk modules (#1422)
vtsvetkov-splunk Oct 31, 2024
7af8746
test(ui): check actual request for oauth (#1419)
vtsvetkov-splunk Oct 31, 2024
f4b8fda
refactor(types): allow to parse unknown errors (#1423)
vtsvetkov-splunk Oct 31, 2024
44c77ed
chore: merge branch 'develop' into fix/update-uccignore-impl
hetangmodi-crest Nov 1, 2024
7dc4935
test(unit): add unit tests for coverage
hetangmodi-crest Nov 1, 2024
8cc7b0c
docs: update typo of file in docs
hetangmodi-crest Nov 4, 2024
2e1fff5
Merge branch 'develop' into fix/update-uccignore-impl
hetangmodi-crest Nov 7, 2024
9e44b08
docs: updated .uccignore docs
hetangmodi-crest Nov 7, 2024
2c270a1
fix: removed raise while importing additional_packaging.py
hetangmodi-crest Nov 12, 2024
c9019f7
docs: added a warning message for deprecation
hetangmodi-crest Nov 12, 2024
d58209e
tests: removed additional_packaging function
hetangmodi-crest Nov 12, 2024
fa390af
chore: removed unit test cases for enable action
hetangmodi-crest Nov 13, 2024
3ef04a2
Merge branch 'develop' into fix/update-uccignore-impl
hetangmodi-crest Nov 13, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pip-wheel-metadata/UNKNOWN.dist-info/top_level.txt
pip-wheel-metadata/UNKNOWN.dist-info/METADATA
.vscode/settings.json
.DS_Store
.venv
.venv*
output
# The following files should never be checked into git but can not be in the
# ignore file due to poetry issues
Expand Down
19 changes: 16 additions & 3 deletions docs/additional_packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

To extend the build process, you can create a `additional_packaging.py` file in the same file level where you have your globalConfig file.

This file should have the `additional_packaging` function, which accepts add-on name as its only argument.
This file should at least have:

- the `cleanup_output_files` function, which accepts `output_path` (str), `add-on name` (str) as its arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

For the users it might be a little bit confusing what is the output_path here. When user decides to change output directory during the build process he would need to change it also in the additional_packaging. I wonder if we can make it more generic since we already have this parameter during the build process _get_build_output_path.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it may be a bit confusing. What do you guys think about leaving only additional_packaging method and passing other arguments (like output_path), through e.g. env variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The additional_packaging function is inclined towards adding something in the final package at output/ dir. This cleanup_output_files if inclined towards cleaning up of files. I have used output_path as variable name as in ucc-gen command, we are asking for --output flag to define the output path of the add-on that is built. We can change this variable name, or I can update the example that we show to capture its meaning.

We are passing the output_path that we get from _get_build_output_path() function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand. My only concern is that when the user runs the command for example:
ucc-gen build --output a/b/c
he must also change the output_path to a/b/c in additional packaging and if he later run:
ucc-gen build --output x/y/z he must remember to change it again the additioanl packaging to x/y/z

Copy link
Contributor Author

@hetangmodi-crest hetangmodi-crest Nov 13, 2024

Choose a reason for hiding this comment

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

Understood. I have addressed this concern in PR #1455.

- the `additional_packaging` function, which accepts `add-on name` (str) as its only argument.

First the `cleanup_output_files` function would be called from `ucc-gen` build process and then `additional_packaging` function.

See the following example for proper usage:

* Build custom UI after `ucc-gen` finishes all its necessary steps.
* Use a workaround for a `ucc-gen` feature that has not been implemented.
- Build custom UI after `ucc-gen` finishes all its necessary steps.
- Use a workaround for a `ucc-gen` feature that has not been implemented.

## Example

Below is an example of additional_packaging.py containing both the implementations of functions.

```python
--8<-- "tests/testdata/test_addons/package_global_config_everything_uccignore/additional_packaging.py"
```
3 changes: 3 additions & 0 deletions docs/uccignore.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# `.uccignore` file

!!! warning "Deprecation Notice"
This feature has been deprecated from UCC framework as of v5.53.0 as the feature is ambiguous. You can achieve the same functionality using [additional_packaging.py](./additional_packaging.md). The `cleanup_output_files` provides a feature to clean up files after the source code has been copied.

This feature can be used to remove files from the output **after** the UCC template files were copied and **before** the source of the
add-on recursively overrides the output folder.

Expand Down
22 changes: 18 additions & 4 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def _get_ignore_list(
if not os.path.exists(ucc_ignore_path):
return []
else:
logger.warning(
"The `.uccignore` feature has been deprecated from UCC and is planned to be removed after May 2025. "
"To achieve the similar functionality use additional_packaging.py."
"\nRefer: https://splunk.github.io/addonfactory-ucc-generator/additional_packaging/."
)
with open(ucc_ignore_path) as ignore_file:
ignore_list = ignore_file.readlines()
ignore_list = [
Expand Down Expand Up @@ -629,15 +634,24 @@ def generate(
os.path.abspath(os.path.join(source, os.pardir, "additional_packaging.py"))
):
sys.path.insert(0, os.path.abspath(os.path.join(source, os.pardir)))
try:
from additional_packaging import cleanup_output_files

cleanup_output_files(output_directory, ta_name)
except ImportError:
logger.info(
"additional_packaging.py is present but does not have `cleanup_output_files`. Skipping clean-up."
hetangmodi-crest marked this conversation as resolved.
Show resolved Hide resolved
)

try:
from additional_packaging import additional_packaging

additional_packaging(ta_name)
except ImportError as e:
logger.exception(
"additional_packaging.py is present but not importable.", e
except ImportError:
logger.info(
"additional_packaging.py is present but does not have `additional_packaging`. "
"Skipping additional packaging."
)
raise e

if global_config:
logger.info("Generating OpenAPI file")
Expand Down
57 changes: 55 additions & 2 deletions tests/smoke/test_ucc_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ def summarize_types(raw_expected_logs):

def test_ucc_generate_with_everything_uccignore(caplog):
"""
Checks the functioning of .uccignore present in a repo.
Compare only the files that shouldn't be present in the output directory.
Checks the deprecation warning of .uccignore present in a repo with
its functionality still working.
"""
with tempfile.TemporaryDirectory() as temp_dir:
package_folder = path.join(
Expand All @@ -476,6 +476,16 @@ def test_ucc_generate_with_everything_uccignore(caplog):
"package_global_config_everything_uccignore",
"package",
)
# create `.uccignore` temporarily
ucc_file = path.join(path.dirname(package_folder), ".uccignore")
f = open(ucc_file, "w+")
f.write(
"""**/**one.py
bin/splunk_ta_uccexample_rh_example_input_two.py
bin/wrong_pattern
"""
)
f.close()
build.generate(source=package_folder, output_directory=temp_dir)

expected_warning_msg = (
Expand All @@ -492,9 +502,22 @@ def test_ucc_generate_with_everything_uccignore(caplog):
removed = set(
caplog.text.split("Removed:", 1)[1].split("INFO")[0].strip().split("\n")
)
exp_msg = (
"The `.uccignore` feature has been deprecated from UCC and is planned to be removed after May 2025. "
"To achieve the similar functionality use additional_packaging.py."
"\nRefer: https://splunk.github.io/addonfactory-ucc-generator/additional_packaging/."
)
exp_info_msg = (
"additional_packaging.py is present but does not have `additional_packaging`."
" Skipping additional packaging."
)

assert exp_msg in caplog.text
assert exp_info_msg in caplog.text
assert expected_warning_msg in caplog.text
assert edm_paths == removed
# on successful assertion, we delete the file
os.remove(ucc_file)

actual_folder = path.join(temp_dir, "Splunk_TA_UCCExample")
# when custom files are provided, default files shouldn't be shipped
Expand All @@ -508,6 +531,36 @@ def test_ucc_generate_with_everything_uccignore(caplog):
assert not path.exists(actual_file_path)


def test_ucc_generate_with_everything_cleanup_output_files():
"""
Checks the functioning of addtional_packaging.py's `cleanup_output_files` present in a repo.
Compares only the files that shouldn't be present in the output directory.
"""
with tempfile.TemporaryDirectory() as temp_dir:
package_folder = path.join(
path.dirname(path.realpath(__file__)),
"..",
"testdata",
"test_addons",
"package_global_config_everything_uccignore",
"package",
)
build.generate(source=package_folder, output_directory=temp_dir)

actual_folder = path.join(temp_dir, "Splunk_TA_UCCExample")
# when custom files are provided, default files shouldn't be shipped
files_should_be_absent = [
("bin", "example_input_one.py"),
("bin", "splunk_ta_uccexample_rh_example_input_one.py"),
("bin", "splunk_ta_uccexample_rh_example_input_two.py"),
("default", "redundant.conf"),
("default", "nav", "views", "file_copied_from_source_code.xml"),
]
for af in files_should_be_absent:
actual_file_path = path.join(actual_folder, *af)
assert not path.exists(actual_file_path)


def test_ucc_generate_only_one_tab():
package_folder = path.join(
path.dirname(path.realpath(__file__)),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

from os.path import sep, exists, dirname, realpath, join
from os import remove, system, _exit, WEXITSTATUS

def cleanup_output_files(output_path: str, ta_name: str) -> None:
"""
prepare a list for the files to be deleted after the source code has been copied to output directory
"""
files_to_delete = []
files_to_delete.append(sep.join([output_path, ta_name, "default", "redundant.conf"]))
files_to_delete.append(sep.join([output_path, ta_name, "bin", "splunk_ta_uccexample_rh_example_input_two.py"]))
files_to_delete.append(sep.join([output_path, ta_name, "bin", "example_input_one.py"]))
files_to_delete.append(sep.join([output_path, ta_name, "bin", "splunk_ta_uccexample_rh_example_input_one.py"]))
files_to_delete.append(sep.join([output_path, ta_name, "bin", "file_does_not_exist.py"]))
files_to_delete.append(sep.join([output_path, ta_name, "default", "nav", "views", "file_copied_from_source_code.xml"]))

for delete_file in files_to_delete:
try:
remove(delete_file)
except (FileNotFoundError):
# simply pass if the file doesn't exist
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<note>
<to>World</to>
<from>Python</from>
<heading>Hello</heading>
<body>Hello World!</body>
</note>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[redundant]
key = value
content_type = json
parser = json
Loading