Full Code of nvbn/import_from_github_com for AI

master 7668a0954ed4 cached
8 files
5.0 KB
1.4k tokens
13 symbols
1 requests
Download .txt
Repository: nvbn/import_from_github_com
Branch: master
Commit: 7668a0954ed4
Files: 8
Total size: 5.0 KB

Directory structure:
gitextract_d64dhyhs/

├── .gitignore
├── LICENSE
├── README.md
├── github_com/
│   └── __init__.py
├── requirements.txt
├── setup.py
└── tests/
    ├── __init__.py
    └── test_github_com.py

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

.idea


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2016 Vladimir Iakovlev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



================================================
FILE: README.md
================================================
# Import from `github_com` (Please don't use it)

Experimental Python module finder/loader from github, like in golang.

So, in golang we can import like:

```go
import "github.com/parnurzeal/gorequest"
```

But in python we should install package by our hands:

```bash
pip install requests
```

And import it like:

```python
import requests
```

But with this magic package and power of [PEP-0302](https://www.python.org/dev/peps/pep-0302/) we can
do it automatically:

```python
from github_com.kennethreitz import requests

assert requests.get('https://github.com/nvbn/import_from_github_com').status_code == 200
```

## Installation

You should have git, Python 3.2+ and pip:

```bash
pip install import_from_github_com
```

## License MIT
Project License can be found [here](LICENSE.md).


================================================
FILE: github_com/__init__.py
================================================
import sys
import pip


class IntermediateModule:
    """Module for paths like `github_com.nvbn`."""

    def __init__(self, fullname):
        self.__package__ = fullname
        self.__path__ = fullname.split('.')
        self.__name__ = fullname


class GithubComFinder:
    """Handles `github_com....` modules."""

    def find_module(self, module_name, package_path):
        if module_name.startswith('github_com'):
            return GithubComLoader()


class GithubComLoader:
    """Installs and imports modules from github."""

    def _is_installed(self, fullname):
        try:
            self._import_module(fullname)
            return True
        except ImportError:
            return False

    def _import_module(self, fullname):
        actual_name = '.'.join(fullname.split('.')[2:])
        return __import__(actual_name)

    def _install_module(self, fullname):
        if not self._is_installed(fullname):
            url = fullname.replace('.', '/') \
                .replace('github_com', 'git+https://github.com', 1)
            pip.main(['install', url])

    def _is_repository_path(self, fullname):
        return fullname.count('.') == 2

    def _is_intermediate_path(self, fullname):
        return fullname.count('.') < 2

    def load_module(self, fullname):
        if self._is_repository_path(fullname):
            self._install_module(fullname)

        if self._is_intermediate_path(fullname):
            module = IntermediateModule(fullname)
        else:
            module = self._import_module(fullname)

        sys.modules[fullname] = module


sys.meta_path.append(GithubComFinder())


================================================
FILE: requirements.txt
================================================
pytest


================================================
FILE: setup.py
================================================
#!/usr/bin/env python
import sys
from setuptools import setup, find_packages

if sys.version_info < (3, 2):
    raise Exception('Only Python 3.2+ is supported')

setup(name='import_from_github_com',
      version='0.1',
      description="Python module finder/loader from github, like in golang",
      author='Vladimir Iakovlev',
      author_email='nvbn.rm@gmail.com',
      url='https://github.com/nvbn/import_from_github_com',
      license='MIT',
      packages=find_packages(exclude=['ez_setup', 'examples',
                                      'tests', 'release']),
      include_package_data=True,
      zip_safe=False)


================================================
FILE: tests/__init__.py
================================================


================================================
FILE: tests/test_github_com.py
================================================
def test_import_module():
    from github_com.kennethreitz import requests

    assert requests.get('https://github.com').status_code == 200


def test_import_from_module():
    from github_com.kennethreitz.requests import get

    assert get('https://github.com').status_code == 200
Download .txt
gitextract_d64dhyhs/

├── .gitignore
├── LICENSE
├── README.md
├── github_com/
│   └── __init__.py
├── requirements.txt
├── setup.py
└── tests/
    ├── __init__.py
    └── test_github_com.py
Download .txt
SYMBOL INDEX (13 symbols across 2 files)

FILE: github_com/__init__.py
  class IntermediateModule (line 5) | class IntermediateModule:
    method __init__ (line 8) | def __init__(self, fullname):
  class GithubComFinder (line 14) | class GithubComFinder:
    method find_module (line 17) | def find_module(self, module_name, package_path):
  class GithubComLoader (line 22) | class GithubComLoader:
    method _is_installed (line 25) | def _is_installed(self, fullname):
    method _import_module (line 32) | def _import_module(self, fullname):
    method _install_module (line 36) | def _install_module(self, fullname):
    method _is_repository_path (line 42) | def _is_repository_path(self, fullname):
    method _is_intermediate_path (line 45) | def _is_intermediate_path(self, fullname):
    method load_module (line 48) | def load_module(self, fullname):

FILE: tests/test_github_com.py
  function test_import_module (line 1) | def test_import_module():
  function test_import_from_module (line 7) | def test_import_from_module():
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".gitignore",
    "chars": 709,
    "preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\n"
  },
  {
    "path": "LICENSE",
    "chars": 1085,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2016 Vladimir Iakovlev\n\nPermission is hereby granted, free of charge, to any person"
  },
  {
    "path": "README.md",
    "chars": 795,
    "preview": "# Import from `github_com` (Please don't use it)\n\nExperimental Python module finder/loader from github, like in golang.\n"
  },
  {
    "path": "github_com/__init__.py",
    "chars": 1633,
    "preview": "import sys\nimport pip\n\n\nclass IntermediateModule:\n    \"\"\"Module for paths like `github_com.nvbn`.\"\"\"\n\n    def __init__(s"
  },
  {
    "path": "requirements.txt",
    "chars": 7,
    "preview": "pytest\n"
  },
  {
    "path": "setup.py",
    "chars": 629,
    "preview": "#!/usr/bin/env python\nimport sys\nfrom setuptools import setup, find_packages\n\nif sys.version_info < (3, 2):\n    raise Ex"
  },
  {
    "path": "tests/__init__.py",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "tests/test_github_com.py",
    "chars": 284,
    "preview": "def test_import_module():\n    from github_com.kennethreitz import requests\n\n    assert requests.get('https://github.com'"
  }
]

About this extraction

This page contains the full source code of the nvbn/import_from_github_com GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (5.0 KB), approximately 1.4k tokens, and a symbol index with 13 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!