Skip to content

Commit

Permalink
feat: Upgrade to Python 3.11 (#43)
Browse files Browse the repository at this point in the history
* Set python 3.11.0 for pyenv

* Update pipenv to require Python 3.11

* Use `increase-if-necessary` for Dependabot updates

https://github.blog/changelog/2022-10-24-reduce-dependabot-version-updates-in-your-python-projects-with-the-increase-if-necessary-strategy/

* Add a handful of missing type annotations

* Add mypy config file

* Update GHA workflows to use Python 3.11

* Update Pylint to use Python 3.11

* Update Python version referenced in README to 3.11

* Work around setup-python version not supporting 3.11 yet

actions/setup-python#213 (comment)

* Revert "Work around setup-python version not supporting 3.11 yet"

This reverts commit fa55503.
  • Loading branch information
Nadock authored Oct 26, 2022
1 parent 5b0a277 commit b4ce557
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ updates:
interval: weekly
time: "07:00"
timezone: Australia/Adelaide
versioning-strategy: increase-if-necessary
labels:
- dependencies
- python
Expand All @@ -31,6 +32,7 @@ updates:
interval: weekly
time: "07:00"
timezone: Australia/Adelaide
versioning-strategy: increase-if-necessary
labels:
- dependencies
- nodejs
2 changes: 1 addition & 1 deletion .github/workflows/deploy_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install Python dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- uses: actions/setup-node@v3
with:
Expand Down
1 change: 0 additions & 1 deletion .pyenv

This file was deleted.

2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs=0

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.10
py-version=3.11


[MESSAGES CONTROL]
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.0
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ types-markdown = "~=3.4.2"
types-pyyaml = "~=6.0.12"

[requires]
python_version = "3.10"
python_version = "3.11"
22 changes: 11 additions & 11 deletions Pipfile.lock

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img alt="Deploy website" src="https://github.com/Nadock/rileychase.net/actions/workflows/deploy_website.yml/badge.svg">
</a>
<a href="https://github.com/Nadock/rileychase.net/blob/main/Pipfile">
<img alt="Python 3.10" src="https://img.shields.io/github/pipenv/locked/python-version/Nadock/rileychase.net">
<img alt="Python 3.11" src="https://img.shields.io/github/pipenv/locked/python-version/Nadock/rileychase.net">
</a>
<a href="https://github.com/psf/black">
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
Expand All @@ -27,7 +27,7 @@ The rest of this `README` contains notes and instructions for me to run my local

## Development Environment Setup

To work on the site content or the `site_generator` you will need a working install of Python 3.10 and Pipenv.
To work on the site content or the `site_generator` you will need a working install of Python 3.11 and Pipenv.

1. Clone the repo
2. Setup a Pipenv venv with `pipenv install --dev`
Expand Down
18 changes: 18 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[mypy]
pretty=True
show_error_codes=True

; Semi-strict mode
warn_unused_configs=True
disallow_untyped_calls=True
; disallow_untyped_defs=True
; disallow_incomplete_defs=True
check_untyped_defs=True
disallow_untyped_decorators=True
no_implicit_optional=True
warn_redundant_casts=True
warn_unused_ignores=True
warn_return_any=True
; no_implicit_reexport=True
strict_equality=True
strict_concatenate=True
9 changes: 5 additions & 4 deletions site_generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
import asyncio
import pathlib
import sys
from typing import Callable

from site_generator import commands, config, errors, logging


class SiteGeneratorCLI:
# pylint: disable=missing-class-docstring, too-few-public-methods

def __init__(self):
def __init__(self) -> None:
self.root_parser = argparse.ArgumentParser(
prog="site_generator", add_help=False
)

def _setup_parser(self):
def _setup_parser(self) -> None:
self.root_parser.add_argument(
"--help",
"-h",
Expand Down Expand Up @@ -94,7 +95,7 @@ def _setup_parser(self):
help="Validate source file for semantic errors",
)

def run(self, argv: list[str]):
def run(self, argv: list[str]) -> None:
"""Setup and run `site_generator` CLI from args."""
self._setup_parser()

Expand All @@ -119,7 +120,7 @@ def run(self, argv: list[str]):
except Exception as ex: # pylint: disable=broad-except
errors.log_error(ex)

def _get_command(self, command: str, cfg: config.SiteGeneratorConfig):
def _get_command(self, command: str, cfg: config.SiteGeneratorConfig) -> Callable:
if command == "live":
return commands.live(cfg)
if command == "build":
Expand Down
3 changes: 2 additions & 1 deletion site_generator/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Callable
from site_generator import config, logging, pipeline

LOGGER = logging.getLogger()


def build(cfg: config.SiteGeneratorConfig):
def build(cfg: config.SiteGeneratorConfig) -> Callable:
"""Build CLI command handler; build site once."""

async def _build():
Expand Down
3 changes: 2 additions & 1 deletion site_generator/commands/live.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import functools
from http import server
from typing import Callable

from watchdog import events, observers # type: ignore

Expand All @@ -9,7 +10,7 @@
LOGGER = logging.getLogger()


def live(cfg: config.SiteGeneratorConfig):
def live(cfg: config.SiteGeneratorConfig) -> Callable:
"""Live CLI command handler; build, serve locally, and rebuild site."""

async def _live():
Expand Down
3 changes: 2 additions & 1 deletion site_generator/commands/validate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys
from typing import Callable

from site_generator import config, logging, markdown

LOGGER = logging.getLogger()


def validate(cfg: config.SiteGeneratorConfig):
def validate(cfg: config.SiteGeneratorConfig) -> Callable:
"""Validate CLI command handler; check files for semantic validation issues."""

async def _validate():
Expand Down
2 changes: 1 addition & 1 deletion site_generator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Config(pydantic.BaseConfig):

@pydantic.validator("templates", "pages", "static", "base", "output")
@classmethod
def ensure_directory(cls, path: Optional[pathlib.Path]):
def ensure_directory(cls, path: Optional[pathlib.Path]) -> pathlib.Path | None:
"""Pydantic validator to ensure the specified path is a directory."""
if path is None:
return None
Expand Down
2 changes: 1 addition & 1 deletion site_generator/emoji/_generate_emoji_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import black


def main(): # pylint: disable=missing-function-docstring
def main() -> None: # pylint: disable=missing-function-docstring
if len(sys.argv) != 3:
print(
"usage: emoji_py_gen.py [gemoji_json_path] [output_path]",
Expand Down
2 changes: 1 addition & 1 deletion site_generator/emoji/_generate_emoji_testpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys


def main(): # pylint: disable=missing-function-docstring
def main() -> None: # pylint: disable=missing-function-docstring
if len(sys.argv) != 3:
print(
"usage: emoji_test_gen.py [gemoji_json_path] [output_path]",
Expand Down
2 changes: 1 addition & 1 deletion site_generator/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PipelineError(SiteGeneratorError):
"""Pipeline failure for a specific source file."""


def log_error(ex: Exception):
def log_error(ex: Exception) -> None:
"""Log an exception according to what kind of exception it is."""
if isinstance(ex, SiteGeneratorError):
LOGGER.error(ex)
Expand Down
2 changes: 1 addition & 1 deletion site_generator/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
LOGGER = logging.getLogger()


async def pipeline(cfg: config.SiteGeneratorConfig):
async def pipeline(cfg: config.SiteGeneratorConfig) -> None:
"""Generate the entire site once end-to-end."""
try:
shutil.rmtree(cfg.output)
Expand Down
2 changes: 1 addition & 1 deletion site_generator/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def render_template(templates: pathlib.Path, name: str, **render_kwargs) -


@jinja2.pass_context
def _render_filter(ctx: jinja2.runtime.Context, value: str):
def _render_filter(ctx: jinja2.runtime.Context, value: str) -> str:
if not value:
return value

Expand Down

0 comments on commit b4ce557

Please sign in to comment.