Skip to content
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

Merged
merged 6 commits into from
Jan 28, 2021
Merged

Conversation

danuker
Copy link
Contributor

@danuker danuker commented Jan 26, 2021

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:

  • title/heading syntax: heading (===) and subheading (---)
  • lists: it unindents single-space-quoted lists, and adds an empty line before the first list element. The majority of files looks good; but nesting conversion is not proper.

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:

  • Architecture/Agent/General section "Remote file", under "steps"
  • Development/GetToKnow section "Products documentation and download pages".
  • Infrastructure/OutOfOrderMachines Mosna under "network cards"
  • Infrastructure/Services/VPN under "Overton"
  • Requirements/Vision, last two list items on page
  • Support/General section "Initial Assessment"
  • Support/CustomerDataBase/Template.rst and some files created from that template.

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 to config.py, because the Trac URL is specified as a config option.

Then, continue testing like PR #3:

Run tests using unittest from the project directory:
python3.8 -m unittest

Checking output

I did not find an easy way to verify the GitHub link behavior. The only way to properly test is to run the conversion, then push and check the wiki.

There are some things you can still check locally:

  • run the script, and then look at the diff using gitk, with the "Ignore space change" checkbox checked.

  • check what :trac: markers are left

@danuker danuker linked an issue Jan 26, 2021 that may be closed by this pull request
@danuker danuker force-pushed the 4_tracwiki_to_github branch from 42a4292 to c869b17 Compare January 26, 2021 15:16
@danuker
Copy link
Contributor Author

danuker commented Jan 27, 2021

This is ready for review.

I have some questions:

  • Is there any way to further deduplicate all the _trac[...] methods? They seem to rhyme to me, but could not quite extract another method from sections that repeat.
  • Are the tiny methods overkill? (_underline, _matches, _sub)? To me they look okay.

@danuker
Copy link
Contributor Author

danuker commented Jan 27, 2021

needs-review

@danuker danuker marked this pull request as ready for review January 27, 2021 17:07
@danuker danuker changed the title WIP: TracWiki links and formatting (#4) TracWiki links and formatting (#4) Jan 27, 2021
Copy link
Member

@adiroiban adiroiban left a 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!

Process general links from TracWiki format to plain RST links
"""
self.assertConvertedContent(
'`Buildbot <https://chevah.com/buildbot/>`_\n',
Copy link
Member

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:
Copy link
Member

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.

Comment on lines 174 to 180
'Heading\n=======\n',
'= Heading ='
Copy link
Member

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 :)

Suggested change
'Heading\n=======\n',
'= Heading ='
'Heading\n'
'=======\n',
'= Heading ='

Comment on lines 178 to 190
'Policy and Process\n'
'==================\n\n'
'Some text\n',

'= Policy and Process =\n\n'
'Some text'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'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.
Copy link
Member

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.

Copy link
Contributor Author

@danuker danuker Jan 28, 2021

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:

gh-rst


def test_bold_is_not_list(self):
"""
Does not add an empty line before a line starting with italic text.
Copy link
Member

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 :)

Suggested change
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'
Copy link
Member

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

Copy link
Contributor Author

@danuker danuker Jan 28, 2021

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 \ns already. But I will format it like you suggested for the 1st level heading test, since it is clear that the \ns 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",
)

Comment on lines 142 to 157
def _tracwiki_heading_to_rst_heading(text: str):
"""
Convert TracWiki headings (titles surrounded by "=") to RST (titles
underlined with "=").
"""
Copy link
Member

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.

Suggested change
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
"""

@@ -3,10 +3,10 @@
from wiki_trac_rst_convert import convert_content


class TracRstToVanillaRst(unittest.TestCase):
class TracToGithubRst(unittest.TestCase):
Copy link
Member

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

Suggested change
class TracToGithubRst(unittest.TestCase):
class TracToGitHubRST(unittest.TestCase):

@danuker danuker force-pushed the 4_tracwiki_to_github branch from e34276e to cfb4135 Compare January 28, 2021 11:01
@danuker danuker changed the title TracWiki links and formatting (#4) Process TracWiki links and formatting. (#4) Jan 28, 2021
@danuker danuker merged commit f1c19a7 into main Jan 28, 2021
@adiroiban adiroiban deleted the 4_tracwiki_to_github branch January 28, 2021 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert TracWiki syntax to GitHub-friendly RST
3 participants