Skip to main content

linguist-python

ci pypi versions PyPi Download stats

Pure Python command-line wrapper of Ruby-based Github Linguist. Linguist detects the language of a Git repo based on the commited 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 commited.

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:

    gem install github-linguist
    
  2. Install this Python wrapper:

    pip install ghlinguist
    

Usage

From Terminal:

python -m 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:

python -m 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:

  1. setup RubyGems:

    apt install --no-install-recommends 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:

    # Install Ruby Gems to ~/gems
    export GEM_HOME=$HOME/gems
    export PATH=$HOME/gems/bin:$PATH
    

Release files for ghlinguist 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghlinguist 1.1.0
File Size Uploaded
ghlinguist-1.1.0.tar.gz 4.9 kB Details

Release files / ghlinguist-1.1.0.tar.gz

Download URL ghlinguist-1.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fd2762d425fd0c86d54879d4a86b5cc6ca82a18b870c7067cf05af976c02fab0
BLAKE2b-256 checksum
How to use checksums
5853234ae47148718d81dd2becde8f8849c2b2e127da0f53f3d30262a62f3e51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page