Skip to content

Commit

Permalink
remove WRITE_SELECTED
Browse files Browse the repository at this point in the history
Implementation is buggy and unreliable. Therefore, it is better to
remove the functionality until a robust implementation is added.
  • Loading branch information
avaris committed Nov 12, 2023
1 parent 0c5d63c commit 86d6898
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 103 deletions.
4 changes: 0 additions & 4 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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?
=============================================

Expand Down
12 changes: 0 additions & 12 deletions docs/publish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
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
Expand Down
22 changes: 0 additions & 22 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,6 @@ Basic settings

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']

A list of metadata fields containing reST/Markdown content to be parsed and
Expand Down Expand Up @@ -1400,21 +1393,6 @@ modification times of the generated ``*.html`` files will always change.
Therefore, ``rsync``-based uploading may benefit from the ``--checksum``
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
================
Expand Down
11 changes: 0 additions & 11 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,6 @@ def parse_arguments(argv=None):
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(
"--fatal",
metavar="errors|warnings",
Expand Down Expand Up @@ -527,8 +518,6 @@ def get_config(args):
config["LOAD_CONTENT_CACHE"] = False
if args.cache_path:
config["CACHE_PATH"] = args.cache_path
if args.selected_paths:
config["WRITE_SELECTED"] = args.selected_paths.split(",")
if args.relative_paths:
config["RELATIVE_URLS"] = args.relative_paths
if args.port is not None:
Expand Down
14 changes: 7 additions & 7 deletions pelican/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def load_source(name, path):
"GZIP_CACHE": True,
"CHECK_MODIFIED_METHOD": "mtime",
"LOAD_CONTENT_CACHE": False,
"WRITE_SELECTED": [],
"FORMATTED_FIELDS": ["summary"],
"PORT": 8000,
"BIND": "127.0.0.1",
Expand Down Expand Up @@ -557,6 +556,13 @@ def handle_deprecated_settings(settings):
)
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


Expand Down Expand Up @@ -585,12 +591,6 @@ def configure_settings(settings):
else:
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
for key in ["DEFAULT_LANG"]:
if key in settings:
Expand Down
23 changes: 0 additions & 23 deletions pelican/tests/test_pelican.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,29 +202,6 @@ def test_theme_static_paths_copy_single_file(self):
for file in ["a_stylesheet", "a_template"]:
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):
settings = read_settings(
path=None,
Expand Down
13 changes: 0 additions & 13 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""Convert file-system path to file:// URL"""
return urllib.parse.urljoin("file://", urllib.request.pathname2url(path))
Expand Down
12 changes: 1 addition & 11 deletions pelican/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from pelican.plugins import signals
from pelican.utils import (
get_relative_path,
is_selected_for_writing,
path_to_url,
sanitised_join,
set_date_tzinfo,
Expand Down Expand Up @@ -145,9 +144,6 @@ def write_feed(
name should be skipped to keep that one)
: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.feed_domain = context.get("FEED_DOMAIN")
Expand Down Expand Up @@ -203,13 +199,7 @@ def write_file(
:param **kwargs: additional variables to pass to the templates
"""

if (
name is False
or name == ""
or not is_selected_for_writing(
self.settings, os.path.join(self.output_path, name)
)
):
if name is False or name == "":
return
elif not name:
# other stuff, just return for now
Expand Down

0 comments on commit 86d6898

Please sign in to comment.