Skip to content

Commit

Permalink
Remove setup.cfg, switch to pyproject.toml, switch from FLake8 to Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed May 6, 2024
1 parent dafcf31 commit 6f5ba74
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 86 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
export PYTHONPATH="${{ github.workspace }}"
python -m unittest
flake8:
name: "Flake8"
ruff:
name: "Ruff"
runs-on: ubuntu-latest
steps:

Expand All @@ -59,15 +59,15 @@ jobs:
uses: actions/checkout@v4

- name: Install Python requirements
run: pip install flake8
run: pip install -r requirements.txt

- name: Run flake8
run: flake8
- name: Run Ruff
run: make lint

release:
name: "🚀 Release"
runs-on: ubuntu-20.04
needs: [tests, flake8]
needs: [tests, ruff]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

steps:
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: test

PYTHON_PKG=qgis_plugin_manager
TESTDIR=test

test:
cd test && python3 -m unittest

lint:
@ruff check $(PYTHON_PKG) $(TESTDIR)

lint-preview:
@ruff check --preview $(PYTHON_PKG) $(TESTDIR)

lint-fix:
@ruff check --fix --preview $(PYTHON_PKG) $(TESTDIR)
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[tool.setuptools]
license-files = "LICENSE"

# Ruff configuration
# See https://doc.astral.sh/ruff/configuration

[tool.ruff]
line-length = 110
target-version = "py37"
exclude = [
".venv",
".local",
]

[tool.ruff.format]
indent-style = "space"

[tool.ruff.lint]
extend-select = ["E", "F", "I", "ANN", "W", "T", "COM", "RUF"]
ignore = [
"ANN101",
"ANN102",
"ANN204",
"T201",
]

[tool.ruff.lint.per-file-ignores]
"test/*" = [
"ANN201",
]

[tool.ruff.lint.isort]
lines-between-types = 1
known-third-party = [
"qgis",
]
order-by-type = true

[tool.ruff.lint.flake8-annotations]
#ignore-fully-untyped = true
suppress-none-returning = true
#suppress-dummy-args = true
2 changes: 1 addition & 1 deletion qgis_plugin_manager/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
]
],
)
8 changes: 4 additions & 4 deletions qgis_plugin_manager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from qgis_plugin_manager.utils import qgis_server_version


def main() -> int: # noqa: C901
def main() -> int:
""" Main function for the CLI menu. """
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("-v", "--version", action="version", version=__version__)

subparsers = parser.add_subparsers(
title="commands", description="qgis-plugin-manager command", dest="command"
title="commands", description="qgis-plugin-manager command", dest="command",
)

subparsers.add_parser("init", help="Create the `sources.list` with plugins.qgis.org as remote")
Expand Down Expand Up @@ -167,7 +167,7 @@ def main() -> int: # noqa: C901
f"{Level.Alert}"
f"Plugin {plugin_object.name} skipped from the upgrade command, because the plugin "
f"is in the ignored list."
f"{Level.End}"
f"{Level.End}",
)
continue

Expand Down
4 changes: 2 additions & 2 deletions qgis_plugin_manager/definitions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import NamedTuple
from typing import ClassVar, NamedTuple

__copyright__ = 'Copyright 2021, 3Liz'
__license__ = 'GPL version 3'
Expand All @@ -10,7 +10,7 @@ class Plugin(NamedTuple):
name: str = None
description: str = None
version: str = None
search: list = []
search: ClassVar = []
qgis_minimum_version: str = None
qgis_maximum_version: str = None
homepage: str = None
Expand Down
18 changes: 9 additions & 9 deletions qgis_plugin_manager/local_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import stat

from pathlib import Path
from typing import Dict, Union
from typing import Dict, Optional, Union

from qgis_plugin_manager.definitions import Level, Plugin
from qgis_plugin_manager.remote import Remote
Expand All @@ -25,7 +25,7 @@

class LocalDirectory:

def __init__(self, folder: Path, qgis_version: str = None):
def __init__(self, folder: Path, qgis_version: Optional[str] = None):
""" Constructor"""
self.folder = folder
# Dictionary : folder : plugin name
Expand Down Expand Up @@ -55,7 +55,7 @@ def init(self) -> bool:
print(
f"{Level.Alert}"
f"QGIS version is unknown, creating with a default {DEFAULT_QGIS_VERSION}"
f"{Level.End}"
f"{Level.End}",
)
version = DEFAULT_QGIS_VERSION

Expand Down Expand Up @@ -152,7 +152,7 @@ def plugin_info(self, plugin: str) -> Union[None, Plugin]:
)
return data

def plugin_installed_version(self, plugin_name) -> Union[str, None]:
def plugin_installed_version(self, plugin_name: str) -> Union[str, None]:
""" If a plugin is installed or not. """
if self._plugins is None:
self.plugin_list()
Expand Down Expand Up @@ -182,7 +182,7 @@ def remove(self, plugin_name: str) -> bool:
try:
shutil.rmtree(plugin_path)
except Exception as e:
print(f"{Level.Critical}Plugin {plugin_name} could not be removed : {str(e)}")
print(f"{Level.Critical}Plugin {plugin_name} could not be removed : {e!s}")

if not Path(self.folder.joinpath(plugin_folder)).exists():
print(f"{Level.Success}Plugin {plugin_name} removed")
Expand All @@ -193,7 +193,7 @@ def remove(self, plugin_name: str) -> bool:
f"{Level.Alert}"
f"Plugin {plugin_name} using folder {plugin_folder} could not be removed "
f"for unknown reason"
f"{Level.End}"
f"{Level.End}",
)
break
print(f"{Level.Alert}Plugin name '{plugin_name}' not found{Level.End}")
Expand All @@ -205,7 +205,7 @@ def remove(self, plugin_name: str) -> bool:

return False

def print_table(self, current_directory: bool = True): # noqa: C901
def print_table(self, current_directory: bool = True):
""" Print all plugins installed as a table. """
if self._plugins is None:
self.plugin_list()
Expand Down Expand Up @@ -322,7 +322,7 @@ def print_table(self, current_directory: bool = True): # noqa: C901
print(pretty_table(data, headers))
else:
print(
f"{Level.Alert}No plugin found in the current directory {self.folder.absolute()}{Level.End}"
f"{Level.Alert}No plugin found in the current directory {self.folder.absolute()}{Level.End}",
)

if len(list_of_owners) > 1:
Expand All @@ -331,7 +331,7 @@ def print_table(self, current_directory: bool = True): # noqa: C901
f"{Level.Alert}"
f"Different rights have been detected : {','.join(list_of_owners)}"
f"{Level.End}. "
f"Please check user-rights."
f"Please check user-rights.",
)

if len(self._invalid) >= 1:
Expand Down
34 changes: 17 additions & 17 deletions qgis_plugin_manager/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import zipfile

from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union
from urllib.parse import unquote, urlencode, urlparse, urlunparse, parse_qs
from typing import Dict, Iterator, List, Optional, Tuple, Union
from urllib.parse import parse_qs, unquote, urlencode, urlparse, urlunparse
from xml.etree.ElementTree import parse

from qgis_plugin_manager.definitions import Level, Plugin
Expand All @@ -27,7 +27,7 @@

class Remote:

def __init__(self, folder: Path, qgis_version: str = None):
def __init__(self, folder: Path, qgis_version: Optional[str] = None):
""" Constructor. """
self.folder = folder
self.list = None
Expand Down Expand Up @@ -61,7 +61,7 @@ def remote_is_ready(self) -> bool:
f"{Level.Critical}"
f"The 'update' command has not been done before. "
f"The repository {server} has not been fetched before."
f"{Level.End}"
f"{Level.End}",
)
self.setting_error = True
return False
Expand Down Expand Up @@ -96,7 +96,7 @@ def remote_list(self) -> list:
print(
f"{Level.Alert}"
f"Your https://plugins.qgis.org remote is not using a dynamic QGIS version."
f"{Level.End}"
f"{Level.End}",
)
print(
f"Instead of\n'{raw_line}'"
Expand All @@ -108,7 +108,7 @@ def remote_list(self) -> list:
f"regenerate it using dynamic QGIS version if QGIS is well configured.\n"
f"This is only a warning, the process will continue with the hardcoded QGIS "
f"version in your 'sources.list' file."
f"\n\n"
f"\n\n",
)

if "[VERSION]" in raw_line:
Expand All @@ -117,7 +117,7 @@ def remote_list(self) -> list:
f"{Level.Alert}"
f"Skipping line '{raw_line}' because it has a token [VERSION] but "
f"no QGIS version could be detected."
f"{Level.End}"
f"{Level.End}",
)
continue

Expand Down Expand Up @@ -298,7 +298,7 @@ def _parse_xml(self, xml_file: Path, plugins: Dict) -> Dict:
self.list_plugins[xml_plugin_name] = plugin_obj
return plugins

def search(self, search_string: str, strict=True) -> List:
def search(self, search_string: str, strict: bool = True) -> List:
""" Search in plugin names and tags."""
# strict is used in tests to not check if the remote is ready
if strict and not self.remote_is_ready():
Expand All @@ -319,8 +319,8 @@ def search(self, search_string: str, strict=True) -> List:
return results

def install(
self, plugin_name, version="latest", current_version: str = "", force: bool = False,
remove_zip=True
self, plugin_name: str, version: str = "latest", current_version: str = "", force: bool = False,
remove_zip: bool = True,
) -> bool:
""" Install the plugin with a specific version.
Expand Down Expand Up @@ -349,7 +349,7 @@ def install(
if current_version == actual:
if not force:
print(
f"\t{Level.Alert}Same version detected on the remote, skipping {plugin_name}{Level.End}"
f"\t{Level.Alert}Same version detected on the remote, skipping {plugin_name}{Level.End}",
)
# Plugin is installed and correct version, it's exit code 0
return True
Expand Down Expand Up @@ -405,7 +405,7 @@ def install(
return True

def _download_zip(
self, url: str, version: str, plugin_name: str, file_name: str, user: str
self, url: str, version: str, plugin_name: str, file_name: str, user: str,
) -> Tuple[bool, Union[None, Path]]:
""" Download the ZIP
"""
Expand Down Expand Up @@ -457,7 +457,7 @@ def _download_zip(
return True, zip_file

@staticmethod
def check_qgis_dev_version(qgis_version) -> Optional[List[str]]:
def check_qgis_dev_version(qgis_version: str) -> Optional[List[str]]:
""" Check if the QGIS current version is odd number. """
if not qgis_version:
return None
Expand All @@ -467,18 +467,18 @@ def check_qgis_dev_version(qgis_version) -> Optional[List[str]]:
print(
f"{Level.Alert}"
f"A QGIS development version is detected : {qgis_version[0]}.{qgis_version[1]}."
f"{Level.End}"
f"{Level.End}",
)
qgis_version[1] = str(int(qgis_version[1]) + 1)
print(
f"{Level.Alert}"
f"If needed, it will use {qgis_version[0]}.{qgis_version[1]} instead."
f"{Level.End}"
f"{Level.End}",
)
return qgis_version

@staticmethod
def server_cache_filename(cache_folder, server) -> Path:
def server_cache_filename(cache_folder: str, server: str) -> Path:
""" Return the path for XML file. """
server, login, _ = Remote.credentials(server)
filename = ""
Expand Down Expand Up @@ -510,7 +510,7 @@ def credentials(cls, server: str) -> Tuple[str, str, str]:

return urlunparse(u), '', ''

def all_credentials(self):
def all_credentials(self) -> Iterator[str, str, str]:
""" Dirty hack to get all credentials for now… """
if self.list is None:
self.remote_list()
Expand Down
Loading

0 comments on commit 6f5ba74

Please sign in to comment.