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

Centralize black & isort configuration #1860

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ lint-desktop: ## Lint .desktop files
find . -name *.desktop -type f -not -path '*/\.git/*' | xargs desktop-file-validate

.PHONY: lint
lint: bandit ## Run linters and formatters
lint: check-black check-isort bandit ## Run linters and formatters

.PHONY: fix
fix: black isort ## Fix lint and formatting issues

bandit: ## Run bandit security checks
@poetry run bandit -c pyproject.toml -r . --severity-level medium

.PHONY: black
black: ## Update Python source code formatting with black
@poetry run black .

.PHONY: check-black
check-black: ## Check Python source code formatting with black
@poetry run black --check --diff .

.PHONY: isort
isort: ## Update Python import organization with isort
@poetry run isort .

.PHONY: check-isort
check-isort: ## Check Python import organization with isort
@poetry run isort --check-only --diff .

safety: ## Run safety dependency checks on build dependencies
find . -name build-requirements.txt | xargs -n1 poetry run safety check --full-report \
--ignore 51668 \
Expand Down
26 changes: 1 addition & 25 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@ semgrep-local:
@echo "Running semgrep with local rules..."
@poetry run semgrep $(SEMGREP_FLAGS) --config ".semgrep"

.PHONY: black
black: ## Format Python source code with black
@poetry run black \
./ \
scripts/*.py

.PHONY: check-black
check-black: ## Check Python source code formatting with black
@poetry run black --check --diff \
./ \
scripts/*.py

.PHONY: isort
isort: ## Run isort to organize Python imports
@poetry run isort --skip-glob .venv \
./ \
scripts/*.py

.PHONY: check-isort
check-isort: ## Check Python import organization with isort
@poetry run isort --skip-glob .venv --check-only --diff \
./ scripts \
/*.py

.PHONY: mypy
mypy: ## Run static type checker
@poetry run mypy --ignore-missing-imports \
Expand Down Expand Up @@ -114,7 +90,7 @@ flake8: ## Run flake8 linting
@poetry run flake8 securedrop_client tests

.PHONY: lint
lint: check-black check-isort flake8 mypy semgrep ## Run all linters
lint: flake8 mypy semgrep ## Run all linters

.PHONY: check
check: clean lint test-random test-integration test-functional ## Run the full CI test suite
Expand Down
3 changes: 1 addition & 2 deletions client/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from logging.config import fileConfig
from os import path

from sqlalchemy import engine_from_config, pool

from alembic import context
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Create Date: 2022-05-24 20:48:28.581857

"""
import sqlalchemy as sa

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
Expand Down
2 changes: 1 addition & 1 deletion client/alembic/versions/d7c8af95bc8e_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Create Date: 2022-06-09 16:41:11.913336

"""
import sqlalchemy as sa

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
Expand Down
89 changes: 2 additions & 87 deletions client/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ PyQt5-sip = [
]
PyAutoGUI = "*"
babel = "^2.12.1"
black = "^23.7.0"
diffoscope = "*"
flake8 = "^6.0.0"
flaky = "*"
isort = "*"
mypy = "^1.4.1"
polib = "*"
pyqt5-stubs = "*"
Expand All @@ -50,15 +48,3 @@ types-polib = "*"
types-python-dateutil = "*"
types-requests = "^2.31.0"
types-setuptools = "^68.0.0"

[tool.black]
line-length = 100

[tool.isort]
line_length = 100
indent = ' '
multi_line_output = 3
ensure_newline_before_comments = true
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
1 change: 0 additions & 1 deletion client/securedrop_client/api_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(self) -> None:


class ApiJob(QueueJob):

"""
Signal that is emitted after an job finishes successfully.
"""
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import gettext
import locale
import logging
Expand Down
16 changes: 10 additions & 6 deletions client/securedrop_client/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ def import_key(self, source: Source) -> None:
def _import(self, key_data: str) -> None:
"""Imports a key to the client GnuPG keyring."""

with tempfile.NamedTemporaryFile("w+") as temp_key, tempfile.NamedTemporaryFile(
"w+"
) as stdout, tempfile.NamedTemporaryFile("w+") as stderr:
with (
tempfile.NamedTemporaryFile("w+") as temp_key,
tempfile.NamedTemporaryFile("w+") as stdout,
tempfile.NamedTemporaryFile("w+") as stderr,
):
temp_key.write(key_data)
temp_key.seek(0)
if self.is_qubes: # pragma: no cover
Expand Down Expand Up @@ -204,9 +206,11 @@ def encrypt_to_source(self, source_uuid: str, data: str) -> str:

cmd = self._gpg_cmd_base()

with tempfile.NamedTemporaryFile("w+") as content, tempfile.NamedTemporaryFile(
"w+"
) as stdout, tempfile.NamedTemporaryFile("w+") as stderr:
with (
tempfile.NamedTemporaryFile("w+") as content,
tempfile.NamedTemporaryFile("w+") as stdout,
tempfile.NamedTemporaryFile("w+") as stderr,
):
content.write(data)
content.seek(0)

Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Over time, this module could become the interface between
the GUI and the controller.
"""

from contextlib import ExitStack
from gettext import gettext as _
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# Import classes here to make possible to import them from securedrop_client.gui.auth
from securedrop_client.gui.auth.dialog import LoginDialog # noqa: F401
1 change: 1 addition & 0 deletions client/securedrop_client/gui/auth/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import logging
from gettext import gettext as _

Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/auth/sign_in/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# Import classes here to make possible to import them from securedrop_client.gui.auth.sign_in
from securedrop_client.gui.auth.sign_in.button import SignInButton # noqa: F401
from securedrop_client.gui.auth.sign_in.error_bar import LoginErrorBar # noqa: F401
1 change: 1 addition & 0 deletions client/securedrop_client/gui/auth/sign_in/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from gettext import gettext as _

from pkg_resources import resource_string
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/auth/sign_in/error_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from pkg_resources import resource_string
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QHBoxLayout, QWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# Import classes here to make possible to import them from securedrop_client.gui.auth.use_offline
from securedrop_client.gui.auth.use_offline.button import LoginOfflineLink # noqa: F401
1 change: 1 addition & 0 deletions client/securedrop_client/gui/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# Import classes here to make possible to import them from securedrop_client.gui.base
from securedrop_client.gui.base.buttons import SDPushButton # noqa: F401
from securedrop_client.gui.base.dialogs import ModalDialog # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/base/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from typing import NewType, Optional

from PyQt5.QtWidgets import QPushButton, QWidget
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/base/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Consists of a QCheckBox and a QLabel positioned horizontally within a QFrame.
Present in the Sign-in and Export Dialog.
"""

from gettext import gettext as _

from pkg_resources import resource_string
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/base/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from gettext import gettext as _

from pkg_resources import resource_string
Expand Down
1 change: 1 addition & 0 deletions client/securedrop_client/gui/base/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from PyQt5.QtWidgets import QLineEdit, QWidget


Expand Down