Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cwd when xsd2py is executed as __main__ and ignore xsd imports #84

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion soapfish/xsd2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def rewrite_paths(schema, cwd, base_path):

def resolve_import(xsdimport, known_files, parent_namespace, cwd, base_path):
location = os.path.join(base_path, xsdimport.schemaLocation)
if not os.path.isfile(location):
return ''
Copy link
Member

@ngnpope ngnpope Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas it is not this simple. If we do not process imports from remote locations, we do not generate code.

I think I have worked out where the issue is now, so should have a solution soon. Unfortunately it requires keeping track of whether an import was local or remote and propagating that state down the tree of imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The external URL must be handled. I didn't had time to work on this issue. It was to ignore these imports:

 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />

I think if no schemaLocation is set, just ignore the import.

cwd = os.path.dirname(location)
logger.info('Generating code for XSD import \'%s\'...' % location)
xml = open_document(location)
Expand Down Expand Up @@ -215,7 +217,9 @@ def main():
from soapfish import xsd
from soapfish.xsd import UNBOUNDED
'''))
code = generate_code_from_xsd(xmlelement, encoding='utf-8')

cwd = os.path.dirname(os.path.abspath(opt.xsd))
code = generate_code_from_xsd(xmlelement, encoding='utf-8', cwd=cwd)
# In Python 3 encoding a string returns bytes so we have to write the
# generated code to sys.stdout.buffer instead of sys.stdout.
# We should not depend on Python 3's "auto-conversion to console charset"
Expand Down