Package: barnhunt
Barn Hunt Map HelperThis is a helper script Jeff uses for draftingBarn Huntcourse
maps.It does a bunch of stuff, but the important bit is that it exports PDF
versions of maps fromInkscapeSVG files.I draw all the maps for a given ring (for a day or weekend) in a
single Inkscape drawing.  Various maps (for different trials/classes,
build map, rat-maps, base maps, etc.) are generated by hiding and
unhiding appropriate layers in the drawing and exporting to PDF.This program automates that process.RequirementsThis program requires Python, version 3.7 or higher to run.It "should" work with all versions of Inkscape, 0.9x through 1.2.1.I use this program on Linux, however the package now includes a GitHub
CI workflow that performs rudimentary testing on Windows and macOS, so
there’s a moderate chance it might "just work" on those platforms.
(Due to a dependency on thepikepdfpackage, it should work on
x86_64-based Macs, but may not work on Macs that use Apple silicon. If
pikepdf compatibility is an issue for you, let me know — it’s probably
fixable.)InstallationWindowsWe now publish a compiled version of the program for Windows (which may
even work.) Using this version has the advantage that Python is not required
to be installed. (And even if Python is installed, this version may work-around
some bugs having to do with the various different ways that Python can be
installed on on Windows computer.)Browse to ourreleasespage. Select a release, and look down in theAssetssection of the
release page. (You may have to click the triangle to expand theAssetssection.)Download the MSI installer (the filename should end with.msi—
e.g.Barnhunt-1.2.0.49-x86_64-pc-windows-msvc.msi). The file
is not signed, so you may have to click through some nasty warnings
about "unrecognized, potentially dangerous" files.Once downloaded, open (double-click) the file you just
downloaded. Hopefully and installer dialog should open.  Accept the
default choices.Now open a terminal command-line window. Typebarnhunt --version. If all is good, barnhunt should report its version. Runbarnhunt --helpfor the help screen.Linux (or Windows with Python installed)As this package is published toPyPIit may be installed into avirtualenvusingpip. It is suggested that you usepipxto combine those two steps.A basic outline of how to proceed:Installpythonif it is not already installed.  (Version 3.7 or
greater is required.)Installpipx.  This might look like:python3-mpipinstall--userpipx
python3-mpipxensurepathInstallbarnhunt.pipxinstallbarnhuntHow to UseSadly, this program is currently quite under-documented.The functions of the basic sub-commands and command-line options are
tersely documented via the--helpoption.  Try:barnhunt--helpandbarnhuntpdfs--helpfor starters.If you get stuck, kick me!AuthorThis package was written by Jeff Dairiki, BHAJ-221A,dairiki@dairiki.org.ChangesRelease 1.2.1rc3 (2023-08-04)Bugs FixedFix crash when clone refers to a hidden layer.Internal API changesInkscape.svg.ancestor_layers(elem)now includeselemin the
returned results ifelemis an Inkscape layer element.
Previously, the search for ancestor layers strated withelem's
parent.Release 1.2.1rc2 (2023-06-06)New FeaturesProvide access to RDF metadata in the SVG source in string
templates.  E.g. the document description may be interpolated via{{ rdf['dc:description'] }}.Bugs FixedFix parsing of version strings reported by pre-release versions of
Inkscape.Release 1.2.1rc1 (2023-05-22)(There was no final release of 1.2.0. It is a long story. I mistakenly
committed a couple of files to LFS. To clear out LFS storage for a
GitHub repo, one has todelete the whole repo. As a result, the
workflow$GITHUB_RUN_NUMBERhas reset. Thus a micro-version bump
is required to keep those PyOxidizer windows build version numbers —<major>.<minor>.<micro>.<run-number>— monotonic.)CLI ChangesThe--inkscape-command,--processesand--shell-mode-inkscapeoptions have been moved from thebarnhunt pdfssubcommand to the
manbarnhuntcommand group.And newdebug-infosubcommand has been added to display various
information about the installed version of thebarnhuntcommand
and its execution environment.The--dump-loaded-modulesoption has been removed.  The
functionality is still available by setting the$BARNHUNT_DUMP_LOADED_MODULESenvironment variable to a non-empty
value.Bugs FixedFixed exception inbarnhunt.cli.default_2up_output_fileduring
shell-completion forbarnhunt 2up.Release 1.2.0rc6 (2023-04-27)Build an Windows executable and installer usingPyOxidizer.  The
.msi installer should be downloadable from theReleasespage.Added a--dump-loaded-modulesoption which causesbarnhuntto
write a list of all loaded modules the current working directory.
(This is a development tool, not generally useful to most users.)Hardwire the distribution version intobarnhunt.__version__rather
than deducing it viaimportlib.metadata.  This allows us to monkey
with the version we report from the PyOxidizer-built Windows
executable so that it indicates the MSI build version as well as
the distribution version.Convert package from setuptools to PDM.Release 1.2.0rc5 (2023-03-05)Bugs FixedWhen there was a visible “clone” (<svg:use>element) that
referenced a source on a hidden layer were being pruned from the SVG
before conversion to PDF.  (When exporting an SVG, hidden layers are
omitted from the SVG — this speeds Inkscape up considerably when
there is a large amount of hidden content.) Now we detect hidden
layers that contain source material for clones, and retain them in
the SVG file.Add a cruft pattern to ignore “Gtk-WARNING"” messages that have
started appearing since I installed Inkscape fromInkscape’s ppa.Fix tests to workaround segfault from pikepdf 7.0.0, 7.1.0, and 7.1.1.
(See [pikepdf/pikepdf#452].)[pikepdf/pikepdf#452]:https://github.com/pikepdf/pikepdf/issues/452).Release 1.2.0rc4 (2023-01-09)Support python 3.11.BugsShell-mode runner: fix readline/pexpect disagreement with respect to
horizontal scrolling of long lines.  In some cases, when Inkscape is
compiled to use GNU readline, long input lines will be scrolled
horizontally (even when stdin is not a tty). This messes with
pexpect's head. We've now added some basic tests for this, and set
some environment variables to try to convince readline not to do the
scrolling.TestingTest under python 3.11Fix tests for Windows environments where $APPDATA is not setFix tests for error message changes in packaging>=22Release 1.2.0rc3 (2022-10-19)Extension/Symbols InstallerMake code for deducing Inkscape profile directory more robust.
(There's now a beter chance this will actually work on Windows.)Support setting Inkscape profile directory via$INKSCAPE_PROFILE_DIR.Release 1.2.0rc2 (2022-10-17)Extension and Symbol Set InstallationThis release add abarnhunt install(anduninstall) sub-command
to simplify installation of theinkex-bhInkscape extensions
andbh-symbolssymbol
sets.TestingUpdate tomypy==0.982for testing. Fix spurious mypy errors.Release 1.2.0rc1 (2022-08-31)First public release to PyPI. Moved project toGitHub.Dropped support for python 3.6Changed license to GPL version 3We now do rudimentary testing under Windows and macOS.DependenciesUsepikepdfinstead ofpdfrwto manipulate PDFs.  (Pdfrw
seems not to be very actively maintained.) The only possible
downside of this is thatpikepdfis not pure-python. It claims to
be easily installable on Windows andx86_64Macs, but is not
(easily) installable on Macs with Apple silicon.Generated PDFs are nowlinearizedandcompressed.Add test dependency onpdfminer.six(but drop
dependency onPyPDF2).CompatibilityRefactorbarnhunt.inkscape.runnerto support running
Inkscape >= 1.0 (as well as continuing to support Inkscape 0.9x).Add--inkscape-commandparameter to thebarnhunt pdfscommand
to specify the name/path of the Inkscape binary to run to export PDFs.
This also supports setting the Inkscape executable via the$INKSCAPE_COMMANDenvironment variable.  Default executable is notinkscape.exeon Windows
(andinkscapeeverywhere else).Usepexpect.popen_spawn.PopenSpawninstead ofpexpect.spawnto
run Inkscape in shell-mode. Due topexpect.spawn's use of ptys, itwill not workon Windows.MacOS: our code for running Inkscape in shell-mode appears to be broken.
For now, onmacOSwe default to not using shell-mode.PackagingAdded a stubbarnhunt.__main__module to allow running viapython -m barnhunt.TestingAdd type annotations.Bit RotFix up tests to address deprecations in PyPDF2.Release 1.1.0a1 (2022-03-08)"Base Map" supportAdd ability to mark layers for exclusion from particular output files.This adds the ability to list multiple comma-separated output base
filenames for a given overlay.
E.g. A layer with label"[o|build_notes,base] Build Notes"will define an overlay which will generate maps in two separate
output files.Tagging a layer with[!output-basename]will exclude that
layer from any maps which are directed to the specified output
filename.Tagging a layer with[=output-basename]will include that layer
from any maps which are directed to the specified output filename, while
excluding all other sibling layers not explicitly tagged to be included
in that output file.Release 1.0.1 (2021-11-10)DiagnosticsBarnhunt pdfsnow issues a warning when generating PDFs from an SVG
file which does not have an explicit random-seed set.Bugs FixedOpen SVG files in binary mode in order to let the XML parser figure
out the encoding from the XML declaration.Release 1.0 (2021-11-10)Support python 3.10.Random SeedThe way the random seed (used for generating random rat numbers) for
each SVG layer is computed has been changed in abackward-incompatibleway.  This was done so that rat numbers can
be kept from changing when an SVG source file is copied or edited in
such a way that the device and/or inode of the file changes.Now, the file-level random seed (an integer) is read from thebh:random-seedattribute of the rootsvgelement of the SVG
file. If nobh:random-seedattribute is set, the file-level seed is
computed by hashing the device and inode numbers of the SVG file.The layer-level seed is formed by hashing the file-level random seed
with the XMLidof the layer.(Formerly, the layer-level seed was form by hashing a triple of the
file-level seed (which was always zero), the hash of the SVG files
device and inode, and the id of the layer.)A newbarnhunt random-seedsub-command has been implemented to help
with setting the random seed for SVG source files.Bit-rotAddressDeprecationWarning: 'contextfunction' is renamed to 'pass_context'from Jinja2. RequireJinja2>3.OCDismsRunpyupgrade --py36-pluson source.Release 0.5 (2021-05-04)Make-ooption to2upsub-command optional.Remove support for python < 3.6.Release 0.4 (2019-02-25)New Sub-Command: 2upNew2upsub-command to format PDFs for 2-up printing.  Pages are
pre-shuffled so that the 2-up pages do not need to be shuffled after
cutting.Release 0.3 (2019-02-20)barnhunt pdfsMulti-page output support.There is a new syntax to specify the output file basename for an overlay.
Multiple overlays which specify the same output file will all be saved to
the same file.It is now possible to render course maps from multiple SVG files in a
single invocation.  (Just list all the files to be rendered on the
command line.)Teststest_layerinfo.test_layerflags_str: Fix test to deal with
arbitrary ordering ofenum.Flagflags.Release 0.2 (2018-11-07)TemplatingDo not expand text within hidden layers.  This avoids generating
error messages (e.g. "'overlay' is undefined") due to template
expansion of unused text.Add optionalskipargument to therandom_ratsfunction.
This allows the generation of more than one set of stable random rat
numbers per layer.  E.g.random_rats(skip=5)will generate a set
of random number totally uncorrelated to that generated byrandom_rats().  Usingskiphas the advantage over usingseed=Nonethat the results are stable and do not vary from
render to render.Release 0.1 (2018-11-07)Python 3.7 is now supported.The template for the output filename has been generalized to work
sensibly in the case where overlays are nested more than two deep.TemplatingAdded new attributes to layers:layer.is_overlayBoolean.  True if layer is an overlay.layer.lineageSequence starting with layer and including each parent layer in
turn.layer.overlayReturns the nearest overlay layer.  If the layer is an overlay,layer.overlayreturnslayer, otherwise it returns the
nearest parent layer which is an overlay.  If the layer is not
contained within an overlay, returnsNone.Added new values to context when expanding text in SVG:overlaysA list of all overlay layers in the lineage of the text
element, in order from outermost to innermost.courseThe outermost overlay layer.  (Equivalent tooverlays[0].)
This value already existed in the context used for filename expansion.overlayIf the element is at least two overlays deep, this is the
innermost overlay.  Otherwise it is unset.  This value already
existed in the context used for filename expansion.Added new values to context when expanding output filenames:overlaysA list of all overlay layers in the lineage of the overlay
being expanded.BugsTemplating: thesafepathfilter would fail with aTypeErrorif applied to anything but a string.  Now it coerces its argument to
text.Templating: (New style) layer flags in parent layers were not being
removed from the layer labels.  (E.g."{{ layer.parent.label }}"was expanding to"[o] Some Overlay", when it should expand to"Some Overlay".)Pexpect==4.4.0 appears to have a subtle brokenness whensearchwindowsizeis set to something other thanNone.  The
problem seems to be inpexpect.expect.py, and is triggered when
multiple chunks of output are read before a match is found.Bit-RotUselog.warning, rather than the deprecatedlog.warn.Release 0.1a12 (2017-02-09)Remove tags from layer.label when expanding templated text in SVG file.Release 0.1a11 (2017-02-01)Add--versioncommand line optionPager forcoordsA fancy pager (poor man'sless) has been added for viewing the
output of thebarnhunt coordssub-command.  If any ofsys.stdinorsys.stdoutis not a tty, then the pager will be disabled.Since there is now a fancy pager, the default for--number-of-rowshas been increased to 1000.Release 0.1a10 (2017-01-30)Things still to be fixedThings still to be fixed: I'm pretty sure things are direly broken if
a drawing contains no overlays, and somewhat broken if a drawing
contains more than two layers of overlays.  The problems have to do
with how the output PDF filenames are determined...New layer flag schemeNew scheme for marking overlay and hidden layers.  One can now set
bit-flags on layers by including the flags in square brackets at the
beginning of the layer label.  I.e. a label like"[o] Master Trial 1"marks the layer as an overlay layer, while"[h] Prototypes"marks a hidden layer.If no layers have any flags,barnhunt pdfswill fall back to the
old name-based heuristics for determining hidden and overlay layers.Release 0.1a9 (2017-01-03)When exporting PDFs, runinkscapewith--export-area-page.PackagingFix MANIFEST.in. Tests were not being included in sdist.Addurlto package metadata.Release 0.1a8 (2018-01-03)Ignoreringlayers when identifyingcourselayers.  (Now a layer
labeled “C8 Ring” will not be treated as a course layer.)pdfs: default--output-directoryto.(avoiding exception when no
explicit output directory is specified.)Release 0.1a7 (2017-11-18)Changebarnhunt coordsso that it omits duplicate coordinates in its output.
Also increase the default for--number-of-rowsto 50 and
add the--group-sizeparameter to separate output into groups.Release 0.1a6 (2017-11-15)Templating:LabelAdapternow stringifies to the layer label, andFileAdapternow stringifies to the file name.More refactoring, more testsRun several inkscapes in parallel.  This results in a major speedup.Release 0.1a5 (2017-11-13)Expand text in SVG file.Add tests.Major code refactor.Release 0.1a4 (2017-11-10)PDFSLog unexpected output from inkscape.Add--no-shell-mode-inkscapeoption to control whether shell-mode inkscape
optimization is used.Release 0.1a3.post1 (2017-11-10)PDFSReverse order that layers are considered.  (Layers are listed from
bottom to top in the SVG file.)Release 0.1a3 (2017-11-10)PDFSReplace spaces and other shell-unfriendly characters with underscores
in output file names.Release 0.1a2 (2017-11-09)Add sub-commands for generating random numbers.Release 0.1a1 (2017-11-07)Initial release.