Skip to content

Commit

Permalink
Upgrade Prospector, use profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 8, 2024
1 parent a3844da commit 5d53aa4
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 554 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ repos:
- --output-format=pylint
additional_dependencies:
- prospector-profile-duplicated==1.6.0 # pypi
- prospector-profile-utils==1.9.1 # pypi
- repo: https://github.com/mheap/json-schema-spell-checker
rev: main
hooks:
Expand Down
40 changes: 4 additions & 36 deletions .prospector.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,18 @@
inherits:
- utils:base
- utils:no-design-checks
- utils:fix
- duplicated
strictness: veryhigh
max-line-length: 110

doc-warnings: true

ignore-paths:
- c2cciutils/configuration.py

pylint:
disable:
- too-many-arguments
- too-many-branches
- too-many-locals
- too-many-statements
- too-many-nested-blocks
- too-many-lines
- too-few-public-methods
- line-too-long # done by Black
- missing-module-docstring

pycodestyle:
options:
max-line-length: 110
disable:
- W293 # blank line contains whitespace
- E501 # line too long, Done by Black

pydocstyle:
disable:
- D105 # Missing docstring in magic method
- D200 # One-line docstring should fit on one line with quotes
- D202 # No blank lines allowed after function docstring
- D203 # 1 blank line required before class
- D212 # Multi-line docstring summary should start at the first line
- D407 # Missing dashed underline after section
mypy:
run: true

bandit:
run: true
options:
config: .bandit.yaml

# Not working withy current Pyroma version
pyroma:
run: true

mccabe:
run: false
8 changes: 0 additions & 8 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def get_repository() -> str:
"""
Get the current GitHub repository like `organization/project`.
"""

if "GITHUB_REPOSITORY" in os.environ:
return os.environ["GITHUB_REPOSITORY"]

Expand All @@ -47,7 +46,6 @@ def merge(default_config: Any, config: Any) -> Any:
default_config: The default config that will be applied
config: The base config, will be modified
"""

if not isinstance(default_config, dict) or not isinstance(config, dict):
return config

Expand Down Expand Up @@ -79,7 +77,6 @@ def get_config() -> c2cciutils.configuration.Configuration:
"""
Get the configuration, with project and auto detections.
"""

config: c2cciutils.configuration.Configuration = {}
if os.path.exists("ci/config.yaml"):
with open("ci/config.yaml", encoding="utf-8") as open_file:
Expand Down Expand Up @@ -279,7 +276,6 @@ def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool:
Arguments:
config: The print configuration
"""

for version in config.get("versions", c2cciutils.configuration.PRINT_VERSIONS_VERSIONS_DEFAULT):
try:
sys.stdout.flush()
Expand Down Expand Up @@ -383,7 +379,6 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
Return the data result
In case of error it throw an exception
"""

with open(os.path.join(os.path.dirname(__file__), query_file), encoding="utf-8") as query_open:
query = query_open.read()

Expand Down Expand Up @@ -460,7 +455,6 @@ def get_branch(branch: Optional[str], master_branch: str = "master") -> str:
Return the branch name
"""

if branch is not None:
return branch
try:
Expand Down Expand Up @@ -573,7 +567,6 @@ def get_codespell_command(config: c2cciutils.configuration.Configuration, fix: b

def snyk_exec() -> tuple[str, dict[str, str]]:
"""Get the Snyk cli executable path."""

if not os.path.exists(os.path.join(os.path.dirname(__file__), "node_modules")):
subprocess.run(["npm", "install"], cwd=os.path.dirname(__file__), check=True) # nosec

Expand All @@ -598,7 +591,6 @@ def create_pull_request_if_needed(
"""
Create a pull request if there are changes.
"""

if pull_request_extra_arguments is None:
pull_request_extra_arguments = ["--fill"]

Expand Down
7 changes: 0 additions & 7 deletions c2cciutils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def print_environment_variables() -> None:
"""
Print the environment variables.
"""

for name, value in sorted(os.environ.items()):
if name != "GITHUB_EVENT":
print(f"{name}: {value}")
Expand All @@ -53,7 +52,6 @@ def print_github_event_file() -> None:
"""
Print the GitHub event file.
"""

if "GITHUB_EVENT_PATH" in os.environ:
with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as event:
print(event.read())
Expand All @@ -63,7 +61,6 @@ def print_github_event_object() -> None:
"""
Print the GitHub event object.
"""

github_event = json.loads(os.environ["GITHUB_EVENT"])
print(yaml.dump(github_event, indent=2))

Expand All @@ -72,29 +69,25 @@ def print_python_package_version() -> None:
"""
Print the version of the Python packages.
"""

subprocess.run(["python3", "-m", "pip", "freeze", "--all"]) # pylint: disable=subprocess-run-check


def print_node_package_version() -> None:
"""
Print the version of the Python packages.
"""

subprocess.run(["npm", "list", "--global"]) # pylint: disable=subprocess-run-check


def print_debian_package_version() -> None:
"""
Print the version of the Python packages.
"""

subprocess.run(["dpkg", "--list"]) # pylint: disable=subprocess-run-check


def print_environment(config: c2cciutils.configuration.Configuration, prefix: str = "Print ") -> None:
"""Print the GitHub environment information."""

functions = [
(
"version",
Expand Down
2 changes: 0 additions & 2 deletions c2cciutils/lib/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def get_dpkg_packages_versions(
Where `debian_11` corresponds on last path element for 'Debian 11'
from https://repology.org/repositories/statistics
"""

dpkg_configuration = c2cciutils.get_config().get("dpkg", {})

os_release = {}
Expand Down Expand Up @@ -127,7 +126,6 @@ def check_versions(
The versions of packages in the image should be present in the config file.
The versions of packages in the image shouldn't be older than the versions of the config file.
"""

result, versions_image = get_dpkg_packages_versions(image, default_distribution, default_release)
if not result:
return False
Expand Down
6 changes: 3 additions & 3 deletions c2cciutils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ def save_credentials_to_gopass(self) -> None:
c2cciutils.gopass_put(secret, key)

def __del__(self) -> None:
"""
Delete the credentials file.
"""
if os.path.exists(self.credentials_pickle_file):
os.remove(self.credentials_pickle_file)

Expand Down Expand Up @@ -250,7 +253,6 @@ def pip(
publish: If False only check the package
package: The package configuration
"""

print(f"::group::{'Publishing' if publish else 'Checking'} '{package.get('path')}' to pypi")
sys.stdout.flush()
sys.stderr.flush()
Expand Down Expand Up @@ -349,7 +351,6 @@ def docker(
dst_tags: Publish using the provided tags
images_full: The list of published images (with tag), used to build the dispatch event
"""

print(
f"::group::Publishing {image_config['name']} to the server {name} using the tags {', '.join(dst_tags)}"
)
Expand Down Expand Up @@ -409,7 +410,6 @@ def helm(folder: str, version: str, owner: str, repo: str, commit_sha: str, toke
commit_sha: The sha of the current commit
token: The GitHub token
"""

print(f"::group::Publishing Helm chart from '{folder}' to GitHub release")
sys.stdout.flush()
sys.stderr.flush()
Expand Down
1 change: 0 additions & 1 deletion c2cciutils/scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def clean(image: str, tag: str, token: str) -> None:
tag: The tag that should be deleted
token: The token used to be authenticated on Docker hub
"""

print(f"Delete image '{image}:{tag}'.")

response = requests.head(
Expand Down
2 changes: 0 additions & 2 deletions c2cciutils/scripts/download_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

def main() -> None:
"""Download applications from GitHub releases or any other URLs to the ~/.local/bin folder."""

argparser = argparse.ArgumentParser(
description="""Download applications from GitHub releases or any other URLs to the ~/.local/bin folder.
Based on tow files, the first contains the information about from where to download the applications,
Expand Down Expand Up @@ -60,7 +59,6 @@ def download_applications(
applications: applications_definition.ApplicationsConfiguration, versions: dict[str, str]
) -> None:
"""Download the versions of applications specified in the configuration."""

bin_path = os.path.join(os.environ["HOME"], ".local", "bin")
if not os.path.exists(bin_path):
os.makedirs(bin_path)
Expand Down
1 change: 0 additions & 1 deletion c2cciutils/scripts/trigger_image_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def dispatch(repository: str, event_type: str, images_full: list[str]) -> None:
"""
Trigger an image update on the argocd repository.
"""

id_ = random.randint(1, 100000) # nosec
print(f"Triggering {event_type}:{id_} on {repository} with {','.join(images_full)}")

Expand Down
1 change: 0 additions & 1 deletion c2cciutils/scripts/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

def main() -> None:
"""Create a new version with its stabilization branch."""

args_parser = argparse.ArgumentParser(
description="Create a new version with its stabilization branch",
usage="""
Expand Down
24 changes: 3 additions & 21 deletions example-project/.prospector.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
inherits:
- utils:base
- utils:no-design-checks
- duplicated
strictness: veryhigh
max-line-length: 110

pylint:
disable:
- too-many-arguments
- too-many-branches
- too-many-locals
- too-many-statements
- too-many-nested-blocks
- too-few-public-methods

pycodestyle:
options:
max-line-length: 110

mypy:
run: true
options:
python-version: 3.8
python-version: '3.10'
ignore-missing-imports: True
warn:
- redundant-casts
Expand All @@ -28,9 +14,5 @@ mypy:
- untyped-defs

bandit:
run: true
options:
config: .bandit.yaml

mccabe:
run: false
Loading

0 comments on commit 5d53aa4

Please sign in to comment.