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

Feature/pep checker #154

Closed
wants to merge 11 commits into from
Closed
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

This file documents any relevant changes.
## [2.1.0]
- feature: added pep8 check

## [2.0.1] 2024-05-06
- bugfix: removed project.json profile "core" validation throughout the project
- chore: bumped version numbers in setup.cfg
- chore: Added hints to several commands

## [2.0.0] 2024-04-11:
- chore: added deprecation warnings
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
build = "*"
twine = "*"
pycodestyle = "*"

[requires]
python_version = "3"
Expand Down
239 changes: 137 additions & 102 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ run the appserver and start your app locally. You may specify a target profile.


```sh
$ viur check [--dev]
$ viur check {pep|dev|all} [--path]
```
Runs a security check for the python environment and for each npm project registered under builds.
Runs a security check for the python environment and for each npm project registered under builds and for pep8 conformity.

```sh
$ viur package {install|update} {vi|scriptor|admin|all}
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install_requires =
pipfile-requirements~=0.3
requests~=2.31
semver~=3.0
pycodestyle~=2.11.1


[options.packages.find]
Expand Down
25 changes: 3 additions & 22 deletions src/viur_cli/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import json
from pprint import pprint

import click
import requests
import difflib
Expand Down Expand Up @@ -119,13 +117,13 @@ def migrate(self):
self.find_key(self, target_key="application_name", target="default", keep=True)
if "application_name" in self:
del self["application_name"]

if "version" not in self["default"]:
self.find_key(self, target_key="version", target="default", keep=True)
# Fail Safe
if "version" in self:
del self["version"]

self.remove_key(self, target_key="core")

if old_format := self["default"].get("format"):
Expand Down Expand Up @@ -159,17 +157,6 @@ def migrate(self):
builds[k]["kind"] = "exec"
self["default"]["builds"] = builds

# Version 1.2.0
"""
Convert versions in the configuration to builds.

This method iterates through the provided version list and updates the project configuration
by converting versions to builds.

:param version_list: list
List of versions to convert to builds.
:return: None
"""
# Check if Builds is in the project.json
if "builds" not in self["default"].keys():
self["default"]["builds"] = {}
Expand Down Expand Up @@ -205,14 +192,8 @@ def migrate(self):
elif response == "no":
self["default"]["builds"].pop("admin", None)
echo_info("You are using the Vi Administration")
"""
Fetch the version of the 'viur-core' package.

This method is responsible for fetching the version of the 'viur-core' package using 'pip list' and updating
the project configuration accordingly.


:return: None
"""

self.save()

Expand Down
39 changes: 28 additions & 11 deletions src/viur_cli/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from viur_cli import echo_info, echo_warning
from .conf import config
from . import cli, echo_error, utils, echo_fatal
from requests import get
from .package import vi as vi_install
from types import SimpleNamespace
import pycodestyle


def get_user_info():
Expand Down Expand Up @@ -162,15 +160,34 @@ def env(profile):


@cli.command()
@click.option('--dev', '-d', is_flag=True, default=False)
def check(dev):
"""
Perform security checks for vulnerabilities.
The 'check' command helps you identify and address security vulnerabilities in your project's dependencies.
"""
@click.argument("action", type=click.Choice(["dev", "pep", "all"]), default="all")
@click.option("--path", "-p", default="deploy")
def check(action, path):
utils.echo_positive(action)
if action == "all":
checkpep8(path)
if do_checks(True):
utils.echo_positive("\U00002714 No vulnerabilities found.")

if action == "dev":
if do_checks(True):
utils.echo_positive("\U00002714 No vulnerabilities found.")

if action == "pep":
checkpep8(path)

if do_checks(dev):
utils.echo_info("\U00002714 No vulnerabilities found.")
pass


def checkpep8(path):
ignore_list = ["E121", "E123", "E126", "E133", "E226", "E241", "E242", "E704", "W503", "W504", "W505"]
style_guide = pycodestyle.StyleGuide(format="pylint", ignore=ignore_list)
report = style_guide.check_files([path])

if report.total_errors:
click.echo(f'Found {report.total_errors} PEP8 violation(s)')
else:
click.echo('No PEP8 violations found')


def do_checks(dev=True):
Expand Down
2 changes: 0 additions & 2 deletions src/viur_cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def create(ctx, name):
Note:

- This command initializes the new ViUR project based on the ViUR base project.

- Make sure to provide a unique project name to avoid conflicts with existing folders.

"""
Expand All @@ -37,7 +36,6 @@ def create(ctx, name):
# fetch base project
os.system(
f'git clone https://github.com/viur-framework/viur-base.git {name}')
project_json_path = f'./{name}/project.json'

# collect project info
conf = config.get_profile("default")
Expand Down
2 changes: 1 addition & 1 deletion src/viur_cli/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "2.0.0"
__version__ = "2.0.1"
MINIMAL_PIPENV = "2023.11.15"