simple command-line parser of GitHub Linguist Ruby program.
Project description
linguist-python
Pure Python command-line wrapper of Ruby-based Github Linguist.
Linguist detects the language of a Git repo based on the commit
ed files.
The repo file
.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
-
Install Linguist as usual:
gem install github-linguist
-
Install this Python wrapper:
pip install ghlinguist
Usage
From Terminal:
ghlinguist
Or import as a Python module.
import ghlinguist as ghl
langs = 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:
ghlinguist -t
or as a Python module:
import ghlinguist as ghl
lang = ghl.linguist('~/mypath', rpath=True)
Both cases simply return the string Python
or Fortran
etc.
Notes
ghLinguist parses text output from
GitHub Linguist,
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:
-
setup RubyGems:
apt install --no-install-recommends ruby-dev libssl-dev libicu-dev zlib1g-dev libcurl4-openssl-dev gem update --system
-
be sure Gems are installed to home directory, NOT system (no sudo) by adding to
~/.bashrc
:# Install Ruby Gems to ~/gems export GEM_HOME=$HOME/gems export PATH=$HOME/gems/bin:$PATH
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ghlinguist-1.0.1.tar.gz
.
File metadata
- Download URL: ghlinguist-1.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | feaa17a49de01c8177da236cce6edc11ab0445f2ea74621683f10f44073656bc |
|
MD5 | 6be0d4a9a617dd930f180ff0c773bc7b |
|
BLAKE2b-256 | 81f7562cbce5790577f8bdd0dd44f0f59c8646d45ab21845a2cef148099d9c1a |