From 1803592b89f58530d5e9de3e20fb261e62b38cde Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 29 Nov 2021 10:51:51 -0700 Subject: [PATCH] fix: adds mypy and corrects type hinting errors --- .github/workflows/build.yml | 8 ++------ .github/workflows/release.yml | 2 +- CHANGELOG.md | 4 ++++ Makefile | 8 ++++++-- github_archive/archive.py | 8 ++++---- github_archive/py.typed | 0 setup.py | 4 +++- test/unit/test_archive.py | 8 ++++---- 8 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 github_archive/py.typed diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e809898..8d35ba7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c41d31..161d2d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 73cac2c..150535f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Makefile b/Makefile index f9c26b6..ffd551d 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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 diff --git a/github_archive/archive.py b/github_archive/archive.py index 28c1740..b982cb3 100644 --- a/github_archive/archive.py +++ b/github_archive/archive.py @@ -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, @@ -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: @@ -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 = [] @@ -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 = [] diff --git a/github_archive/py.typed b/github_archive/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index 0a69a41..bf899d9 100644 --- a/setup.py +++ b/setup.py @@ -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.' ), @@ -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", diff --git a/test/unit/test_archive.py b/test/unit/test_archive.py index 755dfdf..51024ce 100644 --- a/test/unit/test_archive.py +++ b/test/unit/test_archive.py @@ -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 @@ -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 @@ -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 @@ -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