forked from github/pelican
Merge pull request #3243 from avaris/remove-write-selected
This commit is contained in:
commit
9525583ccd
8 changed files with 8 additions and 103 deletions
|
|
@ -217,10 +217,6 @@ changed. A simple solution is to make ``rsync`` use the ``--checksum`` option,
|
||||||
which will make it compare the file checksums in a much faster way than Pelican
|
which will make it compare the file checksums in a much faster way than Pelican
|
||||||
would.
|
would.
|
||||||
|
|
||||||
When only several specific output files are of interest (e.g. when working on
|
|
||||||
some specific page or the theme templates), the ``WRITE_SELECTED`` option may
|
|
||||||
help, see :ref:`writing_only_selected_content`.
|
|
||||||
|
|
||||||
How to process only a subset of all articles?
|
How to process only a subset of all articles?
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,6 @@ folder, using the default theme to produce a simple site. The default theme
|
||||||
consists of very simple HTML without styling and is provided so folks may use
|
consists of very simple HTML without styling and is provided so folks may use
|
||||||
it as a basis for creating their own themes.
|
it as a basis for creating their own themes.
|
||||||
|
|
||||||
When working on a single article or page, it is possible to generate only the
|
|
||||||
file that corresponds to that content. To do this, use the ``--write-selected``
|
|
||||||
argument, like so::
|
|
||||||
|
|
||||||
pelican --write-selected output/posts/my-post-title.html
|
|
||||||
|
|
||||||
Note that you must specify the path to the generated *output* file — not the
|
|
||||||
source content. To determine the output file name and location, use the
|
|
||||||
``--debug`` flag. If desired, ``--write-selected`` can take a comma-separated
|
|
||||||
list of paths or can be configured as a setting. (See:
|
|
||||||
:ref:`writing_only_selected_content`)
|
|
||||||
|
|
||||||
You can also tell Pelican to watch for your modifications, instead of manually
|
You can also tell Pelican to watch for your modifications, instead of manually
|
||||||
re-running it every time you want to see your changes. To enable this, run the
|
re-running it every time you want to see your changes. To enable this, run the
|
||||||
``pelican`` command with the ``-r`` or ``--autoreload`` option. On non-Windows
|
``pelican`` command with the ``-r`` or ``--autoreload`` option. On non-Windows
|
||||||
|
|
|
||||||
|
|
@ -362,13 +362,6 @@ Basic settings
|
||||||
|
|
||||||
If ``True``, load unmodified content from caches.
|
If ``True``, load unmodified content from caches.
|
||||||
|
|
||||||
.. data:: WRITE_SELECTED = []
|
|
||||||
|
|
||||||
If this list is not empty, **only** output files with their paths in this
|
|
||||||
list are written. Paths should be either absolute or relative to the current
|
|
||||||
Pelican working directory. For possible use cases see
|
|
||||||
:ref:`writing_only_selected_content`.
|
|
||||||
|
|
||||||
.. data:: FORMATTED_FIELDS = ['summary']
|
.. data:: FORMATTED_FIELDS = ['summary']
|
||||||
|
|
||||||
A list of metadata fields containing reST/Markdown content to be parsed and
|
A list of metadata fields containing reST/Markdown content to be parsed and
|
||||||
|
|
@ -1400,21 +1393,6 @@ modification times of the generated ``*.html`` files will always change.
|
||||||
Therefore, ``rsync``-based uploading may benefit from the ``--checksum``
|
Therefore, ``rsync``-based uploading may benefit from the ``--checksum``
|
||||||
option.
|
option.
|
||||||
|
|
||||||
.. _writing_only_selected_content:
|
|
||||||
|
|
||||||
|
|
||||||
Writing only selected content
|
|
||||||
=============================
|
|
||||||
|
|
||||||
When only working on a single article or page, or making tweaks to your theme,
|
|
||||||
it is often desirable to generate and review your work as quickly as possible.
|
|
||||||
In such cases, generating and writing the entire site output is often
|
|
||||||
unnecessary. By specifying only the desired files as output paths in the
|
|
||||||
``WRITE_SELECTED`` list, **only** those files will be written. This list can be
|
|
||||||
also specified on the command line using the ``--write-selected`` option, which
|
|
||||||
accepts a comma-separated list of output file paths. By default this list is
|
|
||||||
empty, so all output is written. See :ref:`site_generation` for more details.
|
|
||||||
|
|
||||||
|
|
||||||
Example settings
|
Example settings
|
||||||
================
|
================
|
||||||
|
|
|
||||||
|
|
@ -434,15 +434,6 @@ def parse_arguments(argv=None):
|
||||||
help="Ignore content cache " "from previous runs by not loading cache files.",
|
help="Ignore content cache " "from previous runs by not loading cache files.",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"-w",
|
|
||||||
"--write-selected",
|
|
||||||
type=str,
|
|
||||||
dest="selected_paths",
|
|
||||||
default=None,
|
|
||||||
help="Comma separated list of selected paths to write",
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--fatal",
|
"--fatal",
|
||||||
metavar="errors|warnings",
|
metavar="errors|warnings",
|
||||||
|
|
@ -527,8 +518,6 @@ def get_config(args):
|
||||||
config["LOAD_CONTENT_CACHE"] = False
|
config["LOAD_CONTENT_CACHE"] = False
|
||||||
if args.cache_path:
|
if args.cache_path:
|
||||||
config["CACHE_PATH"] = args.cache_path
|
config["CACHE_PATH"] = args.cache_path
|
||||||
if args.selected_paths:
|
|
||||||
config["WRITE_SELECTED"] = args.selected_paths.split(",")
|
|
||||||
if args.relative_paths:
|
if args.relative_paths:
|
||||||
config["RELATIVE_URLS"] = args.relative_paths
|
config["RELATIVE_URLS"] = args.relative_paths
|
||||||
if args.port is not None:
|
if args.port is not None:
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,6 @@ DEFAULT_CONFIG = {
|
||||||
"GZIP_CACHE": True,
|
"GZIP_CACHE": True,
|
||||||
"CHECK_MODIFIED_METHOD": "mtime",
|
"CHECK_MODIFIED_METHOD": "mtime",
|
||||||
"LOAD_CONTENT_CACHE": False,
|
"LOAD_CONTENT_CACHE": False,
|
||||||
"WRITE_SELECTED": [],
|
|
||||||
"FORMATTED_FIELDS": ["summary"],
|
"FORMATTED_FIELDS": ["summary"],
|
||||||
"PORT": 8000,
|
"PORT": 8000,
|
||||||
"BIND": "127.0.0.1",
|
"BIND": "127.0.0.1",
|
||||||
|
|
@ -557,6 +556,13 @@ def handle_deprecated_settings(settings):
|
||||||
)
|
)
|
||||||
settings[old] = settings[new]
|
settings[old] = settings[new]
|
||||||
|
|
||||||
|
# Warn if removed WRITE_SELECTED is present
|
||||||
|
if "WRITE_SELECTED" in settings:
|
||||||
|
logger.warning(
|
||||||
|
"WRITE_SELECTED is present in settings but this functionality was removed. "
|
||||||
|
"It will have no effect."
|
||||||
|
)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -585,12 +591,6 @@ def configure_settings(settings):
|
||||||
else:
|
else:
|
||||||
raise Exception("Could not find the theme %s" % settings["THEME"])
|
raise Exception("Could not find the theme %s" % settings["THEME"])
|
||||||
|
|
||||||
# make paths selected for writing absolute if necessary
|
|
||||||
settings["WRITE_SELECTED"] = [
|
|
||||||
os.path.abspath(path)
|
|
||||||
for path in settings.get("WRITE_SELECTED", DEFAULT_CONFIG["WRITE_SELECTED"])
|
|
||||||
]
|
|
||||||
|
|
||||||
# standardize strings to lowercase strings
|
# standardize strings to lowercase strings
|
||||||
for key in ["DEFAULT_LANG"]:
|
for key in ["DEFAULT_LANG"]:
|
||||||
if key in settings:
|
if key in settings:
|
||||||
|
|
|
||||||
|
|
@ -202,29 +202,6 @@ class TestPelican(LoggedTestCase):
|
||||||
for file in ["a_stylesheet", "a_template"]:
|
for file in ["a_stylesheet", "a_template"]:
|
||||||
self.assertTrue(os.path.exists(os.path.join(theme_output, file)))
|
self.assertTrue(os.path.exists(os.path.join(theme_output, file)))
|
||||||
|
|
||||||
def test_write_only_selected(self):
|
|
||||||
"""Test that only the selected files are written"""
|
|
||||||
settings = read_settings(
|
|
||||||
path=None,
|
|
||||||
override={
|
|
||||||
"PATH": INPUT_PATH,
|
|
||||||
"OUTPUT_PATH": self.temp_path,
|
|
||||||
"CACHE_PATH": self.temp_cache,
|
|
||||||
"WRITE_SELECTED": [
|
|
||||||
os.path.join(self.temp_path, "oh-yeah.html"),
|
|
||||||
os.path.join(self.temp_path, "categories.html"),
|
|
||||||
],
|
|
||||||
"LOCALE": locale.normalize("en_US"),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
pelican = Pelican(settings=settings)
|
|
||||||
logger = logging.getLogger()
|
|
||||||
orig_level = logger.getEffectiveLevel()
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
mute(True)(pelican.run)()
|
|
||||||
logger.setLevel(orig_level)
|
|
||||||
self.assertLogCountEqual(count=2, msg="Writing .*", level=logging.INFO)
|
|
||||||
|
|
||||||
def test_cyclic_intersite_links_no_warnings(self):
|
def test_cyclic_intersite_links_no_warnings(self):
|
||||||
settings = read_settings(
|
settings = read_settings(
|
||||||
path=None,
|
path=None,
|
||||||
|
|
|
||||||
|
|
@ -840,19 +840,6 @@ def split_all(path):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_selected_for_writing(settings, path):
|
|
||||||
"""Check whether path is selected for writing
|
|
||||||
according to the WRITE_SELECTED list
|
|
||||||
|
|
||||||
If WRITE_SELECTED is an empty list (default),
|
|
||||||
any path is selected for writing.
|
|
||||||
"""
|
|
||||||
if settings["WRITE_SELECTED"]:
|
|
||||||
return path in settings["WRITE_SELECTED"]
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def path_to_file_url(path):
|
def path_to_file_url(path):
|
||||||
"""Convert file-system path to file:// URL"""
|
"""Convert file-system path to file:// URL"""
|
||||||
return urllib.parse.urljoin("file://", urllib.request.pathname2url(path))
|
return urllib.parse.urljoin("file://", urllib.request.pathname2url(path))
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ from pelican.paginator import Paginator
|
||||||
from pelican.plugins import signals
|
from pelican.plugins import signals
|
||||||
from pelican.utils import (
|
from pelican.utils import (
|
||||||
get_relative_path,
|
get_relative_path,
|
||||||
is_selected_for_writing,
|
|
||||||
path_to_url,
|
path_to_url,
|
||||||
sanitised_join,
|
sanitised_join,
|
||||||
set_date_tzinfo,
|
set_date_tzinfo,
|
||||||
|
|
@ -145,9 +144,6 @@ class Writer:
|
||||||
name should be skipped to keep that one)
|
name should be skipped to keep that one)
|
||||||
:param feed_title: the title of the feed.o
|
:param feed_title: the title of the feed.o
|
||||||
"""
|
"""
|
||||||
if not is_selected_for_writing(self.settings, path):
|
|
||||||
return
|
|
||||||
|
|
||||||
self.site_url = context.get("SITEURL", path_to_url(get_relative_path(path)))
|
self.site_url = context.get("SITEURL", path_to_url(get_relative_path(path)))
|
||||||
|
|
||||||
self.feed_domain = context.get("FEED_DOMAIN")
|
self.feed_domain = context.get("FEED_DOMAIN")
|
||||||
|
|
@ -203,13 +199,7 @@ class Writer:
|
||||||
:param **kwargs: additional variables to pass to the templates
|
:param **kwargs: additional variables to pass to the templates
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if (
|
if name is False or name == "":
|
||||||
name is False
|
|
||||||
or name == ""
|
|
||||||
or not is_selected_for_writing(
|
|
||||||
self.settings, os.path.join(self.output_path, name)
|
|
||||||
)
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
elif not name:
|
elif not name:
|
||||||
# other stuff, just return for now
|
# other stuff, just return for now
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue