• victordomingos

    Hi!

    I have created a new personal blog where I intend to reflect on Python and my journey on learning programming. It’s built on both Mac and iOS, with Pelican, a Python-based static website generator. I am making an effort to keep the build process compatible with Pythonista, in order to allow me to use whatever tool I have on hand.

    I would like invite you to take a look:

    no-title.victordomingos.com

    Comments, critics and and suggestions are very welcome.

    posted in Pythonista read more
  • victordomingos

    Well, apparently it works if I remove the lines that define different date formats for each language:

    DATE_FORMATS = {
        'en': ('en_GB', '%d %B %Y'),
        'pt': ('pt_PT', '%d de %B de %Y'),
    }
    

    The rest of the stuff seems to work, so I will give it a shot without the date localization.

    posted in Pythonista read more
  • victordomingos

    I have been going on with this website project, and now I am experimenting with Pelican’s translation feature. I created some pages and articles with the required settings (same slug and different Lang) and added some settings to pelicanconf.py with the translation paths. Once again, it works on desktop (Mac/Python3.6), but not on Pythonista, where I get this:

    $ pelican --debug
    stash: <class 'locale.Error'>: unsupported locale setting
    
    Traceback (most recent call last):
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/stash/system/shruntime.py", line 498, in exec_py_file
        exec code in namespace, namespace
      File "../../../stash_extensions/bin/pelican.py", line 5, in <module>
        main()
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/__init__.py", line 487, in main
        pelican.run()
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/__init__.py", line 171, in run
        p.generate_context()
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/generators.py", line 717, in generate_context
        context_sender=self)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/readers.py", line 572, in read_file
        context=context)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/contents.py", line 389, in __init__
        super(Static, self).__init__(*args, **kwargs)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/contents.py", line 123, in __init__
        locale.setlocale(locale.LC_ALL, locale_string)
      File "/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/locale.py", line 583, in setlocale
        return _setlocale(category, locale)
    Error: unsupported locale setting
    >/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/locale.py(583)setlocale()
    -> return _setlocale(category, locale)
    

    Any hope to get this working? Any tips?

    posted in Pythonista read more
  • victordomingos

    Turns out that the pelican-minify plug-in was using joblib to parallelize it’s execution. Reading through the code of them, I discovered I just needed to change a single character in site-packages/minify.py to make it work properly on Pythonista. By specifying n_jobs=1 in the Parallel class instantiation, instead of n_jobs=-1, it works fine:

        Parallel(n_jobs=1)(delayed(create_minified_file)(filepath, options) for filepath in files_to_minify)
    

    posted in Pythonista read more
  • victordomingos

    While I don’t find a better solution, I am now detecting the current platform and just adding the minification plugin on desktop... but I really would like to get it working on both platforms.

    posted in Pythonista read more
  • victordomingos

    Just did a pip install scandir And apparently it’s working now, at least in StaSh. Thank you very much!

    However, using the custom build script I had written I get an error on aone module used by the pelican-minify plug-in. Here’s what I get by running my build script in Python 2:

    No handlers could be found for logger "pelican.settings"
    Traceback (most recent call last):
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/pelican-stuff/make_html.py", line 15, in <module>
        pelican.run()
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/__init__.py", line 181, in run
        signals.finalized.send(self)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/blinker/base.py", line 267, in send
        for receiver in self.receivers_for(sender)]
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/minify.py", line 32, in minify_html
        Parallel(n_jobs=-1)(delayed(create_minified_file)(filepath, options) for filepath in files_to_minify)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/joblib/parallel.py", line 772, in __call__
        n_jobs = self._initialize_pool()
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/joblib/parallel.py", line 542, in _initialize_pool
        self._pool = MemmapingPool(n_jobs, **poolargs)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/joblib/pool.py", line 580, in __init__
        super(MemmapingPool, self).__init__(**poolargs)
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/joblib/pool.py", line 419, in __init__
        super(PicklingPool, self).__init__(**poolargs)
      File "/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/multiprocessing/pool.py", line 160, in __init__
        self._repopulate_pool()
      File "/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/multiprocessing/pool.py", line 224, in _repopulate_pool
        w.start()
      File "/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/multiprocessing/process.py", line 131, in start
        self._popen = Popen(self)
      File "/var/containers/Bundle/Application/46E67BC7-8A23-4C29-9CBA-6E4CC2B2BB96/Pythonista3.app/Frameworks/Py2Kit.framework/pylib/multiprocessing/forking.py", line 122, in __init__
        self.pid = os.fork()
    OSError: [Errno 1] Operation not permitted
    

    It’s getting more complex...

    posted in Pythonista read more
  • victordomingos

    Thanks. I have just tried that. Now, when running pelican content/ -s pelicanconf.py in StaSh, I get this:

    CRITICAL: ImportError: No module named scandir
    

    Now, that’s weird. It should be available in both Python2.7 and Python 3.6, right? When trying to import it in the console, I get an import error in both versions...

    posted in Pythonista read more
  • victordomingos

    I prefer Python 3 because it’s the one I understand better and know how to debug and extend, and because I believe it will tend to be better supported in the near future.

    But for now it would in fact be very useful to update my current code to be compatible with either version, returning the same html. I am trying to keep my workflow Python 3 and Pythonista 3 compatible, so that I can use whatever machine I have to hand.

    At the moment, I think the only piece of code that is getting in the way are the following lines, where I wanted to get a random image for each generated html page:

    from pathlib import Path
    
    SITEIMAGES = [ Path(*Path(img).parts[1:])
                   for img in glob('{}/{}/*.png'.format(PATH,SITEIMAGE_FOLDER))]
    

    posted in Pythonista read more
  • victordomingos

    Correction: in Python 2, I get this error:

    Traceback (most recent call last):
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/pelican-stuff/make_html.py", line 4, in <module>
        from pelican import Pelican
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/__init__.py", line 19, in <module>
        from pelican import signals
    ImportError: cannot import name signals
    
    

    posted in Pythonista read more
  • victordomingos

    I just tried that. Now it doesn’t run in either Python version. In Python 2, I get an import error for the missing package. In Python 3, I get this:

    Traceback (most recent call last):
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/pelican-stuff/make_html.py", line 4, in <module>
        from pelican import Pelican
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/__init__.py", line 20, in <module>
        from pelican.generators import (ArticlesGenerator, PagesGenerator,
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/generators.py", line 22, in <module>
        from pelican.readers import Readers
      File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/pelican/readers.py", line 10, in <module>
        import docutils
    ModuleNotFoundError: No module named 'docutils'
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!