Skip to content

Commit

Permalink
ci template
Browse files Browse the repository at this point in the history
pep8

better exe find

doc

travis xenial
  • Loading branch information
scivision committed May 1, 2019
1 parent ed2be83 commit 928a223
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 20 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -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__:
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
38 changes: 19 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
```
Expand Down Expand Up @@ -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.

Expand All @@ -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`:
Expand Down
11 changes: 7 additions & 4 deletions ghlinguist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mypy]
ignore_missing_imports = True
strict_optional = False
allow_redefinition = True
28 changes: 1 addition & 27 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 928a223

Please sign in to comment.