diff --git a/.gitignore b/.gitignore index f48183a..de0ca3b 100644 --- a/.gitignore +++ b/.gitignore @@ -130,6 +130,3 @@ dmypy.json # ruff .ruff_cache/ - -# Generated by setuptools-scm -zuullint/_version.py diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 44ba7af..45e6a03 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,9 +1,9 @@ --- -- id: zuullint +- id: zuulcilint name: Zuul Job Linter description: Verifies if Zuul CI jobs files have valid syntax. language: python files: '^(zuul.d/|.?zuul).*\.yaml$' pass_filenames: true verbose: true - entry: zuullint + entry: zuulcilint diff --git a/README.md b/README.md index d70df5f..858dd35 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -# zuullint +# zuulcilint ## Validate from the command line ``` -pip install zuullint +pip install zuulcilint -usage: zuullint [-h] [--version] [--check-playbook-paths] [--schema SCHEMA] file [file ...] +usage: zuulcilint [-h] [--version] [--check-playbook-paths] [--schema SCHEMA] file [file ...] positional arguments: file file(s) or paths to lint @@ -28,10 +28,10 @@ options: Add the code below to your `.pre-commit-config.yaml` file: ```yaml - - repo: https://github.com/codesquadnest/zuullint.git + - repo: https://github.com/codesquadnest/zuulcilint.git rev: "1.0" hooks: - - id: zuullint + - id: zuulcilint ``` @@ -47,7 +47,7 @@ validation by adding the following to `settings.json`: ```json "yaml.schemas": { - "https://raw.githubusercontent.com/codesquadnest/zuullint/master/zuullint/zuul-schema.json": ["*zuul.d/*.yaml", "*/.zuul.yaml"] + "https://raw.githubusercontent.com/codesquadnest/zuulcilint/master/zuulcilint/zuul-schema.json": ["*zuul.d/*.yaml", "*/.zuul.yaml"] }, "yaml.customTags": [ "!encrypted/pkcs1-oaep array" diff --git a/pyproject.toml b/pyproject.toml index 4d58699..b9f3bf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,17 @@ [tool.poetry] -name = "zuullint" +name = "zuulcilint" version = "0.2.1" description = "Zuul CI linter" authors = ["Pedro Baptista "] license = "MIT" readme = "README.md" keywords = ["zuul", "ci", "linter"] -include = ["pyproject.toml", "LICENSE", "README.md", "zuullint/zuul-schema.yaml"] +include = ["pyproject.toml", "LICENSE", "README.md", "zuulcilint/zuul-schema.yaml"] exclude = ["tests/*"] -packages = [{include = "zuullint"}] +packages = [{include = "zuulcilint"}] [tool.poetry.scripts] -zuullint = "zuullint.__main__:main" +zuulcilint = "zuulcilint.__main__:main" [tool.poetry.dependencies] python = "^3.8, <4.0" @@ -52,7 +52,7 @@ extend-ignore = "E203,E501" # Configurations for pytest [tool.pytest] -addopts = ["-ra", "--cov=zuullint", "--cov-report=term-missing"] +addopts = ["-ra", "--cov=zuulcilint", "--cov-report=term-missing"] testpaths = ["tests"] [toolpytest.cov] @@ -97,13 +97,13 @@ legacy_tox_ini = """ poetry commands = poetry install -v - poetry run pytest --cov=zuullint --cov-report=term-missing + poetry run pytest --cov=zuulcilint --cov-report=term-missing [testenv:lint] deps = ruff commands = - ruff zuullint tests + ruff zuulcilint tests [testenv:pre-commit] skip_install = true diff --git a/tests/test_checker.py b/tests/test_checker.py index 106dea7..6247463 100644 --- a/tests/test_checker.py +++ b/tests/test_checker.py @@ -7,8 +7,8 @@ import pathlib import tempfile -import zuullint.checker as zuullint_checker -import zuullint.utils as zuullint_utils +import zuulcilint.checker as zuulcilint_checker +import zuulcilint.utils as zuulcilint_utils def setup_zuul_job_yaml(): @@ -35,9 +35,9 @@ def setup_zuul_job_yaml(): def test_check_job_playbook_paths(): """Test that check_job_playbook_paths() returns a list of invalid paths.""" tmp_path = setup_zuul_job_yaml() - jobs = zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") + jobs = zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") - assert zuullint_checker.check_job_playbook_paths(jobs[0].get("job")) == [ + assert zuulcilint_checker.check_job_playbook_paths(jobs[0].get("job")) == [ "playbooks/pre-run.yaml", "playbooks/run.yaml", "playbooks/post-run.yaml", diff --git a/tests/test_utils.py b/tests/test_utils.py index 0ec5494..e66e018 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,7 +7,7 @@ import pytest -import zuullint.utils as zuullint_utils +import zuulcilint.utils as zuulcilint_utils def setup_tmp_list_of_files(): @@ -50,7 +50,7 @@ def test_get_schema_valid(): tmp_schema = pathlib.Path(tempfile.mkstemp()[1]) with pathlib.Path.open(tmp_schema, "w", encoding="utf-8") as f: f.write("{}") - assert zuullint_utils.get_zuul_schema(tmp_schema) == {} + assert zuulcilint_utils.get_zuul_schema(tmp_schema) == {} def test_get_schema_file_not_found(): @@ -58,7 +58,7 @@ def test_get_schema_file_not_found(): tmp_schema = pathlib.Path(tempfile.mkstemp()[1]) tmp_schema.unlink() try: - zuullint_utils.get_zuul_schema(tmp_schema) + zuulcilint_utils.get_zuul_schema(tmp_schema) except SystemExit: pytest.raises(FileNotFoundError) @@ -69,7 +69,7 @@ def test_get_schema_invalid_json(): with pathlib.Path.open(tmp_schema, "w", encoding="utf-8") as f: f.write("{- foo = bar}") with pytest.raises(SystemExit): - zuullint_utils.get_zuul_schema(tmp_schema) + zuulcilint_utils.get_zuul_schema(tmp_schema) def test_get_zuul_yaml_files_find(): @@ -77,7 +77,7 @@ def test_get_zuul_yaml_files_find(): tmp_path = setup_tmp_list_of_files() default_len = 2 zuul_yaml_files = [ - file.name for file in zuullint_utils.get_zuul_yaml_files(tmp_path) + file.name for file in zuulcilint_utils.get_zuul_yaml_files(tmp_path) ] assert len(zuul_yaml_files) == default_len assert "file0.yaml" in zuul_yaml_files @@ -85,9 +85,9 @@ def test_get_zuul_yaml_files_find(): tmp_path = tmp_path / "subdir" tmp_path.mkdir() - assert len(zuullint_utils.get_zuul_yaml_files(tmp_path)) == 0 + assert len(zuulcilint_utils.get_zuul_yaml_files(tmp_path)) == 0 - assert len(zuullint_utils.get_zuul_yaml_files(tmp_path / "invalid_path")) == 0 + assert len(zuulcilint_utils.get_zuul_yaml_files(tmp_path / "invalid_path")) == 0 def test_get_zuul_yaml_files_skip(): @@ -98,18 +98,18 @@ def test_get_zuul_yaml_files_skip(): tmp_path = tmp_path / "file2.yaml" with pathlib.Path.open(tmp_path, "w", encoding="utf-8") as f: f.write("hello") - assert len(zuullint_utils.get_zuul_yaml_files(tmp_path)) == 1 + assert len(zuulcilint_utils.get_zuul_yaml_files(tmp_path)) == 1 tmp_path = tmp_path.parent / "file3.yml" with pathlib.Path.open(tmp_path, "w", encoding="utf-8") as f: f.write("hello") - assert len(zuullint_utils.get_zuul_yaml_files(tmp_path)) == 0 + assert len(zuulcilint_utils.get_zuul_yaml_files(tmp_path)) == 0 def test_get_jobs_from_zuul_yaml(): """Test that get_jobs_from_zuul_yaml() returns a list of jobs.""" tmp_path = setup_zuul_job_yaml() - jobs = zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") + jobs = zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") assert len(jobs) == 1 assert jobs[0]["job"]["name"] == "test-job" @@ -120,7 +120,7 @@ def test_get_jobs_from_zuul_yaml_invalid_yaml(): with pathlib.Path.open(tmp_path / "job.yaml", "w", encoding="utf-8") as f: f.write("{- foo = bar}") with pytest.raises(SystemExit): - zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") + zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") def test_get_jobs_from_zuul_yaml_no_jobs(): @@ -133,14 +133,14 @@ def test_get_jobs_from_zuul_yaml_no_jobs(): name: test-pipeline """, ) - assert len(zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml")) == 0 + assert len(zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml")) == 0 def test_get_jobs_from_zuul_yaml_no_file(): """Test return an empty list when no file is found.""" tmp_path = setup_zuul_job_yaml() try: - zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "invalid_file") + zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "invalid_file") except SystemExit: pytest.raises(FileNotFoundError) @@ -148,8 +148,8 @@ def test_get_jobs_from_zuul_yaml_no_file(): def test_get_playbook_paths_from_job(): """Test that get_playbook_paths_from_job() returns a list of playbook paths.""" tmp_path = setup_zuul_job_yaml() - jobs = zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") - playbook_paths = zuullint_utils.get_playbook_paths_from_job(jobs[0].get("job")) + jobs = zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") + playbook_paths = zuulcilint_utils.get_playbook_paths_from_job(jobs[0].get("job")) size = 3 assert len(playbook_paths) == size assert playbook_paths[0] == "playbooks/pre-run.yaml" @@ -167,14 +167,14 @@ def test_get_playbook_paths_from_job_no_playbook_paths(): name: test-job """, ) - jobs = zuullint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") - playbook_paths = zuullint_utils.get_playbook_paths_from_job(jobs[0].get("job")) + jobs = zuulcilint_utils.get_jobs_from_zuul_yaml(tmp_path / "job.yaml") + playbook_paths = zuulcilint_utils.get_playbook_paths_from_job(jobs[0].get("job")) assert len(playbook_paths) == 0 def test_get_files_with_extension(): """Test return a list of files with the specified extension.""" tmp_path = setup_tmp_list_of_files() - files = zuullint_utils.get_files_with_extension(tmp_path, "yaml") + files = zuulcilint_utils.get_files_with_extension(tmp_path, "yaml") size = 2 assert len(files) == size diff --git a/tests/test_zuullint.py b/tests/test_zuulcilint.py similarity index 91% rename from tests/test_zuullint.py rename to tests/test_zuulcilint.py index 64bbfe3..4fcf0fd 100644 --- a/tests/test_zuullint.py +++ b/tests/test_zuulcilint.py @@ -20,7 +20,7 @@ def test_invalid(): [ "python", "-m", - "zuullint", + "zuulcilint", "tests/zuul_data_invalid/zuul-config-invalid.yaml", ], ) @@ -40,7 +40,7 @@ def test_valid(): """ try: subprocess.call( - ["python", "zuullint", "-m", "tests/zuul_data"], + ["python", "zuulcilint", "-m", "tests/zuul_data"], ) except subprocess.CalledProcessError as e: pytest.fail(e) diff --git a/zuulcilint/__init__.py b/zuulcilint/__init__.py new file mode 100644 index 0000000..b0e7361 --- /dev/null +++ b/zuulcilint/__init__.py @@ -0,0 +1 @@ +"""Init file for zuulcilint.""" diff --git a/zuullint/__main__.py b/zuulcilint/__main__.py similarity index 96% rename from zuullint/__main__.py rename to zuulcilint/__main__.py index 3268dcb..7971c12 100644 --- a/zuullint/__main__.py +++ b/zuulcilint/__main__.py @@ -11,8 +11,8 @@ import yaml from jsonschema import Draft201909Validator -import zuullint.checker as zuul_checker -import zuullint.utils as zuul_utils +import zuulcilint.checker as zuul_checker +import zuulcilint.utils as zuul_utils # # Register custom yaml constructor for "encrypted/pkcs1-oaep" yaml.SafeLoader.add_constructor( @@ -60,11 +60,11 @@ def main(): ------- None. """ - parser = argparse.ArgumentParser(prog="zuullint") + parser = argparse.ArgumentParser(prog="zuulcilint") parser.add_argument( "--version", action="version", - version=importlib.metadata.version("zuullint"), + version=importlib.metadata.version("zuulcilint"), ) parser.add_argument( "--check-playbook-paths", diff --git a/zuullint/checker.py b/zuulcilint/checker.py similarity index 100% rename from zuullint/checker.py rename to zuulcilint/checker.py diff --git a/zuullint/utils.py b/zuulcilint/utils.py similarity index 100% rename from zuullint/utils.py rename to zuulcilint/utils.py diff --git a/zuullint/zuul-schema.json b/zuulcilint/zuul-schema.json similarity index 100% rename from zuullint/zuul-schema.json rename to zuulcilint/zuul-schema.json diff --git a/zuullint/__init__.py b/zuullint/__init__.py deleted file mode 100644 index bc60a26..0000000 --- a/zuullint/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Init file for zuullint."""