Thursday, June 1, 2017

django-admin makemessages PermissionError [WindError 32] and OsError [Errno 22]

Hi,

I am using custom fabric script to make .po-files for i18n.

The problem is, "django-admin makemessages" keeps on crashing. It also leaves undeleted .html.py files. I can reproduce this error also by using plain "django-admin makemessages -l pt". 

I think this problem in Windows-specific. I am using 64-bit Windows 10, Django 1.11, Fabric3 1.13.1.post1, and Windows Powershell 5.1.14393.1198.

Any help would be appreciated.

Br,

np

"Minimal working example":
 - Crashed on third try. Sometimes it complains about "locale\django.pot" being used by another process, too. Fourth try worked fine.

(<my_project>) PS C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\bases> django-admin makemessages -l pt
processing locale pt
(<my_project>) PS C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\bases> django-admin makemessages -l pt
processing locale pt
(<my_project>) PS C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\bases> django-admin makemessages -l pt
Traceback (most recent call last):
  File "C:\Users\<User>\Miniconda3\Lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\<User>\Miniconda3\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python\VirtualEnv\<my_project>\Scripts\django-admin.exe\__main__.py", line 9, in <module>
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 360, in handle
    potfiles = self.build_potfiles()
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 402, in build_potfiles
    self.process_files(file_list)
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 499, in process_files
    self.process_locale_dir(locale_dir, files)
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 594, in process_locale_dir
    build_file.cleanup()
  File "c:\python\virtualenv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 157, in cleanup
    os.unlink(self.work_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '.\\base.html.py'
(<my_project>) PS C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\bases>

Real-usage example

Fabric code:
def translate(appfolder=None):
    """
    Use django-admin makemessages to make .po files

    INPUTS:
        folder: pathlib.Path object for the folder where to start.
            Used for recursion. (in normal usage, no 'folder' parameter
            is provided.)
    """
    forbidden = ('__pycache__', 'migrations', 'locale', 'utils', 'static')
    if not appfolder:
        appfolder = Path(__file__).parent.parent / '<my_project>'
    for item in appfolder.iterdir():
        if item.is_dir() and (item.name not in forbidden):
            if not (item / 'locale').exists():
                (item / 'locale').mkdir()
                print('Created {}'.format(str((item / 'locale'))))
            print('Running makemessages in {}'.format(str(item)))
            os.chdir(str(item))

            os.system("python {django_admin} makemessages -l fi".format(
                django_admin = django_admin
                ))

            translate(appfolder=item)

Traceback:
- Some files before and after these errors did not produce any errors.

Running makemessages in C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates
Traceback (most recent call last):
  File "C:\Python\VirtualEnv\<my_project>\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 360, in handle
    potfiles = self.build_potfiles()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 402, in build_potfiles
    self.process_files(file_list)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 499, in process_files
    self.process_locale_dir(locale_dir, files)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 594, in process_locale_dir
    build_file.cleanup()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 157, in cleanup
    os.unlink(self.work_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '.\\account\\account_inactive.html.py'
Running makemessages in C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\account
Traceback (most recent call last):
  File "C:\Python\VirtualEnv\<my_project>\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 360, in handle
    potfiles = self.build_potfiles()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 417, in build_potfiles
    with io.open(potfile, 'w', encoding='utf-8') as fp:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\<User>\\Dropbox\\<my_project>\\site\\src\\<my_project>\\templates\\account\\email\\locale\\django.pot'
Running makemessages in C:\Users\<User>\Dropbox\<my_project>\site\src\<my_project>\templates\account\email
Traceback (most recent call last):
  File "C:\Python\VirtualEnv\<my_project>\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 360, in handle
    potfiles = self.build_potfiles()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 402, in build_potfiles
    self.process_files(file_list)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 499, in process_files
    self.process_locale_dir(locale_dir, files)
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 594, in process_locale_dir
    build_file.cleanup()
  File "C:\Python\VirtualEnv\<my_project>\lib\site-packages\django\core\management\commands\makemessages.py", line 157, in cleanup
    os.unlink(self.work_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '.\\email_confirmation_message.txt.py'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ce301ad9-1584-468e-9fef-9e81ef9473b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment