[
  {
    "path": ".gitignore",
    "content": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\nenv/\nbuild/\ndevelop-eggs/\ndist/\ndownloads/\neggs/\n.eggs/\nlib/\nlib64/\nparts/\nsdist/\nvar/\n*.egg-info/\n.installed.cfg\n*.egg\n\n# PyInstaller\n#  Usually these files are written by a python script from a template\n#  before PyInstaller builds the exe, so as to inject date/other infos into it.\n*.manifest\n*.spec\n\n# Installer logs\npip-log.txt\npip-delete-this-directory.txt\n\n# Unit test / coverage reports\nhtmlcov/\n.tox/\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*,cover\n\n# Translations\n*.mo\n*.pot\n\n# Django stuff:\n*.log\n\n# Sphinx documentation\ndocs/_build/\n\n# PyBuilder\ntarget/\n\n.idea\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2016 Vladimir Iakovlev\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# Import from `github_com` (Please don't use it)\n\nExperimental Python module finder/loader from github, like in golang.\n\nSo, in golang we can import like:\n\n```go\nimport \"github.com/parnurzeal/gorequest\"\n```\n\nBut in python we should install package by our hands:\n\n```bash\npip install requests\n```\n\nAnd import it like:\n\n```python\nimport requests\n```\n\nBut with this magic package and power of [PEP-0302](https://www.python.org/dev/peps/pep-0302/) we can\ndo it automatically:\n\n```python\nfrom github_com.kennethreitz import requests\n\nassert requests.get('https://github.com/nvbn/import_from_github_com').status_code == 200\n```\n\n## Installation\n\nYou should have git, Python 3.2+ and pip:\n\n```bash\npip install import_from_github_com\n```\n\n## License MIT\nProject License can be found [here](LICENSE.md).\n"
  },
  {
    "path": "github_com/__init__.py",
    "content": "import sys\nimport pip\n\n\nclass IntermediateModule:\n    \"\"\"Module for paths like `github_com.nvbn`.\"\"\"\n\n    def __init__(self, fullname):\n        self.__package__ = fullname\n        self.__path__ = fullname.split('.')\n        self.__name__ = fullname\n\n\nclass GithubComFinder:\n    \"\"\"Handles `github_com....` modules.\"\"\"\n\n    def find_module(self, module_name, package_path):\n        if module_name.startswith('github_com'):\n            return GithubComLoader()\n\n\nclass GithubComLoader:\n    \"\"\"Installs and imports modules from github.\"\"\"\n\n    def _is_installed(self, fullname):\n        try:\n            self._import_module(fullname)\n            return True\n        except ImportError:\n            return False\n\n    def _import_module(self, fullname):\n        actual_name = '.'.join(fullname.split('.')[2:])\n        return __import__(actual_name)\n\n    def _install_module(self, fullname):\n        if not self._is_installed(fullname):\n            url = fullname.replace('.', '/') \\\n                .replace('github_com', 'git+https://github.com', 1)\n            pip.main(['install', url])\n\n    def _is_repository_path(self, fullname):\n        return fullname.count('.') == 2\n\n    def _is_intermediate_path(self, fullname):\n        return fullname.count('.') < 2\n\n    def load_module(self, fullname):\n        if self._is_repository_path(fullname):\n            self._install_module(fullname)\n\n        if self._is_intermediate_path(fullname):\n            module = IntermediateModule(fullname)\n        else:\n            module = self._import_module(fullname)\n\n        sys.modules[fullname] = module\n\n\nsys.meta_path.append(GithubComFinder())\n"
  },
  {
    "path": "requirements.txt",
    "content": "pytest\n"
  },
  {
    "path": "setup.py",
    "content": "#!/usr/bin/env python\nimport sys\nfrom setuptools import setup, find_packages\n\nif sys.version_info < (3, 2):\n    raise Exception('Only Python 3.2+ is supported')\n\nsetup(name='import_from_github_com',\n      version='0.1',\n      description=\"Python module finder/loader from github, like in golang\",\n      author='Vladimir Iakovlev',\n      author_email='nvbn.rm@gmail.com',\n      url='https://github.com/nvbn/import_from_github_com',\n      license='MIT',\n      packages=find_packages(exclude=['ez_setup', 'examples',\n                                      'tests', 'release']),\n      include_package_data=True,\n      zip_safe=False)\n"
  },
  {
    "path": "tests/__init__.py",
    "content": ""
  },
  {
    "path": "tests/test_github_com.py",
    "content": "def test_import_module():\n    from github_com.kennethreitz import requests\n\n    assert requests.get('https://github.com').status_code == 200\n\n\ndef test_import_from_module():\n    from github_com.kennethreitz.requests import get\n\n    assert get('https://github.com').status_code == 200\n"
  }
]