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

Update dumpstyle.py #824

Merged
merged 2 commits into from Jan 15, 2020
Merged

Update dumpstyle.py #824

merged 2 commits into from Jan 15, 2020

Conversation

tbpassin
Copy link
Contributor

Added from future import absolute_import, and adjusted import statement for Py2-3 compatibility.

Corrected directory location in main routine to be relative to rst2pdf package (os.path.listdir('styles') wouldn't work if we weren't running from the right directory).

Added from __future__ import absolute_import, and adjusted import statement for Py2-3 compatibility.

Corrected directory location in __main__ routine to be relative to rst2pdf package (os.path.listdir('styles') wouldn't work if we weren't running from the right directory).
@tbpassin
Copy link
Contributor Author

Cannot be tested on Windows with autotest, because that only runs on Linux. To test:

py38 -m rst2pdf.dumpstyle # or py27 instead

This must run with no errors. Previous errors I got before I fixed the listdir() were

Traceback (most recent call last):
  File "C:\Users\tom\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\tom\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\Tom\git\rst2pdf\rst2pdf\dumpstyle.py", line 161, in <module>
    for fname in [os.path.join('styles', x) for x in os.listdir('styles') if x.endswith('.json')]:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'styles'

*basestring* doesn't exist in Py3.  Use *str* instead.

Check for presence of basestring to detect py2.7 vs py3+.

Similar import changes needed for pygments2style in order for dumpstyle to run.
@tbpassin
Copy link
Contributor Author

Sorry to have to amend this pull request. This is my first time pushing from a cloned repo, and I'm still getting used to Guthub Desktop.

@akrabat
Copy link
Member

akrabat commented Dec 30, 2019

Can you explain how to test this? i.e. what should I type to see a failure before this change is applied and then after applying, I will see it working?

@tbpassin
Copy link
Contributor Author

Rob, for my test procedure please see my comment at #826. For the dumpstyle module in the Master branch, I got these tracebacks:

C:\Users\tom>py38 -m rst2pdf.dumpstyle
Traceback (most recent call last):
  File "C:\Users\tom\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\tom\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Tom\git\rst2pdf\rst2pdf\dumpstyle.py", line 12, in <module>
    from rson import loads as rloads
ModuleNotFoundError: No module named 'rson'

and for Python 2.7:

C:\Users\tom>python -m rst2pdf.dumpstyle
Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "D:\Tom\git\rst2pdf\rst2pdf\dumpstyle.py", line 160, in <module>
    for fname in [os.path.join('styles', x) for x in os.listdir('styles') if x.endswith('.json')]:
WindowsError: [Error 3] The system cannot find the path specified: 'styles\\*.*'

So for Python3.8, the import of rson failed, and for Python 2.7, the module couldn't find the styles directory. I had to fix both problems to make the module run for both Python versions. I hate to ask for two unrelated changes in one pull request (the import statement, and locating the styles directory), but they are both needed to run successfully.

@maphew maphew mentioned this pull request Jan 3, 2020
@akrabat akrabat closed this in 6344fc6 Jan 15, 2020
@akrabat akrabat merged commit 9884c72 into rst2pdf:master Jan 15, 2020
@akrabat akrabat added this to the 1.0 milestone Jan 15, 2020
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.

None yet

2 participants