addressed review comments

Added prefix for code urls
Changed Domain class name

Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
This commit is contained in:
Alessandro Comodi 2019-09-04 13:01:23 +02:00
parent 78ffa253ff
commit 68eb426527
3 changed files with 36 additions and 21 deletions

View File

@ -130,7 +130,7 @@ do.
There are also "minitests" which are designs which can be viewed by a human in There are also "minitests" which are designs which can be viewed by a human in
Vivado to better understand how to generate more useful designs. Vivado to better understand how to generate more useful designs.
### [Experiments](https://github.com/SymbiFlow/prjxray/blob/master/experiments) ### [Experiments](experiments)
Experiments are like "minitests" except are only useful for a short period of Experiments are like "minitests" except are only useful for a short period of
time. Files are committed here to allow people to see how we are trying to time. Files are committed here to allow people to see how we are trying to
@ -146,21 +146,21 @@ Fuzzers are the scripts which generate the large number of bitstream.
They are called "fuzzers" because they follow an approach similar to the They are called "fuzzers" because they follow an approach similar to the
[idea of software testing through fuzzing](https://en.wikipedia.org/wiki/Fuzzing). [idea of software testing through fuzzing](https://en.wikipedia.org/wiki/Fuzzing).
### [Tools](https://github.com/SymbiFlow/prjxray/blob/master/tools) & [Libs](https://github.com/SymbiFlow/prjxray/blob/master/libs) ### [Tools](tools) & [Libs](libs)
Tools & libs are useful tools (and libraries) for converting the resulting Tools & libs are useful tools (and libraries) for converting the resulting
bitstreams into various formats. bitstreams into various formats.
Binaries in the tools directory are considered more mature and stable then Binaries in the tools directory are considered more mature and stable then
those in the [utils](https://github.com/SymbiFlow/prjxray/blob/master/utils) directory and could be actively used in other those in the [utils](utils) directory and could be actively used in other
projects. projects.
### [Utils](https://github.com/SymbiFlow/prjxray/blob/master/utils) ### [Utils](utils)
Utils are various tools which are still highly experimental. These tools should Utils are various tools which are still highly experimental. These tools should
only be used inside this repository. only be used inside this repository.
### [Third Party](https://github.com/SymbiFlow/prjxray/blob/master/third_party) ### [Third Party](third_party)
Third party contains code not developed as part of Project X-Ray. Third party contains code not developed as part of Project X-Ray.
@ -168,7 +168,7 @@ Third party contains code not developed as part of Project X-Ray.
# Database # Database
Running the all fuzzers in order will produce a database which documents the Running the all fuzzers in order will produce a database which documents the
bitstream format in the [database](https://github.com/SymbiFlow/prjxray/blob/master/database) directory. bitstream format in the [database](database) directory.
As running all these fuzzers can take significant time, As running all these fuzzers can take significant time,
[Tim 'mithro' Ansell <me@mith.ro>](https://github.com/mithro) has graciously [Tim 'mithro' Ansell <me@mith.ro>](https://github.com/mithro) has graciously

View File

@ -24,7 +24,7 @@ import recommonmark
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('.'))
from markdown_code_symlinks import LinkParser, PrjxrayDomain from markdown_code_symlinks import LinkParser, MarkdownSymlinksDomain
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
@ -196,9 +196,12 @@ intersphinx_mapping = {'https://docs.python.org/': None}
def setup(app): def setup(app):
PrjxrayDomain.find_links() github_code_repo = 'https://github.com/SymbiFlow/prjxray/'
app.add_domain(PrjxrayDomain)
MarkdownSymlinksDomain.find_links()
MarkdownSymlinksDomain.add_github_repo(github_code_repo, 'blob/master/')
app.add_domain(MarkdownSymlinksDomain)
app.add_config_value( app.add_config_value(
'recommonmark_config', { 'recommonmark_config', {
'github_code_repo': 'https://github.com/SymbiFlow/prjxray', 'github_code_repo': github_code_repo,
}, True) }, True)

View File

@ -66,14 +66,14 @@ def relative(parent_dir, child_path):
return os.path.relpath(child_path, start=parent_dir) return os.path.relpath(child_path, start=parent_dir)
class PrjxrayDomain(Domain): class MarkdownSymlinksDomain(Domain):
""" """
Extension of the Domain class to implement custom cross-reference links Extension of the Domain class to implement custom cross-reference links
solve methodology solve methodology
""" """
name = 'prjxray' name = 'markdown_symlinks'
label = 'Prjxray' label = 'MarkdownSymlinks'
roles = { roles = {
'xref': XRefRole(), 'xref': XRefRole(),
@ -87,6 +87,9 @@ class PrjxrayDomain(Domain):
'code2docs': {}, 'code2docs': {},
} }
github_repo_url = ""
github_repo_branch = ""
@classmethod @classmethod
def relative_code(cls, url): def relative_code(cls, url):
"""Get a value relative to the code directory.""" """Get a value relative to the code directory."""
@ -162,8 +165,10 @@ Current Value: {}
pprint.pprint(cls.mapping) pprint.pprint(cls.mapping)
@classmethod @classmethod
def remove_extension(cls, path): def add_github_repo(cls, github_repo_url, github_repo_branch):
return filename """Initialize the github repository to update links correctly."""
cls.github_repo_url = github_repo_url
cls.github_repo_branch = github_repo_branch
# Overriden method to solve the cross-reference link # Overriden method to solve the cross-reference link
def resolve_xref( def resolve_xref(
@ -174,11 +179,18 @@ Current Value: {}
todocname = target todocname = target
targetid = '' targetid = ''
# Removing filename extension (e.g. contributing.md -> contributing) if todocname not in self.mapping['code2docs']:
todocname, _ = os.path.splitext(self.mapping['code2docs'][todocname]) # Could be a link to a repository's code tree directory/file
todocname = '{}{}{}'.format(self.github_repo_url, self.github_repo_branch, todocname)
newnode = make_refnode( newnode = nodes.reference('', '', internal=True, refuri=todocname)
builder, fromdocname, todocname, targetid, contnode[0]) newnode.append(contnode[0])
else:
# Removing filename extension (e.g. contributing.md -> contributing)
todocname, _ = os.path.splitext(self.mapping['code2docs'][todocname])
newnode = make_refnode(
builder, fromdocname, todocname, targetid, contnode[0])
return newnode return newnode
@ -186,7 +198,7 @@ Current Value: {}
self, env, fromdocname, builder, target, node, contnode): self, env, fromdocname, builder, target, node, contnode):
res = self.resolve_xref( res = self.resolve_xref(
env, fromdocname, builder, 'xref', target, node, contnode) env, fromdocname, builder, 'xref', target, node, contnode)
return [('prjxray:xref', res)] return [('markdown_symlinks:xref', res)]
class LinkParser(parser.CommonMarkParser, object): class LinkParser(parser.CommonMarkParser, object):
@ -219,7 +231,7 @@ class LinkParser(parser.CommonMarkParser, object):
wrap_node = addnodes.pending_xref( wrap_node = addnodes.pending_xref(
reftarget=unquote(destination), reftarget=unquote(destination),
reftype='xref', reftype='xref',
refdomain='prjxray', # Added to enable cross-linking refdomain='markdown_symlinks', # Added to enable cross-linking
refexplicit=True, refexplicit=True,
refwarn=True) refwarn=True)
# TODO also not correct sourcepos # TODO also not correct sourcepos