jakul / django-transifex

Django integration with python-transifex
20 stars 8 forks source link

Executing `pull_translations` without a locale path setting gives an exception #20

Open willharris opened 8 years ago

willharris commented 8 years ago

When I run

./manage.py tx pull_translations

without having specified TRANSIFEX_PROJECT_PATH in the settings I get the following exception:

Executing pull_translations on project test-392
Pulling translations for "test-392" project, in "en" source language
Traceback (most recent call last):
  File "./manage.py", line 7, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/harris/Src/django-transifex/djangotransifex/management/commands/tx.py", line 75, in handle
    command_func(*args[1:], **options)
  File "/Users/harris/Src/django-transifex/djangotransifex/management/commands/tx.py", line 159, in transifex_pull_translations
    project_slug=self.project_slug, source_language=self.source_language
  File "/Users/harris/Src/django-transifex/djangotransifex/api.py", line 171, in pull_translations
    'LC_MESSAGES'
  File "/Users/harris/Workspaces/Unleash12/env/bin/../lib/python2.7/posixpath.py", line 70, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'function' object has no attribute 'endswith'

This is with Django 1.6.

It seems that if the path is not explicitly set, then django-transifex tries to figure out where the project is located using a lazy function. There are two problems in the code:

There is also the problem that the actual helper function app_settings._get_project_path does not handle the case where the settings file is not top-level in the project. In my case, all my settings are stored in a submodule structure.

The tests do not catch this, because the tests explicitly define TRANSIFEX_PROJECT_PATH.