From 928a223841f4409768c81d2f761ee9fe00637bc1 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Wed, 1 May 2019 14:58:26 -0400 Subject: [PATCH] ci template pep8 better exe find doc travis xenial --- .appveyor.yml | 4 ++-- .coveragerc | 20 ++++++++++++++++++++ .flake8 | 3 +++ .travis.yml | 38 +++++++++++++++++++------------------- README.md | 16 ++++++++++++---- ghlinguist/__init__.py | 11 +++++++---- mypy.ini | 4 ++++ setup.cfg | 28 +--------------------------- 8 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 .coveragerc create mode 100644 .flake8 create mode 100644 mypy.ini diff --git a/.appveyor.yml b/.appveyor.yml index 8fe5e4d..89ce7c5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,13 +1,13 @@ image: #- Visual Studio 2017 # how to setup ssl-dev etc. -- Ubuntu +- Ubuntu1804 stack: python 3 environment: PY_DIR: C:\Python37-x64 -clone_depth: 3 +clone_depth: 25 build: off diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..8c7574f --- /dev/null +++ b/.coveragerc @@ -0,0 +1,20 @@ +[run] +cover_pylib = false +omit = + /home/travis/virtualenv/* + */site-packages/* + */bin/* + +[report] +exclude_lines = + pragma: no cover + def __repr__ + except RuntimeError + except NotImplementedError + except ImportError + except FileNotFoundError + except CalledProcessError + logging.warning + logging.error + logging.critical + if __name__ == __main__: \ No newline at end of file diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..c1daeba --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 132 +exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8e495d6..a479b9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,11 @@ language: python group: travis_latest +dist: xenial git: - depth: 3 + depth: 25 quiet: true -python: -- 3.6 - -os: -- linux - env: GEM_HOME=$HOME/gems PATH=$HOME/gems/bin:$PATH addons: @@ -19,20 +14,25 @@ addons: - ruby-dev - libssl-dev +matrix: + include: + - os: linux + python: 3.6 + after_success: + - pytest --cov + - coveralls + - os: linux + python: 3.7 + install: + - pip install -e .[tests,cov] + script: + - flake8 + - mypy . + + install: - gem install github-linguist --no-document - pip install -e .[tests] -- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then pip install -e .[cov]; fi script: -- pytest -rsv - -- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then flake8; fi -- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then mypy . --ignore-missing-imports; fi - -after_success: -- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then - pytest --cov --cov-config=setup.cfg; - coveralls; - fi - +- pytest -rsv \ No newline at end of file diff --git a/README.md b/README.md index a963fd5..a66d865 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,26 @@ Simple Python command-line wrapper of Ruby-based Github Linguist. [Linguist](https://github.com/github/linguist) (and hence this Python wrapper) detect the language of a Git repo, based on the `commit`ed files -[`.gitattributes`](https://github.com/github/linguist#using-gitattributes) +[`.gitattributes`](https://github.com/github/linguist#using-gitattributes) is used to configure Linguist to not get distracted by `docs` or archive files, etc. using several straightforward rules. This Python wrapper attempts to make Linguist a little more careful by warning users of uncommitted changes or additions that could make Linguist silently give very skewed (inaccurate) results, since Linguist only works on files/changes *after* `git commit`. ## Install +0. Ensure you have Ruby installed. + + * Windows: Windows Subsystem for Linux is recommended. + * Linux: see Notes section at bottom of this README + * MacOS: `brew install ruby` + 1. Install Linguist as usual: + ```sh gem install github-linguist ``` 2. Install Python wrapper: + ```sh pip install -e . ``` @@ -61,8 +69,8 @@ lang = ghl.linguist('~/mypath', rpath=True) Both cases simply return the string `Python` or `Fortran` etc. ## Notes -ghLinguist parses text output from -[GitHub Linguist](https://github.com/github/linguist#using-emacs-or-vim-modelines), +ghLinguist parses text output from +[GitHub Linguist](https://github.com/github/linguist#using-emacs-or-vim-modelines), which is a Ruby program. We call `github-linguist` executable since `linguist` overlaps with QT Lingiust. @@ -72,7 +80,7 @@ If you don't already have RubyGems setup on Linux: 1. setup RubyGems: ```sh apt install ruby-dev libssl-dev libicu-dev zlib1g-dev libcurl4-openssl-dev - + gem update --system ``` 2. be sure Gems are installed to home directory, NOT system (no sudo) by adding to `~/.bashrc`: diff --git a/ghlinguist/__init__.py b/ghlinguist/__init__.py index c40c44d..f3843b0 100644 --- a/ghlinguist/__init__.py +++ b/ghlinguist/__init__.py @@ -2,18 +2,21 @@ import logging from typing import List, Tuple, Union, Optional from pathlib import Path -# takes too long to check if Linguist installed each time +import shutil +EXE = shutil.which('github-linguist') +if not EXE: + raise FileNotFoundError('GitHub Linguist not found, did you install it per README?') -def linguist(path: Path, rtype: bool=False) -> Optional[Union[str, List[Tuple[str, str]]]]: + +def linguist(path: Path, rtype: bool = False) -> Optional[Union[str, List[Tuple[str, str]]]]: path = Path(path).expanduser() if not checkrepo(path): return None - ret = subprocess.check_output(['github-linguist', str(path)], - universal_newlines=True).split('\n') + ret = subprocess.check_output([EXE, str(path)], universal_newlines=True).split('\n') # %% parse percentage lpct = [] diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..bf6bcdf --- /dev/null +++ b/mypy.ini @@ -0,0 +1,4 @@ +[mypy] +ignore_missing_imports = True +strict_optional = False +allow_redefinition = True \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index abea82b..98dbf00 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,30 +44,4 @@ cov = [options.entry_points] console_scripts = - ghlinguist = ghLinguist:main - - -[flake8] -max-line-length = 132 -exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ - -[coverage:run] -cover_pylib = false -omit = - /home/travis/virtualenv/* - */site-packages/* - */bin/* - -[coverage:report] -exclude_lines = - pragma: no cover - def __repr__ - except RuntimeError - except NotImplementedError - except ImportError - except FileNotFoundError - except CalledProcessError - logging.warning - logging.error - logging.critical - if __name__ == .__main__.: + ghlinguist = ghLinguist:main \ No newline at end of file