-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process TracWiki links and formatting. (#4) #6
Conversation
42a4292
to
c869b17
Compare
This is ready for review. I have some questions:
|
needs-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done.
We also have the 3rd level of heading ... but I think that this is only in a few pages
8 matches across 8 files
But we need to create a list in README or a script (python or shell) to identify the pages and things that will need manual conversion.
I would like you to continue working on this and have a PR in which the [[PageOutline]]
macro is fixed and in which every page will have a local table of content inserted.
And then one final PR in which [[TitleIndex(Development/)]]
macro is fixed in the footer... and we should be ready with the conversion.
I only left minor comments. Feel free to addess as you wish and merge this.
For this one time conversion code I have not looks into details on how the code is written .
I was focused on the tests and they are great :)
The GitHub action integration is more about having you familiarized with GitHub action continuous testing infrastructure ... as we use it a lot.
We still have Buildbot, but the plan is to migrate to GitHub actions.
Thanks!
test/test_wiki_trac_rst_convert.py
Outdated
Process general links from TracWiki format to plain RST links | ||
""" | ||
self.assertConvertedContent( | ||
'`Buildbot <https://chevah.com/buildbot/>`_\n', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a minor comment.
I think that assertConvertedContent should be updated to automatically add the expected newline.
Otherwise these tests are confusing.
You have input as [wiki:"Administrative"]
without newlines and then the result has a newline.
I know why there is that newline, but the newline is not part of the conversion for that link.
def test_trac_ticket(self): | ||
""" | ||
Trac ticket references are converted to a hyperlink. | ||
This use case requires `config.py` with the following setting: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is ok here in the context of this project.
but otherwise this tests is fragile as it is not "self-sufficient"
It relies that before running the test you rename the sample config.
But this is ok here, and it's not worth fixing the way config works.
Also, just as an exercise. Can you please enable GitHub Actions automatic test execution for this repo?
Maybe in a separate PR.
test/test_wiki_trac_rst_convert.py
Outdated
'Heading\n=======\n', | ||
'= Heading =' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit easier to read ... you write the code a few times but read it many times... and often while you are tired and distracted by some bug or something that you don't understand :)
'Heading\n=======\n', | |
'= Heading =' | |
'Heading\n' | |
'=======\n', | |
'= Heading =' |
test/test_wiki_trac_rst_convert.py
Outdated
'Policy and Process\n' | ||
'==================\n\n' | ||
'Some text\n', | ||
|
||
'= Policy and Process =\n\n' | ||
'Some text' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Policy and Process\n' | |
'==================\n\n' | |
'Some text\n', | |
'= Policy and Process =\n\n' | |
'Some text' | |
'Policy and Process\n' | |
'==================\n' | |
'\n' | |
'Some text\n', | |
'= Policy and Process =\n' | |
'\n' | |
'Some text' |
Separates lists from paragraphs by one empty line. | ||
|
||
In RST, when lists follow a paragraph without an empty line | ||
inbetween, they fail to parse as lists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that RST is expecting to have a colon (:) at the end of the paragraph preceeding a list...
Maybe auto-add one ?
but this is also ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will leave it as is (add an empty line between), because GitHub does some very strange things with the syntax.
It either:
- (not pictured) if no newline nor one-space indent exists before list items, it does not parse it as a list, just shows the plaintext asterisks and list items continuing on the same line, or
- if there is a one-space indent, it makes the preceding sentence bold and italic:
test/test_wiki_trac_rst_convert.py
Outdated
|
||
def test_bold_is_not_list(self): | ||
""" | ||
Does not add an empty line before a line starting with italic text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a more generic description for the test.
I know that this test was caused by a bug where an empty line might have been introduced.
When possible the test should be written descripting a feature and not describing a bug :)
Does not add an empty line before a line starting with italic text. | |
Italic text markup is preserved as in the TracWiki format. |
'Some text\n', | ||
|
||
'== Subheading ==\n\n' | ||
'Some text' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor test that is missing.
Conversion from source
== Subheading ==
Test right below the heading
It would be nice to convert it as something like this with one extra newline added...
Subheading
----------
Test right below the heading
but this conversion is also ok
Subheading
----------
Test right below the heading
no need to spend more time here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test right below this one (with "Some text") ensures two \n
s already. But I will format it like you suggested for the 1st level heading test, since it is clear that the \n
s on the same line are confusing :)
I wondered what black
does. It's a problem, but they are aware of it. Look what it made of the two tests:
self.assertConvertedContent("Subheading\n" "----------", "== Subheading ==")
self.assertConvertedContent(
"Subheading\n" "----------\n" "\n" "Some text",
"== Subheading ==\n" "\n" "Some text",
)
wiki_trac_rst_convert.py
Outdated
def _tracwiki_heading_to_rst_heading(text: str): | ||
""" | ||
Convert TracWiki headings (titles surrounded by "=") to RST (titles | ||
underlined with "="). | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use some simple example in the docstring to explain how the conversion is done.
No need for all the details... we can have corner cases explained in the test code.
def _tracwiki_heading_to_rst_heading(text: str): | |
""" | |
Convert TracWiki headings (titles surrounded by "=") to RST (titles | |
underlined with "="). | |
""" | |
def _tracwiki_1st_heading_to_rst_heading(text: str): | |
""" | |
Convert TracWiki 1st level headings to RST heading. | |
TracWiki: | |
= Some Top Heading = | |
Content here | |
RST conversion: | |
Some Top Heading | |
---------------- | |
Content here | |
""" |
test/test_wiki_trac_rst_convert.py
Outdated
@@ -3,10 +3,10 @@ | |||
from wiki_trac_rst_convert import convert_content | |||
|
|||
|
|||
class TracRstToVanillaRst(unittest.TestCase): | |||
class TracToGithubRst(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming is complicated ... but I think that the correct speling is GitHub ...also, when we have an abreviation like RST or URL, we keep upper case in the Python name.
so we prefer getURL
and not getUrl
class TracToGithubRst(unittest.TestCase): | |
class TracToGitHubRST(unittest.TestCase): |
e34276e
to
cfb4135
Compare
Scope
There are TracWiki markup links which need to be converted. Here are examples of files (taken from #2 (comment)_ ):
At first, we can use this ticket to convert RST Trac links directives.
Later we should look at converting whole TracWiki pages.
Changes
TracWiki links should now work. I have added a new match case to
_trac_rst_wiki_to_github_links
, as well as new methods that handle TracWiki link syntax (with or without link text different from the article).Also Trac tickets should work. There were only 3 of them, but it was easy enough to automate.
Only one malformed
:trac:
reference remains, which will be addressed manually.TracWiki syntax: the script handles the following:
What is not done
About lists: I did not properly implement nesting. I started to, but it turned out to be too difficult for me, considering the diminishing returns. An exhaustive (as of 2021-01-27) list of failures:
In addition,
{{{ }}}
code blocks need to be converted manually, by searching for{{{
in a commit before stripping the{{{#!rst }}}
armor.How to try and test the changes
reviewers: @adiroiban
First, copy the
config.py.sample
toconfig.py
, because the Trac URL is specified as a config option.Then, continue testing like PR #3: