getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.43k stars 1.81k forks source link

Missing `pelican` executable #3354

Open egberts opened 1 month ago

egberts commented 1 month ago

Issue

The pelican executable is missing.

Often times, development works entails testing Pelican as NOT BEING INSTALLED (also no virtual environment too). Having to supply the missing pelican executable becomes a necessary step. Many development works are done without the installation effort as part of the rapid but streamlined prototyping effort:

Notice no installation (nor invoke build) required.

This is most useful and ideal scenario in many IDE platforms. Also, it would make plugin development easier from the command line (CLI).

Suggested pelican Python file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import logging
from pelican.__main__ import main

class StdinFilter(logging.Filter):
    def filter(self, rec):
        return rec.levelno in (logging.DEBUG, logging.INFO)

class StderrFilter(logging.Filter):
    def filter(self, rec):
        return rec.levelno in (logging.WARNING, logging.FATAL, logging.CRITICAL)

logger = logging.getLogger("__name__")
logger.setLevel(logging.DEBUG)

h1 = logging.StreamHandler(sys.stdout)
h1.setLevel(logging.DEBUG)
h1.addFilter(StdinFilter())
h2 = logging.StreamHandler(sys.stderr)
h2.addFilter(StderrFilter())
h2.setLevel(logging.WARNING)

logger.addHandler(h1)  # DEBUG/INFO
logger.addHandler(h2)  # WARNING/FATAL/CRITICAL

if __name__ == "__main__":
    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit(main())

Platform Used

egberts commented 3 weeks ago

If not installed, but testing... the following log message in server.py is also invalid because the pelican executable is .... not yet installed (evaluation mode as often done by newcomers willing to try Pelican).

    logger.warning(
        "'python -m pelican.server' is deprecated.\nThe "
        "Pelican development server should be run via "
        "'pelican --listen' or 'pelican -l'.\nThis can be combined "
        "with regeneration as 'pelican -lr'.\nRerun 'pelican-"
        "quickstart' to get new Makefile and tasks.py files."
    )