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

chore: add type annotations #3794

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Makefile for running mypy type checks, tests, flake8 checks, and ruff formatting

# Variables
PYTHON = python3
MYPY = mypy
MYPY_CONFIG = mypy.ini
SOURCE_DIR = ./nikola
TEST_DIR = ./tests
TEST_RUNNER = pytest
FLAKE8 = flake8
RUFF = ruff # Ruff linter/formatter

# Default target
.PHONY: all
all: check test lint format

# Check types with mypy
.PHONY: check
check:
@echo "Running mypy type checks..."
$(MYPY) --config-file $(MYPY_CONFIG) $(SOURCE_DIR)

# Run tests with pytest
.PHONY: test
test:
@echo "Running tests..."
$(TEST_RUNNER) $(TEST_DIR)

# Run flake8 checks
.PHONY: lint
lint:
@echo "Running flake8 checks..."
$(FLAKE8) $(SOURCE_DIR) $(TEST_DIR)

# Run ruff checks and formatting
.PHONY: format
format:
@echo "Running Ruff for formatting and linting..."
$(RUFF) check $(SOURCE_DIR) $(TEST_DIR) # Change 'check' to 'fix' if you want to auto-fix issues

# Clean up (optional)
.PHONY: clean
clean:
@echo "Cleaning up..."
# You can add commands to remove unwanted files if needed

# Help
.PHONY: help
help:
@echo "Makefile commands:"
@echo " check - Run mypy type checks"
@echo " test - Run tests using pytest"
@echo " lint - Run flake8 checks on source and tests"
@echo " format - Run Ruff for formatting and linting"
@echo " clean - Clean up (optional)"
@echo " help - Show this help message"
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mypy]
ignore_missing_imports = True
strict = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disable_error_code = no-untyped-call, misc
9 changes: 5 additions & 4 deletions nikola/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@

import os
import sys
from typing import Final

__version__ = '8.3.1'
DEBUG = bool(os.getenv('NIKOLA_DEBUG'))
SHOW_TRACEBACKS = bool(os.getenv('NIKOLA_SHOW_TRACEBACKS'))
__version__: Final[str] = "8.3.1"
DEBUG: bool = bool(os.getenv("NIKOLA_DEBUG"))
SHOW_TRACEBACKS: bool = bool(os.getenv("NIKOLA_SHOW_TRACEBACKS"))

if sys.version_info[0] == 2:
raise Exception("Nikola does not support Python 2.")

from .nikola import Nikola # NOQA
from . import plugins # NOQA
from .nikola import Nikola # NOQA
Loading