Skip to content

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tanbro committed Jun 1, 2024
2 parents e122813 + ea59854 commit 579d82b
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 185 deletions.
2 changes: 2 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
files = src/**/*.py
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-added-large-files
Expand All @@ -12,17 +12,24 @@ repos:
- id: trailing-whitespace
- id: check-yaml
- id: check-toml
# - id: check-ast
- id: check-ast
- id: check-docstring-first

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.2
rev: v0.4.7
hooks:
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.10.0"
hooks:
- id: mypy
args: [--ignore-missing-imports, --config-file, .mypy.ini]
additional_dependencies: [types-PyYAML]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.28.0"
rev: "0.28.4"
hooks:
- id: check-github-workflows
- id: check-readthedocs
3 changes: 0 additions & 3 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ src = ["src"]
extend-exclude = ["docs"]
line-length = 128

[lint]
ignore-init-module-imports = true

[lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.4

> 📅 **Date** 2024-6-1
- 🆕 New Features:
- Add `py.typed` file, make the package PEP-561 friendly

- Better type hints
- Some optimizations and bugfix

## 0.4rc1

> 📅 **Date** 2024-3-15
Expand Down
41 changes: 41 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,44 @@ README

.. include:: ../README.md
:parser: myst_parser.sphinx_

How to build docs
-----------------

#. This documentation is made with `Sphinx <https://www.sphinx-doc.org/>`_, be sure to install it's dependencies:

.. code:: sh
pip install -r docs/requirements.txt
Ignore this step if requirements already installed.

#. (*Optional*) Re-generate API-Docs, if source tree changed:

.. code:: sh
sphinx-apidoc -o docs/apidocs -eMTf src
#. Build HTML documentation:

.. code:: sh
docs/make html
The built static web site is output to ``docs/_build/html``, we can serve it:

.. code:: sh
python -m http.server -d docs/_build/html
then open http://localhost:8000/ in a web browser.

.. tip::
Try another port if ``8000`` is already in use.
For example, to serve on port ``8080``:

.. code:: sh
python -m http.server -d docs/_build/html 8080
.. seealso:: Python ``stdlib``'s :mod:`http.server`
70 changes: 35 additions & 35 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ changelog = "https://github.com/tanbro/jinjyaml/blob/master/CHANGELOG.md"
[tool.setuptools.packages.find]
where = ["src"] # list of folders that contain the packages (["."] by default)

[tool.setuptools.package-data]
pyyaml_include = ["jinjyaml/py.typed"]

[tool.setuptools_scm]
# version_scheme = "guess-next-dev" # guess-next-dev or post-release
write_to = "src/jinjyaml/_version.py"

[tool.black]
line-length = 128

[tool.isort]
profile = "black"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build
setuptools_scm
pre-commit
ruff
mypy
coverage

-r docs/requirements.txt
12 changes: 7 additions & 5 deletions src/jinjyaml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
It may be useful if you only want to render special tag nodes in the document, instead of whole YAML string as a template.
""" # noqa: E501

from ._version import __version__, __version_tuple__
from .constructor import * # noqa: F403
from .data import * # noqa: F403
from .functions import * # noqa: F403
from .representer import * # noqa: F403
__all__ = ["__version__", "version", "version_tuple", "Constructor", "Data", "extract", "Representer"]

from ._version import __version__, version, version_tuple
from .constructor import Constructor
from .data import Data
from .functions import extract
from .representer import Representer
54 changes: 0 additions & 54 deletions src/jinjyaml/_yaml_types.py

This file was deleted.

68 changes: 0 additions & 68 deletions src/jinjyaml/_yaml_types_backward.py

This file was deleted.

12 changes: 10 additions & 2 deletions src/jinjyaml/constructor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Union
from yaml.nodes import ScalarNode

from .data import Data

if TYPE_CHECKING: # pragma: no cover
from yaml import Node
from yaml.cyaml import _CLoader
from yaml.loader import _Loader

__all__ = ["Constructor"]


Expand Down Expand Up @@ -35,11 +43,11 @@ class Constructor:
- Content of the tag **MUST** be text
""" # noqa: E501

def __call__(self, loader, node):
def __call__(self, loader: Union[_Loader, _CLoader], node: Node) -> Union[Data, Any]:
if isinstance(node, ScalarNode):
source = loader.construct_scalar(node)
if not isinstance(source, str): # pragma: no cover
raise ValueError("`{}` expects `str`, but actual `{}`".format(self.__class__, type(source)))
else:
raise TypeError("`{}` does not support `{}` node".format(self.__class__, type(node)))
raise TypeError("`{}` expects `ScalarNode`, but actual `{}`".format(self.__class__, type(node)))
return Data(source)
2 changes: 2 additions & 0 deletions src/jinjyaml/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dataclasses import dataclass

__all__ = ["Data"]
Expand Down
Loading

0 comments on commit 579d82b

Please sign in to comment.