Git Me The URL
Git Me The URL is a Python library and command-line tool (CLI) designed to generate sharable links to your Git source code. It currently supports popular Git hosting platforms such as GitHub, GitLab, and Bitbucket. The project, currently at version 2.2.0, maintains an active development status with releases typically focusing on dependency updates, minor enhancements, or internal improvements, including a significant architectural rewrite in version 2.0.0.
Common errors
-
ModuleNotFoundError: No module named 'gitmetheurl'
cause The `git-me-the-url` package is not installed, or the import statement is incorrect.fixEnsure the package is installed: `pip install git-me-the-url`. Check that the import is `from gitmetheurl import GitMeTheURL`. -
git.exc.InvalidGitRepositoryError: 'path/to/your/dir' does not seem to be a git repository
cause The command or Python script is being executed in a directory that is not part of a Git repository, or the specified path is not a Git repository.fixNavigate to the root of your Git repository before running the command, or ensure that the path passed to `get_source_url` is within a valid Git repository. -
UserWarning: pkg_resources is deprecated as an API.
cause This warning occurs in older versions of `git-me-the-url` (prior to 2.1.0) when run with newer Python or `setuptools` versions. `pkg_resources` was removed in Python 3.12 and recent `setuptools` releases.fixUpgrade `git-me-the-url` to version 2.1.0 or newer: `pip install --upgrade git-me-the-url`. If unable to upgrade, you might need to pin an older `setuptools` version, though this is not recommended.
Warnings
- breaking Version 2.0.0 introduced a significant internal rewrite of the URL translator implementations. While the public API for basic usage (e.g., `get_source_url`) might remain largely compatible, any custom URL generators or plugins developed against the older internal structure may break and require updates.
- deprecated Versions prior to 2.1.0 had a dependency on `pkg_resources`. This package is deprecated and has been removed in Python 3.12, which could lead to `UserWarning: pkg_resources is deprecated` messages or import errors in environments with newer Python versions or `setuptools` versions (e.g., setuptools 82+).
- gotcha The library depends on the `git` executable being installed on the system and discoverable in the system's PATH. Without a functional `git` installation, `git-me-the-url` will not be able to interact with repositories, potentially leading to errors originating from its `GitPython` dependency.
Install
-
pip install git-me-the-url
Imports
- GitMeTheURL
from gitmetheurl import GitMeTheURL
Quickstart
import os
from gitmetheurl import GitMeTheURL
# Ensure you are running this code within a local Git repository
# Or provide a specific path to a Git repository
# For demonstration, we assume a file 'my_file.txt' exists in the current repo
gmtu = GitMeTheURL()
# Get a shareable URL for a specific file in the current Git repository
# Replace 'my_file.txt' with an actual file path in your repository
# Example: If running from the root of a repo, use 'README.md'
try:
url = gmtu.get_source_url('README.md')
print(f"Shareable URL for README.md: {url}")
except Exception as e:
print(f"Error generating URL: {e}")
print("Please ensure you are in a Git repository and the file path is correct.")