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

Adds type hints throughout Hatchet and integrate checks with mypy #153

Open
wants to merge 5 commits into
base: develop
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
41 changes: 41 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM continuumio/miniconda3:24.9.2-0

USER root

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=1000
ENV USERNAME=${USERNAME}
ENV USER_UID=${USER_UID}
ENV USER_GID=${USER_GID}

RUN apt-get update -q \
&& apt-get install -q -y --no-install-recommends \
build-essential \
ripgrep \
pandoc \
adduser \
git \
grep \
curl \
wget \
vim

RUN conda install -y python=3.9 \
&& pip install --no-cache-dir pipx \
&& pipx reinstall-all

RUN conda install -c conda-forge gh jupyterlab

COPY requirements.txt /requirements.txt

RUN python3 -m pip install -r requirements.txt

RUN python3 -m pip install --upgrade flake8-pytest-importorskip click==8.0.4 black==24.4.2 flake8==4.0.1 mypy==1.13.0

RUN groupadd -g ${USER_GID} ${USERNAME} && \
adduser --disabled-password --uid ${USER_UID} --gid ${USER_GID} --gecos "" ${USERNAME} && \
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers

USER $USERNAME

81 changes: 81 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
{
"name": "Hatchet Python 3.9",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},
// "features": {
// // "ghcr.io/devcontainers/features/git:1": {
// // "ppa": true,
// // "version": "os-provided"
// // },
// // "ghcr.io/devcontainers/features/git-lfs:1": {
// // "autoPull": true,
// // "version": "latest"
// // },
// "ghcr.io/devcontainers/features/github-cli:1": {
// "installDirectlyFromGitHubRelease": true,
// "version": "latest"
// }
// // "ghcr.io/devcontainers/features/python:1": {
// // "installTools": true,
// // "toolsToInstall": "autopep8,yapf,pydocstyle,pycodestyle,bandit,pytest,pylint",
// // "enableShared": true,
// // "installJupyterlab": true,
// // "version": "3.9"
// // },
// // "ghcr.io/devcontainers-extra/features/act:1": {
// // "version": "latest"
// // },
// // "ghcr.io/devcontainers-extra/features/curl-apt-get:1": {},
// // "ghcr.io/devcontainers-extra/features/fd:1": {
// // "version": "latest"
// // },
// // "ghcr.io/devcontainers-extra/features/fzf:1": {
// // "version": "latest"
// // },
// // "ghcr.io/devcontainers-extra/features/ripgrep:1": {
// // "version": "latest"
// // },
// // "ghcr.io/devcontainers-extra/features/wget-apt-get:1": {}
// },
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.black-formatter",
"ms-python.flake8",
"dbaeumer.vscode-eslint",
"ms-python.debugpy",
"ms-toolsai.jupyter"
],
"settings": {
"python.defaultInterpreterPath": "/opt/conda/bin/python3",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/opt/conda/bin/black",
"black-formatter.path": [
"/opt/conda/bin/black"
]
}
}
},
"remoteEnv": {
"PATH": "/opt/conda/bin:${containerEnv:PATH}",
"EDITOR": "/usr/bin/vim"
}
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "echo \"export PATH=$CURRENT_PYTHON_BINDIR:\\$PATH\" >> ~/.bashrc"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
8 changes: 7 additions & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ jobs:
python setup.py build_ext --inplace
python -m pip list

- name: Update Black
- name: Update Black and mypy
if: ${{ matrix.python-version == 3.9 }}
run: |
pip install flake8-pytest-importorskip
pip install --upgrade click==8.0.4
pip install black==24.4.2
pip install flake8==4.0.1
pip install mypy==1.13.0

- name: Lint and Format Check with Flake8 and Black
if: ${{ matrix.python-version == 3.9 }}
run: |
black --diff --check .
flake8

- name: Run type checking with mypy
if: ${{ matrix.python-version == 3.9 }}
run: |
mypy hatchet --pretty

- name: Check License Headers
run: |
Expand Down
165 changes: 159 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,169 @@
*.pyc
.cache
.pytest_cache
.ipynb_checkpoints

build
docs/_build
hatchet/cython_modules/libs/graphframe_modules.*.so
hatchet/cython_modules/libs/reader_modules.*.so
hatchet/cython_modules/*.c
hatchet/vis/*node_modules*
hatchet/vis/static/*_bundle*
*package-lock.json

###############################################
# Everything from here on comes from the GitHub
# gitignore template for Python projects
###############################################

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
llnl_hatchet.egg-info/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
33 changes: 18 additions & 15 deletions hatchet/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# SPDX-License-Identifier: MIT

from typing import TYPE_CHECKING


class VersionError(Exception):
"""
Expand All @@ -13,23 +15,24 @@ class VersionError(Exception):
pass


try:
import IPython
if not TYPE_CHECKING:
try:
import IPython

# Testing IPython version
if int(IPython.__version__.split(".")[0]) > 7:
raise VersionError()
# Testing IPython version
if int(IPython.__version__.split(".")[0]) > 7:
raise VersionError()

from .roundtrip.roundtrip.manager import Roundtrip
from .roundtrip.roundtrip.manager import Roundtrip

# Refrencing Roundtrip here to resolve scope issues with import
Roundtrip
# Refrencing Roundtrip here to resolve scope issues with import
Roundtrip

except ImportError:
pass
except ImportError:
pass

except VersionError:
if IPython.get_ipython() is not None:
print(
"Warning: Roundtrip module could not be loaded. Requires jupyter notebook version <= 7.x."
)
except VersionError:
if IPython.get_ipython() is not None:
print(
"Warning: Roundtrip module could not be loaded. Requires jupyter notebook version <= 7.x."
)
Loading