epydoc: Blocks of fixed-width text - markup

I have written a software component that relies on a configuration file. For clarity, I want to document the structure of the configuration file by adding an example file in the docstring of the relevant class. For obvious reasons, it should appear in fixed-width font.
The only way I know is adding >>> before each line, which is bad because doctest might think this is a Python code segment and lose its wits. Moreover, it looks really ugly:
>>> [db]
>>> port = 5432
>>> name = adam_db
...
What I really want is:
[db]
port=5432
name=adam_db
...
In a fixed-width font.
Any ideas?
Thanks,
Adam

Maybe you could use the Literal Block option.

Related

Automatically format YAML to use dot separator where possible

I am using IntelliJ and want to find a quick way to format a lot of yaml files from this:
something:
some:
thing:
enable: true
a:
b:
c: true
d:
e: false
to this:
something.some.thing.enable: true
a.b:
c: true
d.e: false
whereever possible. It is still valid syntax, but in the files in question, it is way better to read and often times, elements really just contain one value.
Is there an offline tool, plugin or maven/gradle build step I can use to achieve this?
It is still valid syntax
Yes, but it doesn't do what you think it does. d.e in YAML will simply load as string "d.e". There is no YAML logic that splits at the dot like you seem to assume.
Java Spring does some postprocessing that causes this to be loaded properly, see also this question. However, this does not work generally with YAML.
See this answer for a yq command that does something like this – however it will print a full path for each value and you probably don't want that. Doing what you want is probably too complex for yq, but not impossible to achieve.
Also mind that queries about finding external tools are off-topic on StackOverflow.

How to use $ (dollar sign) ^(exponent sign) in yaml?

I saw a YAML file that includes some signs like $, ^. For $, I think it tries to get value from a JSON file. But for ^, I'm not sure about that.
I tried to search for the YAML syntax but cannot find the usage of those signs.
Could anyone point out where that usage from? Thanks a lot!
examples:
json: $.A.Documents[*]
input: ^.B.ID
YAML doesn't assign any special meaning to those characters. As far as YAML is concerned, they are simply part of the content.
Of course, the software loading that YAML can do anything with the loaded data – including inspecting the loaded scalars for $ and ^ and implementing some action on them.
While someone might be able to correctly guess which software expects a YAML file like the one you show, it would be vastly easier for you to check the context in which you found that YAML file. This should lead you to the information you seek – i.e., for which software that YAML file has been written. That software's documentation will then describe how those characters are processed.

Markup for Sphinx formatting of argparse

I am using Sphinx/reStructuredText to create HTML and PDF docs for a project and am including the output of the argparse help for the command line tools. At the moment I am pasting the output in manually but plan at some point to switch to autogenerated output.
The problem is that while the formatting is fine for named parameters (like -x or --xray) it doesn't work well on positional parameters. It looks like the absence of a leading '-' on the parameter name is confusing it. The output looks like normal text without the neat indentation etc.
So my question is, does there exist markup that would force formatting the positional parameters as if they had leading '-' characters? If not, could someone suggest where in the docs or code I should start looking to put something together myself?
You may use sphinx-argparse extension.
It does not use output of argparse help, but it instead introspects argparse parser itself and provides proper sphinx markup for both positional arguments and options, formatting them as definition list with proper labels.
Sub-commands are also easily handled.
http://sphinx-argparse.readthedocs.org/en/latest/
It will also cover you needs in:
plan at some point to switch to autogenerated output

Line breaks don't show up right in YAML?

I am looking at a YAML config file for a database, and all I see is a big jumble of text. However, I notice that there is a missing character every now and then if I use my keyboard's arrow keys to navigate around, I notice that there is occasionally a spot where the cursor gets stuck and requires me to press the arrow key two times instead of one. I am currently assuming that this is a line break that only YAML parsers can read. When I force a line break by pressing ENTER, the YAML parser does not understand the config file anymore. How can I get past this limitation without using a non-windows program? This line break has a Hex value of 0A.
As requested, a snippet of what the current YAML text looks like and what I would like it to look like can be found at the links below (due to StackExchange's limited use of indents. Note that these are two different files for a game's configuration. The API for the parser is here.
What I would like the config to look like
What the config currently looks like
It has also come to my attention that the second link might show it as a YAML file since it registers the line-break as a line break. However, the chunk below might give you an idea of what it looks like to me.
RWtorchLight: Version 1.2 made by MYCRAFTisbest
indent1: ''
NOTE: 'The Meta data valuse is the number after the :'
For Example: Black wool, put 35 in Light_Block and 15 in Meta Data
Light_Block: 89
Meta_Deta_LB: 0
IMPORTANT: The torch and boots are not compatable with Meta Data yet
Torch_Item: 50
Helmet_Item: 314
Boot_Item: 317
indent2: ''
Torch_Use: true
Helmet_Use: true
Boot_Use: true
T-or-T Mode: Will create dim light when wearing pumpkin and all below features
Trick-or-Treat Mode: true
C of C: Chance of Cookie is the chance of how often trick-or-treaters get candy
Set to: '"0" for no chance'
Chance of Cookie: 5000
N of C: 'Will randomly chose a number between 1 and # when Cookies are received'
Number of Cookies: 5
BACKGROUND
After reviewing your question and the associated discussion in comments, a likely case is your YAML file is being corrupted either by:
notepad.exe;
your FTP/SFTP/Web page/whatever used for uploading the text; OR
a combination of both of the above
PROBLEM
YAML syntax is whitespace and indentation sensitive, and using MSFT notepad.exe is not recommended because it may not support the encoding specified in your YAML file.
Since YAML uses whitespace to delimit the data, any kind of modification to the text that is not consistent with the original encoding and whitespace of the original YAML will potentially render the file unusable.
This is one of the aspects of YAML that makes it potentially more brittle than alternative formats, such as JSON or XML.
SOLUTION
Use another editor such as Notepad++ (as recommended in the comments) or, if you do not have sufficient privileges to install another text editor, use an online text editor such as editpad (http://www.editpad.org/) to edit and save the YAML to a local file on your machine.
After saving the file to your local machine using a text editor besides notepad.exe, upload your file using an option that does not apply any kind of text filter to the text.
For example, some websites strip out characters from user-uploaded text to prevent things data corruption and security risks.
STEP BY STEP
start with a known well-formed YAML file, such as the one you specified in "What I would like the config to look like"
paste it into Notepad++ (local machine) or editpad (web-based editor)
modify the YAML file so it matches the settings you want
save your modifications to the original file
upload the file via SFTP or other means that preserves the original encoding

Formatting Issue when Using Manipulate to display Lists

Please consider the following problem.
I'm writing a quick Manipulate[] program to display a ton of information, but am running into problem with the unicode. Here is what I currently have as input and output:
Manipulate[
request = filenumber <> "*";
filenames = FileNames[request];
display = Import[type, "List"];
Short[display, 25]
, {filenumber, "001", InputField}, {type, filenames, PopupMenu}]
The problem is that the French-language accents are showing up oddly. The quick workaround I thought of was to change my code to Import[type,"Plaintext"]; which works, but then displays the information in list form, like so:
What would you suggest as a way to get the clarity of the second example with the straightforward list format of the former? So that it wraps on the line rather than having a line break after each entry.
As an aside - probably just as important as the actual question itself - could anybody explain the rationale behind why importing as a "List" distorts the unicode? I've had a lot of trouble working around this, and understanding the underlying behaviour might help me move forward quicker.
Although Import does not have options associated with itself, it takes options relevant to the format being imported. Specifically see the Options section of ref/Format/List for the list of options.
In the case at hand, you can indicate the file encoding with CharacterEncoding->"UTF8":
Import[filename, "List", CharacterEncoding -> "UTF8"]

Resources