Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scivision/linguist-python
Detect repo language(s) with thin Python wrapper of Github Linguist
https://github.com/scivision/linguist-python
github linguist python
Last synced: 14 days ago
JSON representation
Detect repo language(s) with thin Python wrapper of Github Linguist
- Host: GitHub
- URL: https://github.com/scivision/linguist-python
- Owner: scivision
- License: mit
- Created: 2018-08-02T17:43:58.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-11-15T17:02:42.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T16:07:56.889Z (about 1 month ago)
- Topics: github, linguist, python
- Language: Python
- Homepage: https://github.com/github/linguist
- Size: 45.9 KB
- Stars: 12
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# linguist-python
![ci](https://github.com/scivision/linguist-python/workflows/ci/badge.svg)
[![pypi versions](https://img.shields.io/pypi/pyversions/ghlinguist.svg)](https://pypi.python.org/pypi/ghlinguist)
[![PyPi Download stats](http://pepy.tech/badge/ghlinguist)](http://pepy.tech/project/ghlinguist)Pure Python command-line wrapper of Ruby-based Github [Linguist](https://github.com/github/linguist).
Linguist detects the language of a Git repo based on the `commit`ed files.
The repo file
[.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 makes Linguist more intuitive by warning users of uncommitted changes or additions that could make Linguist silently give inaccurate results, since Linguist only works on files that have been `git commit`ed.
## Install
Ruby is required for Linguist:
* Windows: Windows Subsystem for Linux is recommended.
* Linux: see Notes section at bottom of this README
* MacOS / Linux Homebrew: `brew install ruby`1. Install Linguist as usual:
```sh
gem install github-linguist
```
2. Install this Python wrapper:```sh
pip install ghlinguist
```## Usage
From Terminal:
```sh
python -m ghlinguist
```Or import as a Python module.
```python
import ghlinguist as ghllangs = ghl.linguist('~/mypath')
```The functions return a list of tuples like:
```
[('Python'), (97.)]
[('Fortran'), (3.)]
```where the second number is the percentage of code detected for that language.
If the directory is not a Git repo, `None` is returned
### Examples
The primary reason behind creating this Python Linguist wrapper is automatically detecting the repo type, so that appropriate templates can be applied *en masse* to a large number of repos.
Thus to get the repo language from the command line, as GitHub would:```sh
python -m ghlinguist -t
```or as a Python module:
```python
import ghlinguist as ghllang = 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),
which is a Ruby program.
We call `github-linguist` executable since `linguist` overlaps with QT Lingiust.### Linux prereqs
If you don't already have RubyGems setup on Linux:
1. setup RubyGems:
```sh
apt install --no-install-recommends ruby-dev libssl-dev libicu-dev zlib1g-dev libcurl4-openssl-devgem update --system
```
2. be sure Gems are installed to home directory, NOT system (no sudo) by adding to `~/.bashrc`:```sh
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
```