Skip to content

Commit

Permalink
Merge pull request #95 from modular-ml/dev
Browse files Browse the repository at this point in the history
Refactored with code style Black
  • Loading branch information
fabawi committed Feb 12, 2024
2 parents ad7a64e + 61d906d commit a347e02
Show file tree
Hide file tree
Showing 91 changed files with 5,944 additions and 2,106 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/manual_update_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
# sed -i.bak -E "s|<version>[^<]+</version>|<version>$VERSION</version>|" wrapyfi_extensions/wrapyfi_ros2_interfaces/package.xml
# sed -i.bak -E "s|<version>[^<]+</version>|<version>$VERSION</version>|" wrapyfi_extensions/wrapyfi_ros_interfaces/package.xml

- name: Refactor with Code Black
run: |
python3 -m pip install black
black .
- name: Generate Documentation
run: |
cd docs
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
[![arXiv](https://custom-icon-badges.demolab.com/badge/arXiv:2302.09648-lightyellow.svg?logo=arxiv-logomark-small)](https://arxiv.org/abs/2302.09648 "arXiv link")
[![doi](https://custom-icon-badges.demolab.com/badge/10.1145/3610977.3637471-lightyellow.svg?logo=doi_logo)](https://doi.org/10.1145/3610977.3637471 "doi link")



[![License](https://custom-icon-badges.demolab.com/github/license/denvercoder1/custom-icon-badges?logo=law&logoColor=white)](https://github.com/fabawi/wrapyfi/blob/main/LICENSE "license MIT")
[![FOSSA status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmodular-ml%2Fwrapyfi.svg?type=shield&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmodular-ml%2Fwrapyfi?ref=badge_shield&issueType=license)
[![Documentation status](https://readthedocs.org/projects/wrapyfi/badge/?version=latest)](https://wrapyfi.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/github/modular-ml/wrapyfi/graph/badge.svg?token=5SD1A6ENKE)](https://codecov.io/github/modular-ml/wrapyfi)

[![codecov](https://codecov.io/github/modular-ml/wrapyfi/graph/badge.svg?token=5SD1A6ENKE)](https://codecov.io/github/modular-ml/wrapyfi)
[![PyPI version](https://badge.fury.io/py/wrapyfi.svg)](https://badge.fury.io/py/wrapyfi)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io/ "code style link")
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/wrapyfi)](https://pypi.org/project/wrapyfi/ "implementation")
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/wrapyfi)](https://pypi.org/project/wrapyfi/ "python version")
[![PyPI total downloads](https://img.shields.io/pepy/dt/wrapyfi)](https://www.pepy.tech/projects/wrapyfi)
[![Docker Hub Pulls](https://img.shields.io/docker/pulls/modularml/wrapyfi.svg)](https://hub.docker.com/repository/docker/modularml/wrapyfi)

Expand Down
24 changes: 11 additions & 13 deletions docs/_extensions/link_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@
import re

REPLACEMENTS = {
'https://github.com/fabawi/wrapyfi/tree/main/wrapyfi_extensions/yarp/README.md':
'yarp_install_lnk.html',
'https://github.com/modular-ml/wrapyfi_ros2_interfaces/blob/master/README.md':
'ros2_interfaces_lnk.html',
'https://github.com/modular-ml/wrapyfi_ros_interfaces/blob/master/README.md':
'ros_interfaces_lnk.html',
'https://github.com/fabawi/wrapyfi/tree/main/dockerfiles/README.md':
'wrapyfi_docker_lnk.html',
"https://github.com/fabawi/wrapyfi/tree/main/wrapyfi_extensions/yarp/README.md": "yarp_install_lnk.html",
"https://github.com/modular-ml/wrapyfi_ros2_interfaces/blob/master/README.md": "ros2_interfaces_lnk.html",
"https://github.com/modular-ml/wrapyfi_ros_interfaces/blob/master/README.md": "ros_interfaces_lnk.html",
"https://github.com/fabawi/wrapyfi/tree/main/dockerfiles/README.md": "wrapyfi_docker_lnk.html",
}


class LinkModifier(SphinxTransform):
default_priority = 999

def apply(self):
for node in self.document.traverse(nodes.reference):
uri = node.get('refuri', '')
uri = node.get("refuri", "")
for link in REPLACEMENTS.keys():
if link in uri:
# Extract rank value
match = re.search(r'\?rank=(-?\d+)', uri)
match = re.search(r"\?rank=(-?\d+)", uri)
if match:
rank = int(match.group(1))
if rank < 0:
prefix = '../' * -rank
prefix = "../" * -rank
new_uri = prefix + REPLACEMENTS[link]
else:
new_uri = REPLACEMENTS[link]
else:
# Default to rank -2 if no rank parameter
new_uri = '../../' + REPLACEMENTS[link]
new_uri = "../../" + REPLACEMENTS[link]

node["refuri"] = uri.replace(link, new_uri)

node['refuri'] = uri.replace(link, new_uri)

def setup(app):
app.add_transform(LinkModifier)
4 changes: 3 additions & 1 deletion docs/_extensions/math_block_converter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from sphinx.application import Sphinx
import re


def convert_math_blocks(app: Sphinx, docname: str, source: list):
if source:
source[0] = re.sub(r'```math', '```{math}', source[0])
source[0] = re.sub(r"```math", "```{math}", source[0])


def setup(app: Sphinx):
app.connect("source-read", convert_math_blocks)
95 changes: 54 additions & 41 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,41 @@
import ast
import json


def get_project_info_from_setup():
curr_dir = os.path.dirname(__file__)
setup_path = os.path.join(curr_dir, '..', 'setup.py')
with open(setup_path, 'r') as f:
setup_path = os.path.join(curr_dir, "..", "setup.py")
with open(setup_path, "r") as f:
content = f.read()

name_match = re.search(r"name\s*=\s*['\"]([^'\"]*)['\"]", content)
version_match = re.search(r"version\s*=\s*['\"]([^'\"]*)['\"]", content)
url_match = re.search(r"url\s*=\s*['\"]([^'\"]*)['\"]", content)
author_match = re.search(r"author\s*=\s*['\"]([^'\"]*)['\"]", content)

if not name_match or not version_match or not url_match:
raise RuntimeError("Unable to find name, version, url, or author string.")

return {
'name': name_match.group(1),
'version': version_match.group(1),
'url': url_match.group(1),
'author': author_match.group(1)
"name": name_match.group(1),
"version": version_match.group(1),
"url": url_match.group(1),
"author": author_match.group(1),
}


def get_imported_modules(package_name):
package = importlib.import_module(package_name)
imported_modules = []
for _, module_name, _ in pkgutil.walk_packages(path=package.__path__,
prefix=package.__name__ + '.',
onerror=lambda x: None):
for _, module_name, _ in pkgutil.walk_packages(
path=package.__path__, prefix=package.__name__ + ".", onerror=lambda x: None
):
imported_modules.append(module_name)
return imported_modules


def get_all_imports_in_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
with open(file_path, "r", encoding="utf-8") as file:
tree = ast.parse(file.read(), filename=file_path)

imports = set()
Expand All @@ -57,37 +58,45 @@ def get_all_imports_in_package(package_path):
all_imports = set()
for root, dirs, files in os.walk(package_path):
for file in files:
if file.endswith('.py'):
if file.endswith(".py"):
file_path = os.path.join(root, file)
all_imports.update(get_all_imports_in_file(file_path))

return all_imports


def setup(app):
app.add_css_file('wide_theme.css')
app.add_css_file("wide_theme.css")


autodoc_default_options = {
'members': True,
'member-order': 'bysource',
'special-members': '__init__',
'undoc-members': True,
'exclude-members': '__weakref__'
"members": True,
"member-order": "bysource",
"special-members": "__init__",
"undoc-members": True,
"exclude-members": "__weakref__",
}
main_doc = 'index'
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_css_files = ['wide_theme.css']

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'myst_parser', 'sphinx.ext.mathjax',
'math_block_converter', 'link_modifier']
source_suffix = ['.rst', '.md']
main_doc = "index"
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
html_css_files = ["wide_theme.css"]

extensions = [
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.autodoc",
"myst_parser",
"sphinx.ext.mathjax",
"math_block_converter",
"link_modifier",
]
source_suffix = [".rst", ".md"]
exclude_patterns = ["_build"]

myst_enable_extensions = ["dollarmath", "amsmath"]

# mock all libraries except for the ones that are installed
with open('exclude_packages.json', 'r') as f:
with open("exclude_packages.json", "r") as f:
all_imported_modules_pre = set(x for x in json.load(f) if x is not None)
print(all_imported_modules_pre)
# all_imported_modules = get_all_imports_in_package("wrapyfi")
Expand All @@ -100,27 +109,31 @@ def setup(app):
# extract project info
project_info = get_project_info_from_setup()

project = project_info['name']
release = project_info['version']
version = '.'.join(release.split('.')[:2])
url = project_info['url']
author = project_info['author']
project = project_info["name"]
release = project_info["version"]
version = ".".join(release.split(".")[:2])
url = project_info["url"]
author = project_info["author"]

# modify the latex cover page for pdf generation
latex_elements = {
'preamble': r'''
"preamble": r"""
\usepackage{titling}
\pretitle{%
\begin{center}
\vspace{\droptitle}
\includegraphics[width=60mm]{../assets/wrapyfi.png}\\[\bigskipamount]
\Large{\textbf{''' + project + '''}}\\
\normalsize{v''' + release + '''}
\Large{\textbf{"""
+ project
+ """}}\\
\normalsize{v"""
+ release
+ """}
}
\posttitle{\end{center}}
'''
"""
}

sys.path.insert(0, os.path.abspath('../'))
sys.path.append(os.path.abspath('./_extensions'))
sys.path.append(os.path.abspath('./mock_imports'))
sys.path.insert(0, os.path.abspath("../"))
sys.path.append(os.path.abspath("./_extensions"))
sys.path.append(os.path.abspath("./mock_imports"))
2 changes: 1 addition & 1 deletion docs/mock_imports/geometry_msgs/msg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def __init__(self, *args, **kwargs):

class Quaternion(object):
def __init__(self, *args, **kwargs):
pass
pass
2 changes: 1 addition & 1 deletion docs/mock_imports/rclpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Parameter(object):
def __init__(self, *args, **kwargs):
pass
pass
2 changes: 1 addition & 1 deletion docs/mock_imports/std_msgs/msg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class String(object):
def __init__(self, *args, **kwargs):
pass
pass
Loading

0 comments on commit a347e02

Please sign in to comment.