Package: anchovy
AnchovyAnchovy is a minimal, unopinionated file-processing framework equipped with a
complete static website generation toolkit.Minimal:Anchovy’s core is around a thousand lines of code and has no
mandatory dependencies. Plus, Anchovy can be used for real projects with just
a few pip-installable extras, even if you want to preprocess CSS.Unopinionated:Anchovy offers a set of components which can be easily
configured to your site’s exact requirements, without tediously ripping out
or overriding entrenched behaviors. Anchovy does not assume you are building
a blog or that you wish to design your templates in a specific way. You can
even build things that aren’t websites! Plus, Anchovy operates on files, so
it’s simple to integrate tools like imagemagick, dart-sass, or less.js if you
need them.Complete:Anchovy comes with a dependency auditing system, allowing you
to grab any component you want without installing anything but Anchovy and
find out what youwillneed to run your build. Choose from a wealth of
Steps, Anchovy’s modular file processors, for everything from rendering Jinja
templates and minifying CSS to unpacking archives and thumbnailing images.
Plus, add a few extra parameters or lines of configuration to get automatic
intelligent minimum builds based on input checksums, and get a reproducible
run artifact to boot— even if you want to fetch HTTP resources or write your
own Steps. Iterate quickly by launching a lightweight development-grade web
server once the build is complete.InstallationAnchovy has no essential prerequisites and can be installed withpip install anchovyto get just the framework and a few built-in components,
but for typical usagepip install anchovy[base]is recommended. This will
pull in support for Jinja2 templating, markdown, minification, and Anchovy’s
CSS preprocessor. A full list of available extras may be found in thepyproject.tomlfile.Alternatively, Anchovy may be installed directly from source withpip install git+https://github.com/pydsigner/anchovyor the correspondingpip install git+https://github.com/pydsigner/anchovy#egg=anchovy[base].Command Line UsageAnchovy operates on config files written in Python, or even modules directly.python -m anchovy -hanchovy -m mypackage.anchovyconf -o ../release/python -m anchovy mysite/anchovy_site.py -- -hShow MeRunanchovy examples/code_index.py -s -p 8080, then open a browser to
localhost:8080 (or click the link in the console). This example offers the most
extensive demonstration of Anchovy’s functionality as of version 1.0.What’s the Baseline?Here’s minimal example performing about what thestaticjinjamarkdown example
offers:frompathlibimportPathfromanchovyimport(DirectCopyStep,InputBuildSettings,JinjaMarkdownStep,OutputDirPathCalc,REMatcher,Rule,)# Optional, and can be overridden with CLI arguments.SETTINGS=InputBuildSettings(input_dir=Path('site'),working_dir=Path('working'),output_dir=Path('build'),custody_cache=Path('build-cache.json'),)RULES=[# Ignore dotfiles found in either the input_dir or the working dir.Rule((REMatcher(r'(.*/)*\..*',parent_dir='input_dir')|REMatcher(r'(.*/)*\..*',parent_dir='working_dir')),None),# Render markdown files, then stop processing them.Rule(REMatcher(r'.*\.md'),[OutputDirPathCalc('.html'),None],JinjaMarkdownStep()),# Copy everything else in static/ directories through.Rule(REMatcher(r'(.*/)*static/.*',parent_dir='input_dir'),OutputDirPathCalc(),DirectCopyStep()),]This example is very simple, but it’s legitimately enough to start with for a
small website, and offers an advantage over other minimal frameworks by putting
additional batteries within an arm’s reach. If we stored the configuration inconfig.pyand added a raw site like this:site/
    static/
        styles.css
        toolbar.js
    base.jinja.html
    index.md
    about.md
    contact.mdpython -m anchovy config.pywould produce output like this:output/
    static/
        styles.css
        toolbar.js
    index.html
    about.html
    contact.htmlThis example can be found in runnable form asexamples/basic_site.pyin the source distribution. Available command line arguments can be seen by
passing-h:python -m anchovy examples/basic_site.py -- -h. The--is
required becauseanchovyitself also accepts the flag.Programmatic UsageAnchovy is very usable from the command line, but projects desiring to
customize behavior, for example by running tasks before or after pipeline
execution, may utilizeanchovy.cli.run_from_rules():importtimefrompathlibimportPathfromanchovy.cliimportrun_from_rulesfromanchovy.coreimportContextfrommy_site.configimportSETTINGS,RULESclassMyContext(Context):deffind_inputs(path:Path):# Only process files modified in the last hour.hour_ago=time.time()-3600forcandidateinsuper().find_inputs(path):ifcandidate.stat().st_mtime>hour_ago:yieldcandidatedefmain():print('Pretending to run pre-pipeline tasks...')run_from_rules(SETTINGS,RULES,context_cls=MyContext)print('Pretending to run post-pipeline tasks...')if__name__=='__main__':main()