Skip to content

Commit

Permalink
Proper typing, igraph update, rest of tooling (Ruff, mypy, etc.) (#41)
Browse files Browse the repository at this point in the history
* Migrate to pyproject.toml

* auto apply formatting

* ruff check auto fixes

* ruff check fixes

* Copyright update

* from __future__ import annotations

* pyupgrade >= 3.9

* Add typing

* fix errors

* bump igraph, add typing for igraph via 3rdparty-typestubs

* Type fixes for skytemple_files compatibility

* add ruff and mypy to requirements

* make sure to create pytest.xml

* Typing issues Python < 3.11

* fixup typing_extensions imports
  • Loading branch information
theCapypara authored Jun 27, 2024
1 parent 35bfbf4 commit 63bfcd8
Show file tree
Hide file tree
Showing 155 changed files with 4,463 additions and 2,715 deletions.
144 changes: 116 additions & 28 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,162 @@
# Deploys to PyPi on "release".
name: Build, test and publish

on: [push, pull_request]
on:
push:
branches:
- master
- release
- version/*
tags:
- "*"
pull_request: { }

jobs:
linting:
runs-on: ubuntu-latest
name: Linting
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with ruff
run: ruff check --output-format=github .

code-formatting:
runs-on: ubuntu-latest
name: Code Format
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: install ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Check with ruff
run: ruff format --check .

typechecks:
runs-on: ubuntu-latest
name: Type checks
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- uses: theCapypara/mypy-check@rust-support
name: Run type checks
with:
path: 'explorerscript'
mypy_flags: '--config-file mypy.ini --junit-xml mypy-${{ matrix.python-version }}.xml'
requirements: '-r requirements.txt'
python_version: '${{ matrix.python-version }}'
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: MyPy Test Results (Python ${{ matrix.python-version }})
path: mypy-${{ matrix.python-version }}.xml

test:
runs-on: ubuntu-latest
name: Runs tests
strategy:
max-parallel: 5
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install tox tox-gh-actions
- uses: dtolnay/rust-toolchain@stable
- name: Test with tox
run: tox -- -m "not romtest"
- run: mv pytest.xml pytest-${{ matrix.python-version }}.xml
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: "Pytest Test Results (Python ${{ matrix.python-version }})"
path: pytest-${{ matrix.python-version }}.xml

test-event-file:
name: "Publish Test Results Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}

build:
needs: test
needs:
- test
- typechecks
runs-on: ubuntu-latest
name: Build the Python wheel
steps:
# For tags we assume the version in setup.py is correct!
# For tags we assume the version in pyproject.toml is correct!
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Rewrite version for dev if not tag
if: "!startsWith(github.ref, 'refs/tags/')"
run: |
perl -i -pe "s/__version__\s*=\s*'(.*?)(rc.*|a.*|post.*)?'/__version__='\1.dev0+${GITHUB_SHA::8}'/" setup.py
perl -i -pe "s/version\s*=\s*\"(.*?)(\.rc.*|\.a.*|\.post.*)?\"/version=\"\1.dev0+${GITHUB_SHA::8}\"/" pyproject.toml
- name: Note version
run: |
echo "PACKAGE_VERSION=$(python3 -- ./setup.py --version)" >> $GITHUB_ENV
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
echo "PACKAGE_VERSION=$(tomlq '.project.version' pyproject.toml -r)" >> $GITHUB_ENV
- name: Build Python wheels
uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312'
- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wheels
path: dist/*.whl

deploy:
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
name: Deploy wheels to PyPI
steps:
- name: Download wheels
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: wheels
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Upgrade pip
python-version: "3.11"
- name: Upgrade pip and install Twine
run: |
python -m pip install --upgrade pip
pip install twine
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include explorerscript/py.typed
recursive-include explorerscript/antlr *
61 changes: 26 additions & 35 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: noqa
# type: ignore
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
Expand All @@ -18,17 +20,15 @@


# -- Project information -----------------------------------------------------
import sys, os

project = 'ExplorerScript'
copyright = '2020, Parakoopa'
author = 'Parakoopa'
project = "ExplorerScript"
copyright = "2024, Capypara"
author = "Capypara"

# The short X.Y version
version = ''
version = ""
# The full version, including alpha/beta/rc tags
release = ''

release = ""

# -- General configuration ---------------------------------------------------

Expand All @@ -39,22 +39,19 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.viewcode',
'explorerscript.pygments.expslexer'
]
extensions = ["sphinx.ext.viewcode", "explorerscript.pygments.expslexer"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -71,13 +68,13 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

Expand All @@ -90,7 +87,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -106,24 +103,20 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ExplorerScriptDoc'

htmlhelp_basename = "ExplorerScriptDoc"

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -133,33 +126,32 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ExplorerScript.tex', 'ExplorerScript Documentation',
'Parakoopa', 'manual'),
(master_doc, "ExplorerScript.tex", "ExplorerScript Documentation", "Parakoopa", "manual"),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'explorerscript', 'ExplorerScript Documentation',
[author], 1)
]

man_pages = [(master_doc, "explorerscript", "ExplorerScript Documentation", [author], 1)]

# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ExplorerScript', 'ExplorerScript Documentation',
author, 'ExplorerScript', 'Script language for decompiled SSB (Pokémon Mystery Dungeon Explorers of Sky)',
'Miscellaneous'),
(
master_doc,
"ExplorerScript",
"ExplorerScript Documentation",
author,
"ExplorerScript",
"Script language for decompiled SSB (Pokémon Mystery Dungeon Explorers of Sky)",
"Miscellaneous",
),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
Expand All @@ -175,8 +167,7 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

epub_exclude_files = ["search.html"]

# -- Extension configuration -------------------------------------------------

Expand Down
Loading

0 comments on commit 63bfcd8

Please sign in to comment.