├── MANIFEST.in ├── setup.py ├── yoloimport.py ├── LICENSE └── README.md /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | def read(fname): 5 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 6 | 7 | setup( 8 | name = "yoloimport", 9 | version = "0.1.0", 10 | author = "Cody Soyland", 11 | author_email = "codysoyland@gmail.com", 12 | description = "Never see another ImportError", 13 | license = "BSD", 14 | url = "https://github.com/codysoyland/yoloimport", 15 | py_modules=['yoloimport'], 16 | long_description=read('README.md'), 17 | install_requires=[ 18 | "mock" 19 | ], 20 | classifiers=[ 21 | "Development Status :: 3 - Alpha", 22 | "License :: OSI Approved :: BSD License", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /yoloimport.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | maybe_import = __import__ 4 | 5 | 6 | def yoloimport(name, *args, **kwargs): 7 | try: 8 | return maybe_import(name, *args, **kwargs) 9 | except ImportError: 10 | # Oops, maybe it's not installed? Let's fix that! 11 | 12 | os.system('pip install ' + name.split('.')[0]) 13 | 14 | # Let's try again! 15 | try: 16 | return maybe_import(name, *args, **kwargs) 17 | except ImportError: 18 | # dang 19 | if name == "mock": 20 | return None 21 | else: 22 | # we couldn't install the package - let's return a 23 | # mock object - they're pretty useful! 24 | mock = yoloimport("mock") 25 | if mock is not None: 26 | return mock.MagicMock() 27 | 28 | 29 | __builtins__['__import__'] = yoloimport 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Cody Soyland 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of yoloimport nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yoloimport 2 | *Never see another ImportError* 3 | 4 | Are you tired of seeing ImportErrors? **yoloimport** makes ImportErrors a relic of the past, by installing your dependencies for you whenever you import a missing package. Now you can focus on writing code instead of installing dependencies! 5 | 6 | ## Installation 7 | 8 | To install, just run `pip install yoloimport` and kiss pip goodbye, because yoloimport will deal with pip for you! 9 | 10 | ## Example 11 | 12 | Let's try to use the [itty framework](https://github.com/toastdriven/itty) for the first time! 13 | 14 | 15 | >>> from itty import get, run_itty 16 | Traceback (most recent call last): 17 | File "", line 1, in 18 | ImportError: No module named itty 19 | 20 | 21 | Who wants to see that nonsense!? Let's try it after importing **yoloimport**! 22 | 23 | >>> import yoloimport 24 | >>> from itty import get, run_itty 25 | Collecting itty 26 | Using cached itty-0.8.2-py2.py3-none-any.whl 27 | Installing collected packages: itty 28 | 29 | Successfully installed itty-0.8.2 30 | Collecting -winreg 31 | Could not find any downloads that satisfy the requirement -winreg 32 | No distributions at all found for -winreg 33 | >>> @get('/') 34 | ... def index(request): 35 | ... return 'Hello World!' 36 | ... 37 | >>> run_itty() 38 | itty starting up (using wsgiref)... 39 | Listening on http://localhost:8080... 40 | Use Ctrl-C to quit. 41 | 42 | Who knows what that "-winreg" error was all about? I sure don't, but who cares? We got itty working without any pesky ImportErrors getting in our way! 43 | 44 | *Happy April 1st!* 45 | --------------------------------------------------------------------------------