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

new_port fails with AttributeError (locale.nl_langinfo missing) #1313

Closed
remram44 opened this issue Jun 1, 2014 · 6 comments
Closed

new_port fails with AttributeError (locale.nl_langinfo missing) #1313

remram44 opened this issue Jun 1, 2014 · 6 comments
Assignees
Milestone

Comments

@remram44
Copy link

remram44 commented Jun 1, 2014

Just installed Nikola, your handbook claims that you support Windows. However you use locale.nl_langinfo which is not available there, resulting in crashes.

> python -m nikola new_post
[2014-06-01T21:13:50Z] WARNING: Nikola: In order to USE_BUNDLES, you must install the "webassets" Python package.
[2014-06-01T21:13:50Z] WARNING: Nikola: Setting USE_BUNDLES to False.
Creating New Post
-----------------

Title: This is starting to feel like home
Scanning posts....done!
Traceback (most recent call last):
  File "C:\Python2.7.6\lib\site-packages\doit\doit_cmd.py", line 120, in run
    return command.parse_execute(args)
  File "C:\Python2.7.6\lib\site-packages\doit\cmd_base.py", line 78, in parse_execute
    return self.execute(params, args)
  File "C:\Python2.7.6\lib\site-packages\nikola\plugin_categories.py", line 98, in execute
    self._execute(options, args)
  File "C:\Python2.7.6\lib\site-packages\nikola\plugins\command\new_post.py", line 290, in _execute
    date = get_date(schedule, rule, last_date, self.site.tzinfo, self.site.config['FORCE_ISO8601'])
  File "C:\Python2.7.6\lib\site-packages\nikola\plugins\command\new_post.py", line 138, in get_date
    locale.nl_langinfo(locale.D_FMT),
AttributeError: 'module' object has no attribute 'nl_langinfo'

Is Windows actually supported (i.e. tested) or should I move on to another website generator? I know docs can easily become inaccurate :)

@ccanepa
Copy link
Contributor

ccanepa commented Jun 1, 2014

The situation is

  • Nikola around version 6.3 was working right in Windows, tests passing and all.
  • core developers and most contributors use Linux
  • Continuous Integration in Travis don't support test runs in Windows (albeit it is supposed to come at some time)
  • So some incompatibilities had slipped into the codebase between 6.4 and 7.0

About the bug:

Module locale has no nl_langinfo in python 2.7 and 3.3 in Windows
The python docs for locale in 2.7 and 3.3 tells :
"""
[nl_langinfo] ... This function is not available on all systems, and the set of possible options might also vary across platforms.
"""

@Kwpolska
Copy link
Member

Kwpolska commented Jun 2, 2014

See also: #1284. So, we’re back to forcing a date format on our users for the next release.

@remram44, temporary workaround: set FORCE_ISO8601 = True in your config.

@Kwpolska Kwpolska added the bug label Jun 2, 2014
@Kwpolska Kwpolska added this to the v7.0.1 milestone Jun 2, 2014
@Kwpolska Kwpolska self-assigned this Jun 2, 2014
@ishamf
Copy link

ishamf commented Jun 2, 2014

@Kwpolska Got the same bug, and the workaround results in this:

Creating New Post
-----------------

Title: Test Post
Scanning posts....done!
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\doit\doit_cmd.py", line 120, in run
    return command.parse_execute(args)
  File "C:\Python34\lib\site-packages\doit\cmd_base.py", line 78, in parse_execute
    return self.execute(params, args)
  File "C:\Python34\lib\site-packages\nikola\plugin_categories.py", line 98, in execute
    self._execute(options, args)
  File "C:\Python34\lib\site-packages\nikola\plugins\command\new_post.py", line 290, in _execute
    date = get_date(schedule, rule, last_date, self.site.tzinfo, self.site.config['FORCE_ISO8601'])
  File "C:\Python34\lib\site-packages\nikola\plugins\command\new_post.py", line 131, in get_date
    return date.strftime('%Y-%m-%dT%T') + tz_str
ValueError: Invalid format string

I changed the python file to return date.strftime("%Y-%m-%d %H:%M:%S") + tz_str and it works now.

@Kwpolska
Copy link
Member

Kwpolska commented Jun 2, 2014

Oh, that’s broken, too. Thanks for the report, @ishamf! Will fix it soon.

@ccanepa
Copy link
Contributor

ccanepa commented Jun 3, 2014

What if we delegate date-time to some library that have it's own databases, meaning it will not link with some semi-ramdom implementation of a C library ?

Looking in pypi and the web two possible candidates are

Babel

Pure python, includes database from CLDR (Common Locale Data Repository) .
It does more than dates, but less that is needed to, in a long term, drop the 'install OS locales for each languaje desired"
Size: 3MB
Last release: 2013 07
link to date and time doc's section: http://babel.pocoo.org/docs/api/dates/

PyICU

Python bindings to the ICU library , http://site.icu-project.org/ , includes its own databases.

Not pure python, I suspect will be not pip friendly in unix-like systems (installation mentions to adjust some path, probably it would be better to install from a distro package manager)

Interesting because long term it could handle all the localization needs for Nikola, without need to install OS locale support for extra languajes. It also provides conversion between posix locale names and windows locale names.

Size: 12MB the windows binaries + bindings

Also: current PyICU mantainer is very responsive, I asked for certain function not present in the binding at in a few hours was added to the svn repo.

So what ?

I think pyICU is a bit heavy-weight just now, at least for unix-like systems.
But Babel seems doable in the near term.

I can give it a try to Babel if Nikola honchos think is an acceptable dependency.

A question: in new_post.py , function get_date(), do we need to mimic exactly the current output format ?

@Kwpolska
Copy link
Member

Kwpolska commented Jun 3, 2014

@ccanepa We don’t need to mimic any previous format. It just has to be usable by everyone (including dateutil.parser — the default English one isn’t, for instance). We can just do one, human-friendly format for everyone. Like ISO 8601, for instance.

About the other things we do with locales, we might try with Babel, if it works out for Nikola’s needs…

@Kwpolska Kwpolska added PR exists and removed bug labels Jun 3, 2014
Kwpolska added a commit that referenced this issue Jun 3, 2014
fix #1284, fix #1313 -- fix dates in new_post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants