-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from MIERUNE/rfctr
refactor, lint, fix minor bug
- Loading branch information
Showing
11 changed files
with
197 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
Test: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install poetry | ||
run: python -m pip install poetry | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
cache: 'poetry' | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Check poetry.lock | ||
run: poetry lock --check | ||
|
||
# - name: Type-check with Pyright | ||
# run: poetry run pyright . | ||
|
||
- name: Lint with ruff | ||
run: poetry run ruff --output-format=github . | ||
|
||
- name: Format with ruff | ||
run: poetry run ruff format . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
GTFSGo | ||
A QGIS plugin | ||
The plugin to show routes and stops from GTFS | ||
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ | ||
------------------- | ||
begin : 2020-10-29 | ||
copyright : (C) 2020 by Kanahiro Iguchi | ||
email : [email protected] | ||
git sha : $Format:%H$ | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
This script initializes the plugin, making it known to QGIS. | ||
""" | ||
|
||
|
||
# noinspection PyPep8Naming | ||
def classFactory(iface): # pylint: disable=invalid-name | ||
"""Load GTFSGo class from file GTFSGo. | ||
|
@@ -33,4 +6,5 @@ def classFactory(iface): # pylint: disable=invalid-name | |
""" | ||
# | ||
from .gtfs_go import GTFSGo | ||
|
||
return GTFSGo(iface) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
GTFSGo | ||
A QGIS plugin | ||
The plugin to show routes and stops from GTFS | ||
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ | ||
------------------- | ||
begin : 2020-10-29 | ||
git sha : $Format:%H$ | ||
copyright : (C) 2020 by MIERUNE Inc. | ||
email : [email protected] | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
import os | ||
|
||
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt | ||
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator | ||
from qgis.PyQt.QtGui import QIcon | ||
from qgis.PyQt.QtWidgets import QAction | ||
|
||
|
@@ -49,11 +26,10 @@ def __init__(self, iface): | |
self.plugin_dir = os.path.dirname(__file__) | ||
|
||
# initialize locale | ||
locale = QSettings().value('locale/userLocale')[0:2] | ||
locale = QSettings().value("locale/userLocale")[0:2] | ||
locale_path = os.path.join( | ||
self.plugin_dir, | ||
'i18n', | ||
'GTFSGo_{}.qm'.format(locale)) | ||
self.plugin_dir, "i18n", "GTFSGo_{}.qm".format(locale) | ||
) | ||
|
||
if os.path.exists(locale_path): | ||
self.translator = QTranslator() | ||
|
@@ -62,10 +38,10 @@ def __init__(self, iface): | |
|
||
# Declare instance attributes | ||
self.actions = [] | ||
self.menu = self.tr(u'>FS GO') | ||
self.menu = self.tr(">FS GO") | ||
# TODO: We are going to let the user set this up in a future iteration | ||
self.toolbar = self.iface.addToolBar(u'GTFSGo') | ||
self.toolbar.setObjectName(u'GTFSGo') | ||
self.toolbar = self.iface.addToolBar("GTFSGo") | ||
self.toolbar.setObjectName("GTFSGo") | ||
|
||
# print "** INITIALIZING GTFSGo" | ||
|
||
|
@@ -86,19 +62,20 @@ def tr(self, message): | |
:rtype: QString | ||
""" | ||
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass | ||
return QCoreApplication.translate('GTFSGo', message) | ||
return QCoreApplication.translate("GTFSGo", message) | ||
|
||
def add_action( | ||
self, | ||
icon_path, | ||
text, | ||
callback, | ||
enabled_flag=True, | ||
add_to_menu=True, | ||
add_to_toolbar=True, | ||
status_tip=None, | ||
whats_this=None, | ||
parent=None): | ||
self, | ||
icon_path, | ||
text, | ||
callback, | ||
enabled_flag=True, | ||
add_to_menu=True, | ||
add_to_toolbar=True, | ||
status_tip=None, | ||
whats_this=None, | ||
parent=None, | ||
): | ||
"""Add a toolbar icon to the toolbar. | ||
:param icon_path: Path to the icon for this action. Can be a resource | ||
|
@@ -153,9 +130,7 @@ def add_action( | |
self.toolbar.addAction(action) | ||
|
||
if add_to_menu: | ||
self.iface.addPluginToWebMenu( | ||
self.menu, | ||
action) | ||
self.iface.addPluginToWebMenu(self.menu, action) | ||
|
||
self.actions.append(action) | ||
|
||
|
@@ -164,14 +139,14 @@ def add_action( | |
def initGui(self): | ||
"""Create the menu entries and toolbar icons inside the QGIS GUI.""" | ||
|
||
icon_path = os.path.join(os.path.dirname( | ||
__file__), 'imgs', 'busstop.png') | ||
icon_path = os.path.join(os.path.dirname(__file__), "imgs", "busstop.png") | ||
self.add_action( | ||
icon_path, | ||
text=self.tr(u'GTFS GO'), | ||
text=self.tr("GTFS GO"), | ||
callback=self.run, | ||
parent=self.iface.mainWindow(), | ||
add_to_menu=True) | ||
add_to_menu=True, | ||
) | ||
|
||
# -------------------------------------------------------------------------- | ||
|
||
|
@@ -197,9 +172,7 @@ def unload(self): | |
# print "** UNLOAD GTFSGo" | ||
|
||
for action in self.actions: | ||
self.iface.removePluginWebMenu( | ||
self.tr(u'>FS GO'), | ||
action) | ||
self.iface.removePluginWebMenu(self.tr(">FS GO"), action) | ||
self.iface.removeToolBarIcon(action) | ||
# remove the toolbar | ||
del self.toolbar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
GTFSGoDockWidget | ||
A QGIS plugin | ||
The plugin to show routes and stops from GTFS | ||
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ | ||
------------------- | ||
begin : 2020-10-29 | ||
git sha : $Format:%H$ | ||
copyright : (C) 2020 by MIERUNE Inc. | ||
email : [email protected] | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
import csv | ||
import datetime | ||
import json | ||
import os | ||
import shutil | ||
import tempfile | ||
import urllib | ||
import uuid | ||
import csv | ||
|
||
from PyQt5.QtCore import * | ||
from PyQt5.QtGui import * | ||
from PyQt5.QtWidgets import * | ||
from qgis.core import * | ||
from qgis.gui import * | ||
from PyQt5.QtCore import QDate, QSortFilterProxyModel, Qt | ||
from PyQt5.QtWidgets import QAbstractItemView, QDialog, QLineEdit, QMessageBox | ||
from qgis.core import ( | ||
QgsCoordinateReferenceSystem, | ||
QgsProject, | ||
QgsSymbolLayer, | ||
QgsVectorLayer, | ||
) | ||
from qgis.gui import QgisInterface | ||
from qgis.PyQt import uic | ||
from qgis.utils import iface | ||
|
||
from . import constants, repository | ||
from .gtfs_go_labeling import get_labeling_for_stops | ||
|
@@ -55,7 +34,7 @@ | |
|
||
|
||
class GTFSGoDialog(QDialog): | ||
def __init__(self, iface): | ||
def __init__(self, iface: QgisInterface): | ||
"""Constructor.""" | ||
super().__init__() | ||
self.ui = uic.loadUi( | ||
|
@@ -129,7 +108,7 @@ def init_japan_dpf_gui(self): | |
now = datetime.datetime.now() | ||
self.ui.japanDpfTargetDateEdit.setDate(QDate(now.year, now.month, now.day)) | ||
|
||
self.japanDpfExtentGroupBox.setMapCanvas(iface.mapCanvas()) | ||
self.japanDpfExtentGroupBox.setMapCanvas(self.iface.mapCanvas()) | ||
self.japanDpfExtentGroupBox.setOutputCrs( | ||
QgsCoordinateReferenceSystem("EPSG:4326") | ||
) | ||
|
@@ -162,7 +141,6 @@ def download_zip(self, url: str) -> str: | |
|
||
return download_path | ||
|
||
|
||
def get_target_feed_infos(self): | ||
feed_infos = [] | ||
if self.repositoryCombobox.currentData() == REPOSITORY_ENUM["preset"]: | ||
|
@@ -304,7 +282,7 @@ def execution(self): | |
mode="w", | ||
encoding="utf-8", | ||
errors="ignore", | ||
newline='', | ||
newline="", | ||
) as f: | ||
writer = csv.DictWriter(f, fieldnames=stop_relations[0].keys()) | ||
writer.writeheader() | ||
|
@@ -335,10 +313,10 @@ def get_delimiter(self): | |
return "" | ||
return self.ui.delimiterLineEdit.text() | ||
|
||
def get_time_filter(self, lineEdit): | ||
def get_time_filter(self, line_edit: QLineEdit): | ||
if not self.ui.timeFilterCheckBox.isChecked(): | ||
return "" | ||
return lineEdit.text().replace(":", "") | ||
return line_edit.text().replace(":", "") | ||
|
||
def show_geojson( | ||
self, | ||
|
@@ -368,7 +346,7 @@ def show_geojson( | |
stops_geojson, os.path.basename(stops_geojson).split(".")[0], "ogr" | ||
) | ||
# make and set labeling for stops | ||
stops_labeling = get_labeling_for_stops("stop_names") | ||
stops_labeling = get_labeling_for_stops("stop_name") | ||
stops_vlayer.setLabelsEnabled(True) | ||
stops_vlayer.setLabeling(stops_labeling) | ||
|
||
|
@@ -477,7 +455,7 @@ def refresh(self): | |
self.ui.freqFrame.setEnabled(self.ui.aggregateCheckbox.isChecked()) | ||
|
||
@staticmethod | ||
def validate_time_lineedit(lineedit): | ||
def validate_time_lineedit(lineedit: QLineEdit): | ||
digits = "".join( | ||
list(filter(lambda char: char.isdigit(), list(lineedit.text()))) | ||
).ljust(6, "0")[-6:] | ||
|
@@ -545,12 +523,12 @@ def japan_dpf_set_table(self, results: list): | |
result["feed_pref_id"] | ||
] | ||
model = repository.japan_dpf.table.Model(results) | ||
proxyModel = QSortFilterProxyModel() | ||
proxyModel.setDynamicSortFilter(True) | ||
proxyModel.setSortCaseSensitivity(Qt.CaseInsensitive) | ||
proxyModel.setSourceModel(model) | ||
proxy_model = QSortFilterProxyModel() | ||
proxy_model.setDynamicSortFilter(True) | ||
proxy_model.setSortCaseSensitivity(Qt.CaseInsensitive) | ||
proxy_model.setSourceModel(model) | ||
|
||
self.japanDpfResultTableView.setModel(proxyModel) | ||
self.japanDpfResultTableView.setModel(proxy_model) | ||
self.japanDpfResultTableView.setCornerButtonEnabled(True) | ||
self.japanDpfResultTableView.setSortingEnabled(True) | ||
# -1 is no sort indicator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.