Commit ccba80cc authored by Vasili's avatar Vasili

Check types

parent b4280040
......@@ -137,6 +137,30 @@ optional = false
python-versions = ">=3.5"
version = "8.5.0"
[[package]]
category = "dev"
description = "Optional static typing for Python"
name = "mypy"
optional = false
python-versions = ">=3.5"
version = "0.782"
[package.dependencies]
mypy-extensions = ">=0.4.3,<0.5.0"
typed-ast = ">=1.4.0,<1.5.0"
typing-extensions = ">=3.7.4"
[package.extras]
dmypy = ["psutil (>=4.0)"]
[[package]]
category = "dev"
description = "Experimental type system extensions for programs checked with the mypy typechecker."
name = "mypy-extensions"
optional = false
python-versions = "*"
version = "0.4.3"
[[package]]
category = "dev"
description = "Core utilities for Python packages"
......@@ -319,12 +343,19 @@ version = "0.5.11"
[[package]]
category = "dev"
description = "a fork of Python 2 and 3 ast modules with type comment support"
marker = "implementation_name == \"cpython\" and python_version < \"3.8\""
name = "typed-ast"
optional = false
python-versions = "*"
version = "1.4.1"
[[package]]
category = "dev"
description = "Backported and Experimental Type Hints for Python 3.5+"
name = "typing-extensions"
optional = false
python-versions = "*"
version = "3.7.4.3"
[[package]]
category = "dev"
description = "ASCII transliterations of Unicode text"
......@@ -363,7 +394,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
testing = ["jaraco.itertools", "func-timeout"]
[metadata]
content-hash = "e75934de9c7ac18e84ec7e4bd692cfd600adedfe5305989a592f6fbe409d2969"
content-hash = "184ec7bd80b010027dff1b8190700662da33cfdc0f253f77ed9c4b1d8d4764de"
lock-version = "1.0"
python-versions = "^3.6"
......@@ -438,6 +469,26 @@ more-itertools = [
{file = "more-itertools-8.5.0.tar.gz", hash = "sha256:6f83822ae94818eae2612063a5101a7311e68ae8002005b5e05f03fd74a86a20"},
{file = "more_itertools-8.5.0-py3-none-any.whl", hash = "sha256:9b30f12df9393f0d28af9210ff8efe48d10c94f73e5daf886f10c4b0b0b4f03c"},
]
mypy = [
{file = "mypy-0.782-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:2c6cde8aa3426c1682d35190b59b71f661237d74b053822ea3d748e2c9578a7c"},
{file = "mypy-0.782-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9c7a9a7ceb2871ba4bac1cf7217a7dd9ccd44c27c2950edbc6dc08530f32ad4e"},
{file = "mypy-0.782-cp35-cp35m-win_amd64.whl", hash = "sha256:c05b9e4fb1d8a41d41dec8786c94f3b95d3c5f528298d769eb8e73d293abc48d"},
{file = "mypy-0.782-cp36-cp36m-macosx_10_6_x86_64.whl", hash = "sha256:6731603dfe0ce4352c555c6284c6db0dc935b685e9ce2e4cf220abe1e14386fd"},
{file = "mypy-0.782-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:f05644db6779387ccdb468cc47a44b4356fc2ffa9287135d05b70a98dc83b89a"},
{file = "mypy-0.782-cp36-cp36m-win_amd64.whl", hash = "sha256:b7fbfabdbcc78c4f6fc4712544b9b0d6bf171069c6e0e3cb82440dd10ced3406"},
{file = "mypy-0.782-cp37-cp37m-macosx_10_6_x86_64.whl", hash = "sha256:3fdda71c067d3ddfb21da4b80e2686b71e9e5c72cca65fa216d207a358827f86"},
{file = "mypy-0.782-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d7df6eddb6054d21ca4d3c6249cae5578cb4602951fd2b6ee2f5510ffb098707"},
{file = "mypy-0.782-cp37-cp37m-win_amd64.whl", hash = "sha256:a4a2cbcfc4cbf45cd126f531dedda8485671545b43107ded25ce952aac6fb308"},
{file = "mypy-0.782-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6bb93479caa6619d21d6e7160c552c1193f6952f0668cdda2f851156e85186fc"},
{file = "mypy-0.782-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:81c7908b94239c4010e16642c9102bfc958ab14e36048fa77d0be3289dda76ea"},
{file = "mypy-0.782-cp38-cp38-win_amd64.whl", hash = "sha256:5dd13ff1f2a97f94540fd37a49e5d255950ebcdf446fb597463a40d0df3fac8b"},
{file = "mypy-0.782-py3-none-any.whl", hash = "sha256:e0b61738ab504e656d1fe4ff0c0601387a5489ca122d55390ade31f9ca0e252d"},
{file = "mypy-0.782.tar.gz", hash = "sha256:eff7d4a85e9eea55afa34888dfeaccde99e7520b51f867ac28a48492c0b1130c"},
]
mypy-extensions = [
{file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
]
packaging = [
{file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"},
{file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"},
......@@ -517,6 +568,11 @@ typed-ast = [
{file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"},
{file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"},
]
typing-extensions = [
{file = "typing_extensions-3.7.4.3-py2-none-any.whl", hash = "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"},
{file = "typing_extensions-3.7.4.3-py3-none-any.whl", hash = "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918"},
{file = "typing_extensions-3.7.4.3.tar.gz", hash = "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c"},
]
unidecode = [
{file = "Unidecode-1.1.1-py2.py3-none-any.whl", hash = "sha256:1d7a042116536098d05d599ef2b8616759f02985c85b4fef50c78a5aaf10822a"},
{file = "Unidecode-1.1.1.tar.gz", hash = "sha256:2b6aab710c2a1647e928e36d69c21e76b453cd455f4e2621000e54b2a9b8cce8"},
......
......@@ -14,6 +14,7 @@ yapf = "^0.30.0"
pytest = "^6.0.2"
pytest-mock = "^3.3.1"
tbump = "^6.1.1"
mypy = "^0.782"
[tool.poetry.scripts]
git-cu = 'git_cu.main:main'
......
......@@ -5,7 +5,9 @@ import argparse
import logging
import os
import sys
from argparse import Namespace
from pathlib import PurePath
from typing import List
from urllib.parse import urlparse
from git_cu import __version__ as VERSION
......@@ -17,7 +19,7 @@ class UrlParseError(Exception):
'''Raised when parsing a URL fails'''
def parse_args(args):
def parse_args(args: List) -> Namespace:
'''Parses command line options. Returns a Namespace.'''
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--version', action='version', version=VERSION)
......@@ -37,7 +39,7 @@ def parse_args(args):
return parser.parse_args(args)
def git_cu(url, clone_args, dry_run):
def git_cu(url: str, clone_args: List, dry_run: bool) -> None:
'''Invokes git clone for 'url' with arguments 'clone_args'.
If 'dry_run' is True git clone is not actually executed'''
if '..' in url:
......@@ -77,7 +79,7 @@ def git_cu(url, clone_args, dry_run):
sys.exit(1)
def main():
def main() -> None:
'''Entry point. Parses command line arguments, sets up logging, and runs application.'''
args = parse_args(sys.argv[1:])
if args.debug:
......@@ -90,18 +92,18 @@ def main():
git_cu(args.url, args.args, args.dry_run)
def assemble_path(host, urlpath):
def assemble_path(host: str, urlpath: str) -> PurePath:
'''Returns a PurePath to clone into given a hostname and url path'''
path = urlpath
if path.endswith('.git'):
path = path[:-4]
path = path.split('/')
path = PurePath(host, *path)
logger.debug('%s -> %s', urlpath, path)
return path
components = path.split('/')
result = PurePath(host, *components)
logger.debug('%s -> %s', urlpath, result)
return result
def parse(url):
def parse(url: str) -> PurePath:
'''Returns a destination path from a URL.'''
try:
parsed = urlparse(url)
......@@ -117,7 +119,7 @@ def parse(url):
return assemble_path(host, parsed.path)
def parse_scp(url):
def parse_scp(url: str) -> PurePath:
'''Returns a destination path from an scp-style URL.'''
host, path = url.split(':', maxsplit=1)
logger.debug('host: %s path: %s', host, path)
......@@ -126,19 +128,19 @@ def parse_scp(url):
return assemble_path(host, path)
def is_url(url):
def is_url(url: str) -> bool:
'''Returns True if url looks like a URL, otherwise False.
See https://www.git-scm.com/docs/git-clone#URLS for details'''
return '://' in url
def is_scp(url):
def is_scp(url: str) -> bool:
'''Returns True if url looks like an scp-style URL, otherwise False.
See https://www.git-scm.com/docs/git-clone#URLS for details'''
return ':' in url and not '/' in url.split(':')[0]
def get_dest_dir(url):
def get_dest_dir(url: str) -> PurePath:
'''Returns a destination directory based on url.'''
if is_url(url):
parser = parse
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment