diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..b6555ee --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,30 @@ +name: Python package + +on: + push: + branches: [ '*' ] + pull_request: + branches: [ '*' ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + - name: Build Sphinx test project + run: | + cd sphinx_lua/test + sphinx-build -b html -W . _build diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..8ee9fd3 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,29 @@ +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 462ba37..4045454 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__/ .idea sphinx_lua.egg-info sphinx_lua/test/build/ +_build/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ce5650d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -sudo: false -language: python -addons: - apt: - packages: - - npm -python: - - "2.7" - - "3.6" -install: - - npm install jsdoc@3.5.5 - - pip install tox-travis -script: - - PATH=$TRAVIS_BUILD_DIR/node_modules/.bin:$PATH tox diff --git a/setup.py b/setup.py index cafe011..a01cdee 100644 --- a/setup.py +++ b/setup.py @@ -39,11 +39,13 @@ 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: Documentation :: Sphinx', 'Topic :: Software Development :: Documentation' ], + python_requires='>=3.9', keywords=['sphinx', 'documentation', 'docs', 'lua', 'luadoc', 'restructured'], ) diff --git a/sphinx_lua/renderers.py b/sphinx_lua/renderers.py index d5226ba..fc88cf7 100644 --- a/sphinx_lua/renderers.py +++ b/sphinx_lua/renderers.py @@ -79,10 +79,14 @@ def process_link(s): def start_stop_line(doc_node, file_path): """ Return start stop line in the form '1-5' """ - file = open(os.path.join(self._app.confdir, file_path), "r") - start_line = file.read(doc_node.start_char).count('\n') + 1 - stop_line = file.read(doc_node.stop_char - doc_node.start_char).count('\n') + 1 + start_line - file.close() + file_path = os.path.join(self._app.confdir, file_path) + with open(file_path, "r") as f: + content = f.read() + total_lines = content.count('\n') + 1 + start_line = content[:doc_node.start_char].count('\n') + 1 + stop_line = content[:doc_node.stop_char].count('\n') + 1 + # Clamp to actual file line count (avoid "out of range" with Sphinx -W) + stop_line = min(stop_line, total_lines) return str(start_line) + "-" + str(stop_line) # Render to RST using Jinja: