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

Fix "sre_constants.error: bogus escape: '\\U'" on Windows #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix "sre_constants.error: bogus escape: '\\U'" on Windows #26

wants to merge 1 commit into from

Conversation

ColinDuquesnoy
Copy link

Here is the traceback I had on Windows:

C:\Users\colin>boss create ./helloworld -t boss:python
Project Description: Spam
Project Name: Eggs
Project Creator Email: [email protected]
Python Module Name: eggs
Version: 1
License: MIT
Project Url: http://spam-some.eggs
Project Creator: EggSpammer
Traceback (most recent call last):
  File "C:\Python34\Scripts\boss-script.py", line 9, in <module>
    load_entry_point('boss==0.9.20', 'console_scripts', 'boss')()
  File "C:\Python34\lib\site-packages\boss\cli\main.py", line 62, in main
    app.run()
  File "C:\Python34\lib\site-packages\cement\core\foundation.py", line 764, in run
    self.controller._dispatch()
  File "C:\Python34\lib\site-packages\cement\core\controller.py", line 472, in _dispatch
    return func()
  File "C:\Python34\lib\site-packages\boss\cli\controllers\base.py", line 73, in create
    src.create_from_template(source, template, self.app.pargs.extra[0])
  File "C:\Python34\lib\site-packages\boss\cli\source.py", line 63, in create_from_template
    tmpl.copy(dest_dir)
  File "C:\Python34\lib\site-packages\boss\cli\template.py", line 269, in copy
    dest_path = fs.abspath(re.sub(self.basedir, dest_basedir, tmpl_path))
  File "C:\Python34\lib\re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Python34\lib\re.py", line 294, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python34\lib\sre_compile.py", line 568, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Python34\lib\sre_parse.py", line 760, in parse
    p = _parse_sub(source, pattern, 0)
  File "C:\Python34\lib\sre_parse.py", line 370, in _parse_sub
    itemsappend(_parse(source, state))
  File "C:\Python34\lib\sre_parse.py", line 730, in _parse
    code = _escape(source, this, state)
  File "C:\Python34\lib\sre_parse.py", line 361, in _escape
    raise error("bogus escape: %s" % repr(escape))
sre_constants.error: bogus escape: '\\U'

C:\Users\colin>

My solution is simply to replace \\ by /

This issue was originally reported in HackEdit/hackedit#14

Here is the traceback I had:

```
C:\Users\colin>boss create ./helloworld -t boss:python
Project Description: Spam
Project Name: Eggs
Project Creator Email: [email protected]
Python Module Name: eggs
Version: 1
License: MIT
Project Url: http://spam-some.eggs
Project Creator: EggSpammer
Traceback (most recent call last):
  File "C:\Python34\Scripts\boss-script.py", line 9, in <module>
    load_entry_point('boss==0.9.20', 'console_scripts', 'boss')()
  File "C:\Python34\lib\site-packages\boss\cli\main.py", line 62, in main
    app.run()
  File "C:\Python34\lib\site-packages\cement\core\foundation.py", line 764, in run
    self.controller._dispatch()
  File "C:\Python34\lib\site-packages\cement\core\controller.py", line 472, in _dispatch
    return func()
  File "C:\Python34\lib\site-packages\boss\cli\controllers\base.py", line 73, in create
    src.create_from_template(source, template, self.app.pargs.extra[0])
  File "C:\Python34\lib\site-packages\boss\cli\source.py", line 63, in create_from_template
    tmpl.copy(dest_dir)
  File "C:\Python34\lib\site-packages\boss\cli\template.py", line 269, in copy
    dest_path = fs.abspath(re.sub(self.basedir, dest_basedir, tmpl_path))
  File "C:\Python34\lib\re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Python34\lib\re.py", line 294, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python34\lib\sre_compile.py", line 568, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Python34\lib\sre_parse.py", line 760, in parse
    p = _parse_sub(source, pattern, 0)
  File "C:\Python34\lib\sre_parse.py", line 370, in _parse_sub
    itemsappend(_parse(source, state))
  File "C:\Python34\lib\sre_parse.py", line 730, in _parse
    code = _escape(source, this, state)
  File "C:\Python34\lib\sre_parse.py", line 361, in _escape
    raise error("bogus escape: %s" % repr(escape))
sre_constants.error: bogus escape: '\\U'

C:\Users\colin>
```

My solution is simply to replace '\\' by '/'.

This issue was originally reported in HackEdit/hackedit#14
@ColinDuquesnoy
Copy link
Author

The failing test is not related to this PR. It's just that coverage >= 4.0 doesn't support py32 anymore...

@derks
Copy link
Member

derks commented Nov 17, 2015

Thank you for the pull request. Is this issue specific to the path, or is it broken using any standard path?

@ColinDuquesnoy
Copy link
Author

Yes, it happens with any standard "windows" path. I tried with a few official boss templates and my owns, all failed with the same traceback.

@ColinDuquesnoy
Copy link
Author

You can reproduce this bug with the following code:

>>> basedir = r'C:\Users\reneg\.boss\cache\tmp0yyrefpr\python'
>>> tmpl = r'C:\Users\reneg\.boss\cache\tmp0yyrefpr\python\README.md'
>>> destir = 'D:\Documents\helloworld'
>>> import re
>>> re.sub(basedir, destdir, tmpl)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Python34\lib\re.py", line 294, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python34\lib\sre_compile.py", line 568, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Python34\lib\sre_parse.py", line 760, in parse
    p = _parse_sub(source, pattern, 0)
  File "C:\Python34\lib\sre_parse.py", line 370, in _parse_sub
    itemsappend(_parse(source, state))
  File "C:\Python34\lib\sre_parse.py", line 730, in _parse
    code = _escape(source, this, state)
  File "C:\Python34\lib\sre_parse.py", line 361, in _escape
    raise error("bogus escape: %s" % repr(escape))
sre_constants.error: bogus escape: '\\U'
>>>

Running the boss test suite on windows lead to a test failing for the same reason:

D:\Documents\boss>python setup.py test
running test
running egg_info
writing requirements to boss.egg-info\requires.txt
writing dependency_links to boss.egg-info\dependency_links.txt
writing namespace_packages to boss.egg-info\namespace_packages.txt
writing boss.egg-info\PKG-INFO
writing top-level names to boss.egg-info\top_level.txt
writing entry points to boss.egg-info\entry_points.txt
reading manifest file 'boss.egg-info\SOURCES.txt'
writing manifest file 'boss.egg-info\SOURCES.txt'
running build_ext
C:\Python34\lib\site-packages\nose\config.py:264: RuntimeWarning: Option 'with-coverage' in config file 'setup.cfg' ignored: excluded by runtime environment
  warn(msg, RuntimeWarning)
C:\Python34\lib\site-packages\nose\config.py:264: RuntimeWarning: Option 'cover-package' in config file 'setup.cfg' ignored: excluded by runtime environment
  warn(msg, RuntimeWarning)
C:\Python34\lib\site-packages\nose\config.py:264: RuntimeWarning: Option 'cover-erase' in config file 'setup.cfg' ignored: excluded by runtime environment
  warn(msg, RuntimeWarning)
C:\Python34\lib\site-packages\nose\config.py:264: RuntimeWarning: Option 'cover-html' in config file 'setup.cfg' ignored: excluded by runtime environment
  warn(msg, RuntimeWarning)
C:\Python34\lib\site-packages\nose\config.py:264: RuntimeWarning: Option 'cover-html-dir' in config file 'setup.cfg' ignored: excluded by runtime environment
  warn(msg, RuntimeWarning)
test_00_add_source (tests.cli.cli_tests.CLITestCase) ... ok
test_01_add_local_source (tests.cli.cli_tests.CLITestCase) ... ok
test_01_sync (tests.cli.cli_tests.CLITestCase) ... Cloning into 'C:\Users\reneg\AppData\Local\Temp\tmpxrzrjz5a\cache\tmphdr3um34'...
remote: Counting objects: 758, done.
Receiving objects:  88% (668/758)    0 (delta 0), pack-reused 758
Receiving objects: 100% (758/758), 241.01 KiB | 0 bytes/s, done.
Resolving deltas: 100% (247/247), done.
Checking connectivity... done.
Already up-to-date.
ok
test_add_source_bad_arguments (tests.cli.cli_tests.CLITestCase) ... ok
test_clean (tests.cli.cli_tests.CLITestCase) ... 'touch' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
ok
test_clean_missing_project (tests.cli.cli_tests.CLITestCase) ... ok
test_cli (tests.cli.cli_tests.CLITestCase) ... ok
test_create_bad_destination (tests.cli.cli_tests.CLITestCase) ... ok
test_create_default_source (tests.cli.cli_tests.CLITestCase) ... D:\Documents\boss\boss\cli\template.py:87: ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\reneg\\AppData\\Local\\Temp\\tmpxrzrjz5a\\cache\\tmphdr3um34\\python\\boss.yml' mode='r' encoding='cp1252'>
  return yaml.load(open(full_path, 'r'))
ERROR
test_create_from_local_source (tests.cli.cli_tests.CLITestCase) ... D:\Documents\boss\boss\cli\template.py:87: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Documents\\boss\\tests\\templates\\python\\boss.yml' mode='r' encoding='cp1252'>
  return yaml.load(open(full_path, 'r'))
C:\Python34\lib\site-packages\cement\ext\ext_logging.py:284: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
  self.backend.warn(msg, **kwargs)
WARNING: File Exists: D:\Documents\boss\tests\templates\python\README
WARNING: File Exists: D:\Documents\boss\tests\templates\python\README
WARNING: File Exists: D:\Documents\boss\tests\templates\python\requirements.txt
WARNING: File Exists: D:\Documents\boss\tests\templates\python\requirements.txt
WARNING: File Exists: D:\Documents\boss\tests\templates\python\setup.cfg
WARNING: File Exists: D:\Documents\boss\tests\templates\python\setup.cfg
WARNING: File Exists: D:\Documents\boss\tests\templates\python\setup.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\setup.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\test_python_module\__init__.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\test_python_module\__init__.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\tests\test_test_python_module.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\tests\test_test_python_module.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\tests\test_test_python_module.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\tests\test_test_python_module.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\test_python_module\__init__.py
WARNING: File Exists: D:\Documents\boss\tests\templates\python\test_python_module\__init__.py
INFO: Writing: C:\Users\reneg\AppData\Local\Temp\tmplm5ykyke\dest\.gitignore
INFO: Writing: C:\Users\reneg\AppData\Local\Temp\tmplm5ykyke\dest\.gitignore
INFO: Writing: C:\Users\reneg\AppData\Local\Temp\tmplm5ykyke\dest\LICENSE
INFO: Writing: C:\Users\reneg\AppData\Local\Temp\tmplm5ykyke\dest\LICENSE
ok
test_create_missing_template (tests.cli.cli_tests.CLITestCase) ... ok
test_default (tests.cli.cli_tests.CLITestCase) ... ok
test_list_sources (tests.cli.cli_tests.CLITestCase) ... ok
test_list_templates (tests.cli.cli_tests.CLITestCase) ... ok
test_rm_source (tests.cli.cli_tests.CLITestCase) ... ok
test_rm_source_bad_label (tests.cli.cli_tests.CLITestCase) ... ok
test_rm_source_no_label (tests.cli.cli_tests.CLITestCase) ... ok
test_zz_missing_data_dir (tests.cli.cli_tests.CLITestCase) ... ERROR
tests.cli.cli_tests.get_test_app ... ok
test_main_argument_error (tests.cli.main_tests.CLIMainTestCase) ... ok
test_main_no_args (tests.cli.main_tests.CLIMainTestCase) ... ok
test_main_template_error (tests.cli.main_tests.CLIMainTestCase) ... ERROR
test_boss_argument_error (tests.core.exc_tests.ExceptionTestCase) ... ok
test_boss_config_error (tests.core.exc_tests.ExceptionTestCase) ... ok
test_boss_error (tests.core.exc_tests.ExceptionTestCase) ... ok
test_boss_runtime_error (tests.core.exc_tests.ExceptionTestCase) ... ok
test_boss_template_error (tests.core.exc_tests.ExceptionTestCase) ... ok

======================================================================
ERROR: test_create_default_source (tests.cli.cli_tests.CLITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\Documents\boss\tests\cli\cli_tests.py", line 181, in test_create_default_source
    app.run()
  File "C:\Python34\lib\site-packages\cement\core\foundation.py", line 764, in run
    self.controller._dispatch()
  File "C:\Python34\lib\site-packages\cement\core\controller.py", line 472, in _dispatch
    return func()
  File "D:\Documents\boss\boss\cli\controllers\base.py", line 73, in create
    src.create_from_template(source, template, self.app.pargs.extra[0])
  File "D:\Documents\boss\boss\cli\source.py", line 63, in create_from_template
    tmpl.copy(dest_dir)
  File "D:\Documents\boss\boss\cli\template.py", line 265, in copy
    dest_path = fs.abspath(re.sub(self.basedir, dest_basedir, tmpl_path))
  File "C:\Python34\lib\re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "C:\Python34\lib\re.py", line 294, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python34\lib\sre_compile.py", line 568, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Python34\lib\sre_parse.py", line 760, in parse
    p = _parse_sub(source, pattern, 0)
  File "C:\Python34\lib\sre_parse.py", line 370, in _parse_sub
    itemsappend(_parse(source, state))
  File "C:\Python34\lib\sre_parse.py", line 730, in _parse
    code = _escape(source, this, state)
  File "C:\Python34\lib\sre_parse.py", line 361, in _escape
    raise error("bogus escape: %s" % repr(escape))
sre_constants.error: bogus escape: '\\U'

======================================================================
ERROR: test_zz_missing_data_dir (tests.cli.cli_tests.CLITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\Documents\boss\tests\cli\cli_tests.py", line 247, in test_zz_missing_data_dir
    shutil.rmtree(app.config.get('boss', 'data_dir'))
  File "C:\Python34\lib\shutil.py", line 478, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Python34\lib\shutil.py", line 368, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 368, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 368, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 368, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 368, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 373, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Python34\lib\shutil.py", line 371, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Accès refusé: 'C:\\Users\\reneg\\AppData\\Local\\Temp\\tmpxrzrjz5a\\cache\\tmphdr3um34\\.git\\objects\\pack\\pack-4b76ccc9fd353d1a700a4a770b536e5bdfb8296c.idx'

======================================================================
ERROR: test_main_template_error (tests.cli.main_tests.CLIMainTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python34\lib\shelve.py", line 111, in __getitem__
    value = self.cache[key]
KeyError: 'sources'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\nose\tools\nontrivial.py", line 60, in newfunc
    func(*arg, **kw)
  File "D:\Documents\boss\tests\cli\main_tests.py", line 18, in test_main_template_error
    main(['create', '-t', 'bogus:bogus_template', self.tmp_dir])
  File "D:\Documents\boss\boss\cli\main.py", line 62, in main
    app.run()
  File "C:\Python34\lib\site-packages\cement\core\foundation.py", line 764, in run
    self.controller._dispatch()
  File "C:\Python34\lib\site-packages\cement\core\controller.py", line 472, in _dispatch
    return func()
  File "D:\Documents\boss\boss\cli\controllers\base.py", line 62, in create
    sources = self.app.db.get('sources')
  File "C:\Python34\lib\shelve.py", line 106, in get
    return self[key]
  File "C:\Python34\lib\shelve.py", line 114, in __getitem__
    value = Unpickler(f).load()
EOFError: Ran out of input

----------------------------------------------------------------------
Ran 27 tests in 4.426s

FAILED (errors=3)

@derks
Copy link
Member

derks commented Dec 13, 2015

Thank you! I've finally learned how to get Windows up and running with Vagrant so I will be able to look into this now. Really appreciate the input.

@x007007007
Copy link

x007007007 commented Dec 12, 2016

hi, I try to fix window path bug, #31 , I think re.sub parse '\' as a escape character , but we should consider *nix can have '\' character in a path. I don't think replace \ to / is good solution

@sdanielson-cxp
Copy link

Better fix dest_path = fs.abspath(re.sub(self.basedir.replace('\', '/'), dest_basedir.replace('\', '/'), tmpl_path.replace('\', '/'))).

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.

4 participants