Skip to content

Conversation

@artfwo
Copy link

@artfwo artfwo commented Mar 13, 2014

This commit fixes some minor issues that arise when importing rdflib in a Py3 environment. Compatibility with at least Python 2.6 is verified.

@joernhees
Copy link
Member

hmm, isn't this handled by py2to3 in setup.py? I wonder how all the tests in the python3 environments on travis pass otherwise?!?

@artfwo
Copy link
Author

artfwo commented Mar 13, 2014

It is handled by setup, but that won't work if you can't predict which Python version will be used to run the program (we ship rdflib bundled with a LibreOffice plugin, and a version built specifically for Python 2 or 3 will break things depending on which Python is used in at runtime).

In this patch, I tried to follow the style of compatibility hacks already found in some rdflib modules, thus assuming a pull request is at least worth proposing, although may need additional work to make sure all the parsers/stores work in either Python.

@joernhees
Copy link
Member

yes, it's definitely worth proposing, i'm just not sure how far we should go trying to recreate py2to3 within rdflib at runtime, in how many different places and if your fix is enough to achieve your goal.

just a thought:
maybe a centralized embedded py2to3 call doing the magic at import time of rdflib in the scenario you describe makes more sense and leads to cleaner code? (so at import time rdflib being built for py2 could check if it's run by py3, issue a warning, but then invoke py2to3 on itself as graceful degradation).

Another thought:
you could bundle rdflib twice, once for a py2, once for a py3 environment and then have a dynamic loader which decides... this might be the better solution as i'm sure you won't only have the problem with rdflib...

@gromgull
Copy link
Member

The theory of 2to3 was that you would port your code-base once, and then work on the new one. Using it like we do, to continously convert the code at install time is a bit of a pain in the neck, it makes it very awkward to actually develop on py3.

So does this make the code so py3 compatible that the tests pass without running 2to3 first?

@artfwo
Copy link
Author

artfwo commented Mar 13, 2014

I'm getting a lot of errors when running tests on either raw or prepared sources (./run_tests_py3.sh). At least some of the errors are seemingly unrelated to py3: undefined identifiers, etc. but few of them are py3-related syntax errors.

The patch above only touches the few modules used by https://github.com/commonsmachinery/libcredit , and tested to work under py2 or py3. I could probably extend it to cover remaining modules if you guys don't object the "get rid of 2to3" idea and that doesn't conflict with any general rdflib plans.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 307678c on commonsmachinery:master into 00b153a on RDFLib:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 307678c on commonsmachinery:master into 00b153a on RDFLib:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 307678c on commonsmachinery:master into 00b153a on RDFLib:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 307678c on commonsmachinery:master into 00b153a on RDFLib:master.

@gromgull
Copy link
Member

I'm getting a lot of errors when running tests on either raw or prepared sources

Then your setup is somehow broken. On Travis both 3.2 and 3.3 pass fine: https://travis-ci.org/RDFLib/rdflib/builds/20659051

Running tests on the raw sources with py3 is unlikely to work.

If we want to make a codebase that "natively" supports both 2 and 3, we could look into https://pypi.python.org/pypi/six - it does a lot of what our py3compat layer also does and more.

@gweis
Copy link
Member

gweis commented Mar 15, 2014

Hi,

I think six could be really helpful to clean up packaging. It seems a bit
messy to me currently.

Cheers,

Gerhard

Sent from my iPad

On 14 Mar 2014, at 5:05 pm, Gunnar Aastrand Grimnes <
notifications@github.com> wrote:

I'm getting a lot of errors when running tests on either raw or prepared
sources

Then your setup is somehow broken. On Travis both 3.2 and 3.3 pass fine:
https://travis-ci.org/RDFLib/rdflib/builds/20659051

Running tests on the raw sources with py3 is unlikely to work.

If we want to make a codebase that "natively" supports both 2 and 3, we
could look into https://pypi.python.org/pypi/six - it does a lot of what
our py3compat layer also does and more.


Reply to this email directly or view it on
GitHubhttps://github.com//pull/373#issuecomment-37621628
.

@dbs
Copy link
Contributor

dbs commented Mar 17, 2014

+1 to outsourcing the runtime compatibility layer to six; html5lib appears to be using it successfully

@joernhees
Copy link
Member

ok, uhm shall we close this pull request and open a branch for moving things to six then?

@artfwo
Copy link
Author

artfwo commented Mar 18, 2014

Fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants