Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/type-checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Type Checking

on:
push:
branches: [ master ]
pull_request:
branches: [ '*' ]

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[dev]"

- name: Run mypy
run: |
mypy powerplantmatching
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ doc/_build
doc/api
.vscode
test.ipynb

# temporary
.devcontainer/
.repoai/
12 changes: 6 additions & 6 deletions powerplantmatching/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
"downloaders": {},
}

makedirs(join(package_config["data_dir"], "data", "in"), exist_ok=True)
makedirs(join(package_config["data_dir"], "data", "out"), exist_ok=True)
makedirs(join(str(package_config["data_dir"]), "data", "in"), exist_ok=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change for this PR, but just the note that we wanna move to pathlib in general. Not sure if mypy would be happy without the str cast then

makedirs(join(str(package_config["data_dir"]), "data", "out"), exist_ok=True)


def _package_data(fn):
return join(package_config["repo_data_dir"], fn)


def _data_in(fn):
return join(package_config["data_dir"], "data", "in", fn)
return join(str(package_config["data_dir"]), "data", "in", fn)


def _data_out(fn, config):
if config is None:
directory = join(package_config["data_dir"], "data", "out", "default")
directory = join(str(package_config["data_dir"]), "data", "out", "default")
else:
directory = join(package_config["data_dir"], "data", "out", config["hash"])
directory = join(str(package_config["data_dir"]), "data", "out", config["hash"])
makedirs(directory, exist_ok=True)
return join(directory, fn)

Expand All @@ -60,7 +60,7 @@ def _data_out(fn, config):
logFormatter = logging.Formatter(
"%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s"
)
fileHandler = logging.FileHandler(join(package_config["data_dir"], "PPM.log"))
fileHandler = logging.FileHandler(join(str(package_config["data_dir"]), "PPM.log"))
fileHandler.setFormatter(logFormatter)
logger.addHandler(fileHandler)
# logger.info('Initialization complete.')
Expand Down
3 changes: 2 additions & 1 deletion powerplantmatching/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import cycler, rcParams
from cycler import cycler
from matplotlib import rcParams
from matplotlib.legend_handler import HandlerPatch
from matplotlib.lines import Line2D

Expand Down
47 changes: 46 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ docs= [
"nbsphinx",
"sphinx-automodapi",
]
dev= ["pre-commit", "pytest", "pytest-cov"]
dev= [
"pre-commit",
"pytest",
"pytest-cov",
"mypy",
"types-requests",
"types-PyYAML",
"pandas-stubs",
"types-tqdm",
"types-six"
]

# Add optional dependencies for plotting
plotting= [
"cartopy"
]

# setuptools_scm settings

Expand Down Expand Up @@ -92,3 +107,33 @@ select = [
'TID', # flake8-tidy-imports
'NPY', # numpy
]

# Add basic mypy configuration
[tool.mypy]
python_version = "3.9"
warn_unused_configs = true
disallow_untyped_defs = false
disallow_incomplete_defs = false
# Ignore class-level imports in accessor.py
disable_error_code = ["misc"]

# Ignore missing imports for external libraries
[[tool.mypy.overrides]]
module = [
"matplotlib.*",
"seaborn.*",
"networkx.*",
"pycountry.*",
"country_converter.*",
"geopy.*",
"unidecode.*",
"entsoe.*",
"yaml.*",
"scipy.*",
"pandas.*",
"tqdm.*",
"deprecation.*",
"cartopy.*",
"six.*",
]
ignore_missing_imports = true