Giter Club home page Giter Club logo

Comments (5)

LukasWallrich avatar LukasWallrich commented on May 21, 2024 1

Thanks - there I confused myself with package versions and virtual environments - with the new version, everything works fine!

from httpimport.

LukasWallrich avatar LukasWallrich commented on May 21, 2024

To get this to work again, I had to go all the way back to version 0.7.2 ...

from httpimport.

operatorequals avatar operatorequals commented on May 21, 2024

Hello @LukasWallrich

Thanks a lot for making this Issue! It is the proper chance to document this and make it searchable for others that will certainly have the same problem!

So, after 0.7.2 the syntax of all function signatures changed (for reasons documented here: #39 (comment)). In this answer I'll demonstrate the difference and the way to fix it.

0.7.2

You code snippet should work:

>>> import httpimport
>>> httpimport.__version__
'0.7.2'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>> 
>>> with httpimport.remote_repo(["Gmodel"], url):
...     from Gmodel import GProblem
... 
>>> GProblem
<class 'Gmodel.GProblem'>

>=1.0.0

Your code should fail with the error in the title:

>>> import httpimport
>>> httpimport.__version__
'1.0.0'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>> 
>>> with httpimport.remote_repo(["Gmodel"], url):
...     from Gmodel import GProblem
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
[...]
line 254, in __init__
    self.url = url if not url.endswith('/') else url[:-1]
AttributeError: 'list' object has no attribute 'endswith'

So what happens?

The remote_repo function used to accept a list as a mandatory parameter and a str (the url). After 1.0.0, the list parameter was removed. So now it only accepts the url.

The Fix

Just removing the ["Gmodel"] (the first parameter) from your code *would fix it:

>>> import httpimport
>>> httpimport.__version__
'1.3.0'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>> with httpimport.remote_repo(url): # <-------------- check out the new syntax
...     from Gmodel import GProblem
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ImportError: cannot import name 'GProblem' from 'Gmodel' (https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/Gmodel.py)
>>> 

Yet, you are using the same syntax in the Gist code itself, as shown below:
https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/Gmodel.py - line 1:

# Used this to avoid duplicating files
import httpimport
url = "https://gist.githubusercontent.com/LukasWallrich/05f445821fbae694b37a205dc08b2b4f/raw/"

with httpimport.remote_repo(["HPmodel"], url):
     from HPmodel import HPProblem, PSAgent
[...]

so it fails to import the module using >=1.0.0 as it fetches the Gist code, tries to execute it (to load the new module) and halts with a syntax error in the module code itself.

If you also remove the ["HPmodel"] parameter from the Gist code, it will be able to run using the latest version (1.3.0 at time of writing).

I hope I helped! This is what breaking changes do to a project...

from httpimport.

LukasWallrich avatar LukasWallrich commented on May 21, 2024

Ah, ok - that makes sense. Thank you!

Unfortunately, it still does not work.

If I run

import httpimport
url = "https://gist.githubusercontent.com/LukasWallrich/05f445821fbae694b37a205dc08b2b4f/raw/"

with httpimport.remote_repo(url):
     from HPmodel import HPProblem, PSAgent

I get Exception: Plain HTTP URL provided with 'httpimport.INSECURE' not set - which is rather confusing since the URL is obviously not plain HTML ...

from httpimport.

operatorequals avatar operatorequals commented on May 21, 2024

Plain HTTP URL provided with 'httpimport.INSECURE' not set

This log message doesn't even exist in the >=1.0.0 version! Try updating to 1.3.0 and running again!

What actually happened:

This comes from 0.7.2:
https://github.com/operatorequals/httpimport/blob/0.7.2/httpimport.py#L97

and happens as remote_repo in this version has a default value for the url parameter, which is http://... (you can see here: https://github.com/operatorequals/httpimport/blob/0.7.2/httpimport.py#L329). The whole API is unusable - that's why I changed it!

from httpimport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.