Skip to content

Commit

Permalink
Add lint task. Pass lint. Score: 10/10
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Jun 16, 2024
1 parent b0b4659 commit 1276e4b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 32 deletions.
36 changes: 36 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Lint",
"detail": "pylint icm",
"type": "shell",
"command": "${command:python.interpreterPath}",
"args": ["-m", "pylint", "icm"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true,
},

"problemMatcher": {
"owner": "python",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(W|E|C).+:\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
1 change: 1 addition & 0 deletions icm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Icestudio Collection Manager"""

# -*- coding: utf-8 -*-
# -- This file is part of the Icestudio project
# -- (C) 2017 FPGAwars
Expand Down
1 change: 1 addition & 0 deletions icm/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Icestudio Collection Manager"""

# -*- coding: utf-8 -*-
# -- This file is part of the Icestudio project
# -- (C) 2017 FPGAwars
Expand Down
19 changes: 9 additions & 10 deletions icm/commands/cmd_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Docstring"""

# -*- coding: utf-8 -*-
# -- This file is part of the Icestudio project
# -- (C) 2017 FPGAwars
Expand Down Expand Up @@ -43,7 +44,7 @@ def create():
os.path.dirname(__file__), "..", "resources", "en.po"
)

with open(local_po_file, "r") as file:
with open(local_po_file, "r", encoding="utf-8") as file:
po_file = file.read()
_create_file("locale/en/en.po", po_file)

Expand All @@ -57,7 +58,7 @@ def create():
os.path.dirname(__file__), "..", "resources", "GPL-2.0"
)

with open(local_license, "r") as file:
with open(local_license, "r", encoding="utf-8") as file:
_license = file.read()
_create_file("LICENSE", _license)

Expand All @@ -67,7 +68,7 @@ def create():
os.path.dirname(__file__), "..", "resources", "package.tpl.json"
)

with open(package_template, "r") as file:
with open(package_template, "r", encoding="utf-8") as file:
template = Template(file.read())

package = template.safe_substitute(
Expand All @@ -92,17 +93,15 @@ def create():
def _create_directory(name):
if not os.path.exists(name):
os.makedirs(name)
click.secho(" - `{}` directory created".format(name), fg="green")
click.secho(f" - `{name}` directory created", fg="green")
else:
click.secho(
" - `{}` directory already exists".format(name), fg="yellow"
)
click.secho(f" - `{name}` directory already exists", fg="yellow")


def _create_file(name, content):
if not os.path.exists(name):
with open(name, "w") as file:
with open(name, "w", encoding="utf-8") as file:
file.write(content)
click.secho(" - `{}` file created".format(name), fg="green")
click.secho(f" - `{name}` file created", fg="green")
else:
click.secho(" - `{}` file already exists".format(name), fg="yellow")
click.secho(" - `{name}` file already exists", fg="yellow")
32 changes: 14 additions & 18 deletions icm/commands/cmd_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Update command"""

# -*- coding: utf-8 -*-
# -- This file is part of the Icestudio project
# -- (C) 2017 FPGAwars
Expand Down Expand Up @@ -96,37 +97,32 @@ def _update_file(dest, data):
def _update_existing_file(dest, data):
"""Update the dest file with the given data"""

with open(dest, "r") as file:
with open(dest, "r", encoding="utf-8") as file:

# Read the current data from the fiel and check
# if it is equal or not to the given data
if file.read() == data:
click.secho(
" - `{}` file already updated".format(dest), fg="yellow"
)
click.secho(f" - `{dest}` file already updated", fg="yellow")
# -- The file is outdated
else:
if click.confirm(
"The `{}` file has changes.\n"
"Do you want to replace it?".format(dest)
f"The `{dest}` file has changes.\n"
"Do you want to replace it?"
):
with open(dest, "w") as file:
with open(dest, "w", encoding="utf-8") as file:
file.write(data)
click.secho(" - `{}` file updated".format(dest), fg="green")
click.secho(f" - `{dest}` file updated", fg="green")
else:
click.secho(" - `{}` file not updated".format(dest), fg="red")
click.secho(f" - `{dest}` file not updated", fg="red")


def _create_new_file(dest, data):
path = os.path.dirname(dest)
if path and not os.path.exists(path):
os.mkdir(path)
with open(
dest,
"w",
) as file:
with open(dest, "w", encoding="utf-8") as file:
file.write(data)
click.secho(" - `{}` file created".format(dest), fg="green")
click.secho(f" - `{dest}` file created", fg="green")


def _generate_readme_string():
Expand All @@ -140,10 +136,10 @@ def _generate_readme_string():
os.path.dirname(__file__), "..", "resources", "README.tpl.md"
)

with open("package.json", "r") as pack:
with open("package.json", "r", encoding="utf-8") as pack:
package = json.load(pack)

with open(readme_template, "r") as file:
with open(readme_template, "r", encoding="utf-8") as file:

# Read the template content
template = Template(file.read())
Expand Down Expand Up @@ -462,7 +458,7 @@ def _generate_translation_strings():
)

# -- Process the template file
with open(readme_template, "r") as file:
with open(readme_template, "r", encoding="utf-8") as file:
translations = []
template = Template(file.read())

Expand Down Expand Up @@ -516,7 +512,7 @@ def _find_texts(path, translations, ext=".ice"):


def _find_texts_in_file(filepath, translations):
with open(filepath, "r") as path:
with open(filepath, "r", encoding="utf-8") as path:
project = path.read()
# Append descriptions
path = re.compile(PATTERN_DESC)
Expand Down
5 changes: 3 additions & 2 deletions icm/commands/cmd_validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validate a collection"""

# -*- coding: utf-8 -*-
# -- This file is part of the Icestudio project
# -- (C) 2017 FPGAwars
Expand Down Expand Up @@ -51,7 +52,7 @@ def validate_collection():

def _validate_package_file(valid):
try:
with open("package.json", "r") as data:
with open("package.json", "r", encoding="utf-8") as data:
package = json.load(data)
keys = package.keys()
valid = _check_key("name", keys, valid, lambda x: package[x])
Expand Down Expand Up @@ -81,6 +82,6 @@ def _check_key(key, keys, valid, extra_check=lambda x: x):
if not (key in keys and extra_check(key)):
valid &= False
click.secho(
" - Error: not valid {} in `package.json`".format(key), fg="yellow"
f" - Error: not valid {key} in `package.json`", fg="yellow"
)
return valid
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ icm = "icm.__main__:cli"

[tool.black]
line-length = 79
target-version = ['py38']
target-version = ['py39']
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = True
envlist = py38
envlist = py10

[testenv]
deps =
Expand Down

0 comments on commit 1276e4b

Please sign in to comment.