Skip to content

Commit

Permalink
fix: adds mypy and corrects type hinting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Nov 29, 2021
1 parent c9c31a6 commit 1803592
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"
- name: Install Dependencies
run: make install
- name: Run linting
run: make lint
- name: Check format
run: make format-check
- name: Check imports
run: make isort-check
test:
runs-on: ubuntu-latest
strategy:
matrix:
pythonversion: ["3.7", "3.8", "3.9"]
pythonversion: ["3.7", "3.8", "3.9", "3.10"]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v4.2.2 (2021-11-29)

* Adds `mypy` and fixes typing errors

## v4.2.1 (2021-11-25)

* Bumps `woodchips` to use the new implementation (also fixes a bug where we were creating a new `woodchips.Logger` class each time we called the logger instead of reusing the same logger instance)
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ black-check:
$(VIRTUAL_BIN)/black $(PROJECT_NAME)/ test/ --check

## format - Runs all formatting tools against the project
format: black isort lint
format: black isort lint mypy

## format-check - Checks if the project is formatted correctly against all formatting rules
format-check: black-check isort-check lint
format-check: black-check isort-check lint mypy

## install - Install the project locally
install:
Expand All @@ -54,6 +54,10 @@ isort-check:
lint:
$(VIRTUAL_BIN)/flake8 $(PROJECT_NAME)/ test/

## mypy - Run mypy type checking on the project
mypy:
$(VIRTUAL_BIN)/mypy $(PROJECT_NAME)/ test/

## test - Test the project
test:
$(VIRTUAL_BIN)/pytest
Expand Down
8 changes: 4 additions & 4 deletions github_archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import List

import woodchips
from github import AuthenticatedUser, Gist, Github, Repository
from github import Gist, Github, Repository

from github_archive.constants import (
DEFAULT_LOCATION,
Expand Down Expand Up @@ -193,7 +193,7 @@ def initialize_project(self):
logger.critical(message)
raise ValueError(message)

def authenticated_user_in_users(self) -> AuthenticatedUser.AuthenticatedUser:
def authenticated_user_in_users(self) -> bool:
return self.authenticated_user.login.lower() in self.users

def get_all_git_assets(self, context: str) -> List:
Expand Down Expand Up @@ -239,7 +239,7 @@ def get_all_git_assets(self, context: str) -> List:

return final_sorted_list

def iterate_repos_to_archive(self, repos: Repository.Repository, operation: str):
def iterate_repos_to_archive(self, repos: List[Repository.Repository], operation: str):
"""Iterate over each repository and start a thread if it can be archived."""
thread_limiter = BoundedSemaphore(self.threads)
thread_list = []
Expand All @@ -263,7 +263,7 @@ def iterate_repos_to_archive(self, repos: Repository.Repository, operation: str)
for thread in thread_list:
thread.join()

def iterate_gists_to_archive(self, gists: Gist.Gist, operation: str):
def iterate_gists_to_archive(self, gists: List[Gist.Gist], operation: str):
"""Iterate over each gist and start a thread if it can be archived."""
thread_limiter = BoundedSemaphore(self.threads)
thread_list = []
Expand Down
Empty file added github_archive/py.typed
Empty file.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
'coveralls == 3.*',
'flake8',
'isort',
'mypy',
'pytest == 6.*',
'pytest-cov == 2.*',
]

setuptools.setup(
name='github-archive',
version='4.2.1',
version='4.2.2',
description=(
'A powerful tool to concurrently clone or pull user and org repos and gists to create a GitHub archive.'
),
Expand All @@ -29,6 +30,7 @@
author='Justintime50',
license='MIT',
packages=setuptools.find_packages(),
package_data={'github-archive': ['py.typed']},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def test_archive_repo_clone_exists(mock_logger, mock_subprocess, mock_git_asset)


@patch('shutil.rmtree')
@patch('subprocess.run', side_effect=subprocess.TimeoutExpired(cmd=subprocess.run, timeout=0.1))
@patch('subprocess.run', side_effect=subprocess.TimeoutExpired(cmd='subprocess.run', timeout=0.1))
@patch('logging.Logger.error')
def test_archive_repo_timeout_exception(mock_logger, mock_subprocess, mock_remove_dir, mock_git_asset):
operation = CLONE_OPERATION
Expand All @@ -458,7 +458,7 @@ def test_archive_repo_timeout_exception(mock_logger, mock_subprocess, mock_remov


@patch('shutil.rmtree')
@patch('subprocess.run', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.run))
@patch('subprocess.run', side_effect=subprocess.CalledProcessError(returncode=1, cmd='subprocess.run'))
@patch('logging.Logger.error')
def test_archive_repo_called_process_error(mock_logger, mock_subprocess, mock_remove_dir, mock_git_asset):
operation = PULL_OPERATION
Expand Down Expand Up @@ -495,7 +495,7 @@ def test_archive_gist_clone_exists(mock_logger, mock_subprocess, mock_path_exist


@patch('shutil.rmtree')
@patch('subprocess.run', side_effect=subprocess.TimeoutExpired(cmd=subprocess.run, timeout=0.1))
@patch('subprocess.run', side_effect=subprocess.TimeoutExpired(cmd='subprocess.run', timeout=0.1))
@patch('logging.Logger.error')
def test_archive_gist_timeout_exception(mock_logger, mock_subprocess, mock_remove_dir, mock_git_asset):
operation = CLONE_OPERATION
Expand All @@ -509,7 +509,7 @@ def test_archive_gist_timeout_exception(mock_logger, mock_subprocess, mock_remov


@patch('shutil.rmtree')
@patch('subprocess.run', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.run))
@patch('subprocess.run', side_effect=subprocess.CalledProcessError(returncode=1, cmd='subprocess.run'))
@patch('logging.Logger.error')
def test_archive_gist_called_process_error(mock_logger, mock_subprocess, mock_remove_dir, mock_git_asset):
operation = PULL_OPERATION
Expand Down

0 comments on commit 1803592

Please sign in to comment.