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

Convert to an installable python package #148

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
if: (steps.parse_user.outputs.permission == 'admin')
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .

- name: run leanproject
if: (steps.parse_user.outputs.permission == 'admin')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .

- name: run leanproject
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/.vscode
/.venv
/__pycache__

*.egg-info
2 changes: 1 addition & 1 deletion gen_docs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ bash "$source"scripts/mk_all.sh
lean src/entrypoint.lean >export.json
bash "$source"scripts/rm_all.sh

python3 print_docs.py -r "$source" -w "$site_root" "${args[@]}"
lean-doc-gen -r "$source" -w "$site_root" "${args[@]}"
Copy link
Member

Choose a reason for hiding this comment

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

Please make it possible to run doc-gen and gen_docs without installing the package. python -m lean_doc_gen fails here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do we care about supporting non-installed packages?

Note that even with the package installed, python -m lean_doc_gen fails here; but that's only because it picks up the non-installed version in the current directory. If I moved lean_doc_gen to python_src/lean_doc_gen, or just changed the working directory when running this script, then that wouldn't happen.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we care about supporting non-installed packages?

Because I'm using that for development and I'm not keen on changing my ways. If we require installation then the readme must be updated. I believe there was a flag where pip just symlinks the package during installation, so that you don't need to reinstall after every change.

7 changes: 4 additions & 3 deletions print_docs.py → lean_doc_gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
from typing import NamedTuple, List, Optional
import sys

from mistletoe_renderer import CustomHTMLRenderer
import pybtex.database
from pybtex.style.labels.alpha import LabelStyle
from pylatexenc.latex2text import LatexNodes2Text
import networkx as nx

from .mistletoe_renderer import CustomHTMLRenderer

root = os.getcwd()

from jinja2 import Environment, FileSystemLoader, select_autoescape
from jinja2 import Environment, PackageLoader, select_autoescape
env = Environment(
loader=FileSystemLoader('templates', 'utf-8'),
loader=PackageLoader('lean_doc_gen', encoding='utf-8'),
autoescape=select_autoescape(['html', 'xml'])
)
env.globals['sorted'] = sorted
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pygments.lexers import get_lexer_by_name as get_lexer
from pygments.formatters.html import HtmlFormatter

from mathjax_editing import remove_math, replace_math
from .mathjax_editing import remove_math, replace_math

class RawUrl(span_token.SpanToken):
"""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Make sure that olean files are generated for mathlib in `_target`, otherwise thi

## Usage

Install the python package using `pip install -e .`, which sets it up using a symlink so that
you do not need to reinstall it after each edit.

`./gen_docs` will create a directory `html` with the generated documentation.

The links will point to `/` as the root of the site.
Expand Down
40 changes: 40 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[metadata]
name = lean_doc_gen
version = 0.0.1
author = Mathlib Community
description = A documentation builder for lean code
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/leanprover-community/doc-gen
project_urls =
Bug Tracker = https://github.com/leanprover-community/doc-gen/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent

[options]
package_dir =
=.
packages = lean_doc_gen
python_requires = >=3.8
install_requires =
mistletoe>=0.7.2
toml
mathlibtools
pygments >= 2.7.1
jinja2
networkx
pybtex>=0.22.2
latexcodec>=2.0.0
PyYAML>=5.3.1
six>=1.15.0
pylatexenc>=2.4

[options.package_data]
lean_doc_gen =
templates/*.j2

[options.entry_points]
console_scripts =
lean-doc-gen = lean_doc_gen:main