diff options
author | Peter Pentchev <roam@debian.org> | 2023-05-13 13:31:39 +0300 |
---|---|---|
committer | Peter Pentchev <roam@debian.org> | 2023-05-13 13:31:39 +0300 |
commit | d5996b34a4c565adb9f4132fba8bed3807974a3a (patch) | |
tree | 617ad739ca4a06c828380594781fb0367a26c5f1 | |
parent | 56254ec63273174464d598bd93bce92af4a0248a (diff) | |
parent | 1554f632bfc2f1ceef99f20fbbf86c8d03a733b0 (diff) |
Update upstream source from tag 'upstream/0.1.2'
Update to upstream version '0.1.2'
with Debian dir c59da571f5326722d4bba0d90d4ebd388b668a5d
31 files changed, 514 insertions, 233 deletions
diff --git a/.config/ruff-all/pyproject.toml b/.config/ruff-all/pyproject.toml deleted file mode 100644 index 3823c31..0000000 --- a/.config/ruff-all/pyproject.toml +++ /dev/null @@ -1,3 +0,0 @@ -[tool.ruff] -extend = "../ruff-base/pyproject.toml" -select = ["ALL"] diff --git a/.editorconfig b/.editorconfig index d8410fd..30071c9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause +# # https://editorconfig.org/ root = true @@ -31,6 +34,10 @@ tab_size = 8 indent_style = space indent_size = 2 +[*.yml] +indent_style = space +indent_size = 2 + [setup.cfg] indent_style = space indent_size = 4 diff --git a/LICENSES/BSD-2-Clause.txt b/LICENSES/BSD-2-Clause.txt new file mode 100644 index 0000000..5f662b3 --- /dev/null +++ b/LICENSES/BSD-2-Clause.txt @@ -0,0 +1,9 @@ +Copyright (c) <year> <owner> + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in index bc82747..3badf99 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,11 @@ -recursive-include .config *.toml +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + +recursive-include config *.toml +recursive-include docs *.md include .editorconfig -include CHANGELOG.md +recursive-include LICENSES *.txt +include mkdocs.yml recursive-include nix *.nix *.sh recursive-include requirements *.txt include tox.ini @@ -1,15 +1,20 @@ Metadata-Version: 2.1 Name: parse_stages -Version: 0.1.1 +Version: 0.1.2 Summary: Parse an expression for selecting stages and tags Author-email: Peter Pentchev <roam@ringlet.net> -Project-URL: Homepage, https://gitlab.com/ppentchev/parse-stages -Project-URL: Changes, https://gitlab.com/ppentchev/parse-stages/-/blob/main/CHANGELOG.md +Project-URL: Homepage, https://devel.ringlet.net/devel/parse-stages/ +Project-URL: Changes, https://devel.ringlet.net/devel/parse-stages/changes/ Project-URL: Issue Tracker, https://gitlab.com/ppentchev/parse-stages/-/issues Project-URL: Source Code, https://gitlab.com/ppentchev/parse-stages -Requires-Python: >=3.7 +Requires-Python: >=3.8 Description-Content-Type: text/markdown +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + # Parse a mini-language for selecting objects by tag or name This library is mostly useful for command-line parsing by other tools like @@ -111,7 +116,9 @@ Select the test environments that match the specification: ## Contact The `parse-stages` library was written by [Peter Pentchev][roam]. -It is developed in [a GitLab repository][gitlab]. +It is developed in [a GitLab repository][gitlab]. This documentation is +hosted at [Ringlet][ringlet-parse-stages]. [roam]: mailto:roam@ringlet.net "Peter Pentchev" [gitlab]: https://gitlab.com/ppentchev/parse-stages "The parse-stages GitLab repository" +[ringlet-parse-stages]: https://devel.ringlet.net/devel/parse-stages/ "The Ringlet parse-stages homepage" @@ -1,3 +1,8 @@ +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + # Parse a mini-language for selecting objects by tag or name This library is mostly useful for command-line parsing by other tools like @@ -99,7 +104,9 @@ Select the test environments that match the specification: ## Contact The `parse-stages` library was written by [Peter Pentchev][roam]. -It is developed in [a GitLab repository][gitlab]. +It is developed in [a GitLab repository][gitlab]. This documentation is +hosted at [Ringlet][ringlet-parse-stages]. [roam]: mailto:roam@ringlet.net "Peter Pentchev" [gitlab]: https://gitlab.com/ppentchev/parse-stages "The parse-stages GitLab repository" +[ringlet-parse-stages]: https://devel.ringlet.net/devel/parse-stages/ "The Ringlet parse-stages homepage" diff --git a/config/ruff-all/pyproject.toml b/config/ruff-all/pyproject.toml new file mode 100644 index 0000000..d59603f --- /dev/null +++ b/config/ruff-all/pyproject.toml @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + +[tool.ruff] +extend = "../ruff-base/pyproject.toml" +select = ["ALL"] diff --git a/.config/ruff-base/pyproject.toml b/config/ruff-base/pyproject.toml index 0a52153..6a09349 100644 --- a/.config/ruff-base/pyproject.toml +++ b/config/ruff-base/pyproject.toml @@ -1,5 +1,8 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + [tool.ruff] -target-version = "py37" +target-version = "py38" line-length = 100 select = [] ignore = [ diff --git a/config/ruff-most/pyproject.toml b/config/ruff-most/pyproject.toml new file mode 100644 index 0000000..61d02f4 --- /dev/null +++ b/config/ruff-most/pyproject.toml @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + +[tool.ruff] +extend = "../ruff-base/pyproject.toml" +# These are all the Ruff 0.0.254 linters. +select = [ + "A", + "ANN", + "ARG", + "B", + "BLE", + "C4", + "C90", + "COM", + "D", + "DJ", + "DTZ", + "E", + # "EM", + "ERA", + "EXE", + "F", + "FBT", + "G", + # "I", + "ICN", + "INP", + "ISC", + "N", + "NPY", + "PD", + "PGH", + "PIE", + "PL", + "PT", + "PTH", + "PYI", + "Q", + "RET", + "RSE", + "RUF", + "S", + "SIM", + "SLF", + "T10", + "T20", + # "TCH", + # "TID", + # "TRY", + "UP", + "W", + "YTT", +] diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..d926b81 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,44 @@ +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + +# API Reference + +## The tagged object classes + +::: parse_stages.Tagged + handler: python + +::: parse_stages.TaggedFrozen + handler: python + +## The evaluated boolean expression + +::: parse_stages.BoolExpr + handler: python + +::: parse_stages.OrExpr + handler: python + +::: parse_stages.AndExpr + handler: python + +::: parse_stages.NotExpr + handler: python + +## The object's tags and keywords + +::: parse_stages.TagExpr + handler: python + +::: parse_stages.KeywordExpr + handler: python + +## The helper functions + +::: parse_stages.parse_spec + handler: python + +::: parse_stages.parse_stage_ids + handler: python diff --git a/CHANGELOG.md b/docs/changes.md index 8588e98..3b823c4 100644 --- a/CHANGELOG.md +++ b/docs/changes.md @@ -1,3 +1,8 @@ +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + # Changelog All notable changes to the parse-stages project will be documented in this file. @@ -7,6 +12,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.2] - 2023-03-10 + +### Semi-incompatible changes + +- Drop Python 3.7 support. + +### Fixes + +- Fix the 0.1.1 release URL in the changelog file. +- Do not run the `pyupgrade` Tox environment automatically. +- Add a docstring to the unit test suite's `__init__.py` file instead of + overriding a linter check. + +### Additions + +- Start some MkDocs-based documentation. +- Add the `reuse` Tox test environment to run the REUSE tool manually. + +### Other changes + +- Rework the Ruff invocation Tox targets a bit: + - drop the `ruff-all-unchained` test environment; at this point in + Ruff's development we are bound to specific versions anyway + - move the config files to a `config/` directory, not `.config/` + - move the "normal" Ruff invocation configuration to `config/ruff-most/` + - use Ruff 0.0.254 with no code changes + - activate all of Ruff 0.0.254's liners in the "normal" invocation +- Switch to SPDX license tags. +- Specify the supported Python version in the configuration of the pylint and + black tools. +- Move the changelog file into the documentation directory. +- In the packaging metadata, point to the Ringlet homepage generated from + the newly-added documentation. + ## [0.1.1] - 2023-02-05 ### Fixes @@ -37,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - First public release. -[Unreleased]: https://gitlab.com/ppentchev/parse-stages/-/compare/release%2F0.1.0...main -[0.1.1]: https://gitlab.com/ppentchev/parse-stages/-/tags/release%2F0.1.1 +[Unreleased]: https://gitlab.com/ppentchev/parse-stages/-/compare/release%2F0.1.2...main +[0.1.2]: https://gitlab.com/ppentchev/parse-stages/-/compare/release%2F0.1.1...release%2F0.1.2 +[0.1.1]: https://gitlab.com/ppentchev/parse-stages/-/compare/release%2F0.1.0...release%2F0.1.1 [0.1.0]: https://gitlab.com/ppentchev/parse-stages/-/tags/release%2F0.1.0 diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..f34bae2 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,105 @@ +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + +# Parse a mini-language for selecting objects by tag or name + +## Overview + +The `parse-stages` Python library may be used by other tools to group +objects (e.g. [Tox] or [Nox] test environments) for step-by-step processing +(e.g. running some tests in parallel, then only running others if the first +group passes). + +The language used by the library is described in the +[_Grouping stages_](language.md#grouping-stages-for-step-by-step-execution) +section. + +[tox]: https://tox.wiki/en/latest/ "The tox automation project" +[nox]: https://nox.thea.codes/en/stable/ "The nox flexible automation tool" + +## Installation + +A program that uses the `parse-stages` library should specify it in +its list of requirements, e.g. using [PEP508][pep508] syntax: + + parse-stages >= 0.1.2, < 0.2 + +[pep508]: https://peps.python.org/pep-0508/ "PEP 508 – Dependency specification for Python Software Packages" + +## Parsing a stage specification + +The `parse_spec()` function parses a string specification into +a [BoolExpr][parse_stages.BoolExpr] object that may later be used to +select matching objects (e.g. test environments). + +``` py + e_check = parse_stages.parse_spec("@check") + e_check_quick = parse_stages.parse_spec("@check and @quick") + e_check_no_ruff = parse_stages.parse_spec("@check and not ruff") + + specs = [(spec, parse_stages.parse_spec(spec)) for spec in args.stage_specs] +``` + +## Check whether an object matches a parsed specification + +The `parse-stages` library provides two base dataclasses for objects that +may be matched against parsed expressions: +[TaggedFrozen][parse_stages.TaggedFrozen] and [Tagged][parse_stages.Tagged]. +Both classes have the same members: + +- [name][parse_stages.TaggedFrozen.name]: a string +- [tags][parse_stages.TaggedFrozen.tags]: a list of strings +- [get_keyword_haystacks()][parse_stages.TaggedFrozen.get_keyword_haystacks]: + a method that returns a list of strings, + `self.name` unless overridden + +When a `BoolExpr` object's [evaluate()][parse_stages.BoolExpr.evaluate] +method is called for a specific +`TaggedFrozen` or `Tagged` object, it checks whether the specification +matches the tags and keywords defined for this object. Tags are matched +exactly, while a keyword is considered to match if it is contained in +the checked string; e.g. `pep` would match both `pep8` and `exp_pep563`, +while `@black` would not match a `black-reformat` tag. + +The `get_keyword_haystacks()` method returns the strings to look in for +matching keywords. By default, it only returns the `name` field; +however, it may be extended, e.g. for Nox sessions it may also return +the name of the Python function that implements the session, for test +classes with methods it may return the class name and the method name, etc. + +``` py + # Obtain a list (okay, a dictionary) of test environments in some way + tox_envs = get_tox_environments() # {"ruff": {"tags": ["check", "quick"]}, ...} + + # Convert them to objects that the parsed expressions can match + all_envs = [ + parse_stages.TaggedFrozen(name, env["tags"]) + for name, env in tox_envs.items() + ] + + # Or define our own class that may hold additional information + @dataclasses.dataclass(frozen=True) + class TestEnv(parse_stages.TaggedFrozen): + """A single test environment: name, tags, etc.""" + ... + + all_envs = [TestEnv(name, env["tags"], ...) for name, env in tox_envs.items()] + + # Select the ones that match the "@check" expression + matched = [env for env in all_envs if e_check.evaluate(env)] + + # Or if we only care about the names... + quick_names = [env.name for env in all_envs if e_check_quick.evaluate(env)] +``` + +## Contact + +The `parse-stages` library was written by [Peter Pentchev][roam]. +It is developed in [a GitLab repository][gitlab]. This documentation is +hosted at [Ringlet][ringlet-parse-stages]. + +[roam]: mailto:roam@ringlet.net "Peter Pentchev" +[gitlab]: https://gitlab.com/ppentchev/parse-stages "The parse-stages GitLab repository" +[ringlet-parse-stages]: https://devel.ringlet.net/devel/parse-stages/ "The Ringlet parse-stages homepage" diff --git a/docs/language.md b/docs/language.md new file mode 100644 index 0000000..2379f16 --- /dev/null +++ b/docs/language.md @@ -0,0 +1,32 @@ +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + +# The Specification Mini-Language + +## Grouping stages for step-by-step execution + +The specification mini-language may roughly be described as: + + expr ::= and_expr ["or" and_expr...] + and_expr ::= not_expr ["and" not_expr...] + not_expr ::= ["not"] atom + atom ::= tag | keyword + tag ::= "@" characters + keyword ::= characters + characters ::= [A-Za-z0-9_-]+ + +Thus, all of the following: + +- `@check` +- `@check and @quick` +- `@tests and not examples` +- `not @tests` +- `pep8 or not @quick and @check` + +...are valid expressions, +with the "not", "and", and "or" keywords having their usual precedence +(`pep8 or not @quick and @check` is parsed as +`pep8 or ((@not quick) and @check)`, but the mini-language does not +support parentheses yet). diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..e50f78c --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + +theme: + name: material + features: + - navigation.instant + - navigation.tracking + - toc.integrate + - toc.follow + - content.code.copy + palette: + - media: "(prefers-color-scheme: light)" + scheme: default + toggle: + icon: material/weather-sunny + name: Switch to dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + toggle: + icon: material/weather-night + name: Switch to light mode +site_name: parse-stages +repo_url: https://gitlab.com/ppentchev/parse-stages +repo_name: parse-stages +site_author: ppentchev +site_url: https://devel.ringlet.net/devel/parse-stages/ +site_dir: site/docs +nav: + - 'index.md' + - 'Changelog': 'changes.md' + - 'Language reference': 'language.md' + - 'API reference': 'api.md' +markdown_extensions: + - toc: + - pymdownx.highlight: + anchor_linenums: true + - pymdownx.inlinehilite: + - pymdownx.superfences: +plugins: + - mkdocstrings: + handlers: + python: + paths: [src] + options: + heading_level: 3 + show_root_heading: true + - search +watch: + - 'src/parse_stages' diff --git a/nix/mkdocs.nix b/nix/mkdocs.nix new file mode 100644 index 0000000..b445ea3 --- /dev/null +++ b/nix/mkdocs.nix @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + +{ pkgs ? import <nixpkgs> { } +, py-ver ? 311 +}: +let + python-name = "python${toString py-ver}"; + python = builtins.getAttr python-name pkgs; + python-pkgs = python.withPackages (p: with p; + [ + mkdocs + mkdocs-material + mkdocstrings + mkdocstrings-python + ] + ); +in +pkgs.mkShell { + buildInputs = [ python-pkgs ]; + shellHook = '' + set -e + rm -rf site + mkdocs build + exit + ''; +} diff --git a/nix/python-pytest.nix b/nix/python-pytest.nix index e967074..c928ad5 100644 --- a/nix/python-pytest.nix +++ b/nix/python-pytest.nix @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + { pkgs ? import <nixpkgs> { } , py-ver ? 311 }: diff --git a/nix/reformat.sh b/nix/reformat.sh index 8fb2298..83bd84d 100755 --- a/nix/reformat.sh +++ b/nix/reformat.sh @@ -1,28 +1,7 @@ #!/bin/sh # -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause set -e diff --git a/nix/run-pytest.sh b/nix/run-pytest.sh index f110a0b..5a83ded 100755 --- a/nix/run-pytest.sh +++ b/nix/run-pytest.sh @@ -1,28 +1,7 @@ #!/bin/sh # -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause set -e diff --git a/pyproject.toml b/pyproject.toml index fd1fa6b..1eda632 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + [build-system] requires = ["setuptools >= 61", "wheel"] build-backend = "setuptools.build_meta" @@ -6,7 +9,7 @@ build-backend = "setuptools.build_meta" name = "parse_stages" description = "Parse an expression for selecting stages and tags" readme = "README.md" -requires-python = ">= 3.7" +requires-python = ">= 3.8" dynamic = ["dependencies", "version"] [[project.authors]] @@ -14,8 +17,8 @@ name = "Peter Pentchev" email = "roam@ringlet.net" [project.urls] -Homepage = "https://gitlab.com/ppentchev/parse-stages" -Changes = "https://gitlab.com/ppentchev/parse-stages/-/blob/main/CHANGELOG.md" +Homepage = "https://devel.ringlet.net/devel/parse-stages/" +Changes = "https://devel.ringlet.net/devel/parse-stages/changes/" "Issue Tracker" = "https://gitlab.com/ppentchev/parse-stages/-/issues" "Source Code" = "https://gitlab.com/ppentchev/parse-stages" @@ -32,14 +35,16 @@ dependencies = {file = "requirements/install.txt"} version = {attr = "parse_stages.defs.VERSION"} [tool.black] +target-version = ["py38", "py39", "py310", "py311"] line-length = 100 [tool.mypy] strict = true -python_version = "3.7" +python_version = "3.8" # This is the list of the Pylint 2.16.1 default plugins. [tool.pylint] +py-version = "3.8" load-plugins = [ "pylint.extensions.bad_builtin", "pylint.extensions.broad_try_clause", @@ -70,9 +75,5 @@ load-plugins = [ "pylint.extensions.while_used", ] -[tool.ruff] -extend = ".config/ruff-base/pyproject.toml" -select = ["E", "F"] - [tool.test-stages] -stages = ["ruff and not @manual", "@check", "@tests"] +stages = ["ruff and not @manual", "@check and not @manual", "@tests and not @manual"] diff --git a/requirements/install.txt b/requirements/install.txt index 1bff622..10705d8 100644 --- a/requirements/install.txt +++ b/requirements/install.txt @@ -1 +1,4 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + pyparsing >= 3, < 4 diff --git a/requirements/test.txt b/requirements/test.txt index 422bfeb..9b975a9 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1 +1,4 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + pytest >= 6, < 8 diff --git a/src/parse_stages.egg-info/PKG-INFO b/src/parse_stages.egg-info/PKG-INFO index a5806a8..0946473 100644 --- a/src/parse_stages.egg-info/PKG-INFO +++ b/src/parse_stages.egg-info/PKG-INFO @@ -1,15 +1,20 @@ Metadata-Version: 2.1 Name: parse-stages -Version: 0.1.1 +Version: 0.1.2 Summary: Parse an expression for selecting stages and tags Author-email: Peter Pentchev <roam@ringlet.net> -Project-URL: Homepage, https://gitlab.com/ppentchev/parse-stages -Project-URL: Changes, https://gitlab.com/ppentchev/parse-stages/-/blob/main/CHANGELOG.md +Project-URL: Homepage, https://devel.ringlet.net/devel/parse-stages/ +Project-URL: Changes, https://devel.ringlet.net/devel/parse-stages/changes/ Project-URL: Issue Tracker, https://gitlab.com/ppentchev/parse-stages/-/issues Project-URL: Source Code, https://gitlab.com/ppentchev/parse-stages -Requires-Python: >=3.7 +Requires-Python: >=3.8 Description-Content-Type: text/markdown +<!-- +SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +SPDX-License-Identifier: BSD-2-Clause +--> + # Parse a mini-language for selecting objects by tag or name This library is mostly useful for command-line parsing by other tools like @@ -111,7 +116,9 @@ Select the test environments that match the specification: ## Contact The `parse-stages` library was written by [Peter Pentchev][roam]. -It is developed in [a GitLab repository][gitlab]. +It is developed in [a GitLab repository][gitlab]. This documentation is +hosted at [Ringlet][ringlet-parse-stages]. [roam]: mailto:roam@ringlet.net "Peter Pentchev" [gitlab]: https://gitlab.com/ppentchev/parse-stages "The parse-stages GitLab repository" +[ringlet-parse-stages]: https://devel.ringlet.net/devel/parse-stages/ "The Ringlet parse-stages homepage" diff --git a/src/parse_stages.egg-info/SOURCES.txt b/src/parse_stages.egg-info/SOURCES.txt index fac50b8..a0f8f71 100644 --- a/src/parse_stages.egg-info/SOURCES.txt +++ b/src/parse_stages.egg-info/SOURCES.txt @@ -1,12 +1,19 @@ .editorconfig -CHANGELOG.md MANIFEST.in README.md +mkdocs.yml pyproject.toml setup.cfg tox.ini -.config/ruff-all/pyproject.toml -.config/ruff-base/pyproject.toml +LICENSES/BSD-2-Clause.txt +config/ruff-all/pyproject.toml +config/ruff-base/pyproject.toml +config/ruff-most/pyproject.toml +docs/api.md +docs/changes.md +docs/index.md +docs/language.md +nix/mkdocs.nix nix/python-pytest.nix nix/reformat.sh nix/run-pytest.sh diff --git a/src/parse_stages/__init__.py b/src/parse_stages/__init__.py index ce8e58b..8a20a65 100644 --- a/src/parse_stages/__init__.py +++ b/src/parse_stages/__init__.py @@ -1,26 +1,5 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause """Parse a mini-language for selecting objects by tag or name. This library is mostly useful for command-line parsing by other tools like diff --git a/src/parse_stages/defs.py b/src/parse_stages/defs.py index 836312c..3efe693 100644 --- a/src/parse_stages/defs.py +++ b/src/parse_stages/defs.py @@ -1,26 +1,5 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause """Common definitions for the parse-stages library.""" # Some of this library's consumers need to be able to use typedload on @@ -37,7 +16,10 @@ class TaggedFrozen: """A base class for representing a constant object that has some tags.""" name: str + """The name of the object, e.g. the name of the Tox test environment.""" + tags: List[str] + """The tags specified for this object.""" def get_keyword_haystacks(self) -> List[str]: """Get the strings to look for keywords in. @@ -52,7 +34,10 @@ class Tagged: """A base class for representing an object that has some tags.""" name: str + """The name of the object, e.g. the name of the Tox test environment.""" + tags: List[str] + """The tags specified for this object.""" def get_keyword_haystacks(self) -> List[str]: """Get the strings to look for keywords in. @@ -62,4 +47,4 @@ class Tagged: return [self.name] -VERSION = "0.1.1" +VERSION = "0.1.2" diff --git a/src/parse_stages/expr.py b/src/parse_stages/expr.py index e38b347..821daeb 100644 --- a/src/parse_stages/expr.py +++ b/src/parse_stages/expr.py @@ -1,26 +1,5 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause """The hierarchy of classes representing an expression and its components.""" from __future__ import annotations @@ -46,6 +25,7 @@ class TagExpr(BoolExpr): """A tag to be checked against obj.tags.""" tag: str + """The tag to be matched exactly against the object's list of tags.""" def evaluate(self, obj: defs.TaggedFrozen | defs.Tagged) -> bool: """Check whether the tag is present in the object's list of tags.""" @@ -57,6 +37,7 @@ class KeywordExpr(BoolExpr): """A tag to be checked against an object's name or list of tags.""" keyword: str + """The keyword to be matched as a substring of the object's keywords.""" def evaluate(self, obj: defs.TaggedFrozen | defs.Tagged) -> bool: """Check whether the tag is present in the object's list of tags.""" @@ -68,6 +49,7 @@ class NotExpr(BoolExpr): """A negated boolean expression.""" child: BoolExpr + """The expression to be negated.""" def evaluate(self, obj: defs.TaggedFrozen | defs.Tagged) -> bool: """Check whether the specified expression does not hold true.""" @@ -79,6 +61,7 @@ class AndExpr(BoolExpr): """An "atom and atom [and atom...]" subexpression.""" children: list[BoolExpr] + """The subexpressions to be combined.""" def evaluate(self, obj: defs.TaggedFrozen | defs.Tagged) -> bool: """Check whether all the specified expressions hold true.""" @@ -90,6 +73,7 @@ class OrExpr(BoolExpr): """An "subexpr or subexpr [or subexpr...]" subexpression.""" children: list[BoolExpr] + """The subexpressions to be combined.""" def evaluate(self, obj: defs.TaggedFrozen | defs.Tagged) -> bool: """Check whether any of the specified expressions hold(s) true.""" diff --git a/src/parse_stages/p_pyp.py b/src/parse_stages/p_pyp.py index 4a22f78..c8d6c45 100644 --- a/src/parse_stages/p_pyp.py +++ b/src/parse_stages/p_pyp.py @@ -1,27 +1,6 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -"""Parse an expression using the pyparsing library.""" +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause +"""Parse an expression using the `pyparsing` library.""" # Let's make sure that the parsed tokens are exactly as we expect them to be # flake8: noqa: S101 @@ -109,7 +88,7 @@ _p_complete = _p_spec.leave_whitespace() def parse_spec(spec: str) -> expr.BoolExpr: - """Parse an expression using the pyparsing library.""" + """Parse an expression using the `pyparsing` library.""" res = _p_complete.parse_string(spec, parse_all=True).as_list() assert len(res) == 1 and isinstance(res[0], expr.BoolExpr), repr(res) return res[0] @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause + [tox] envlist = ruff @@ -21,27 +24,18 @@ skip_install = True tags = check deps = - ruff >= 0.0.241, < 0.1 + ruff >= 0.0.254, < 0.1 commands = - ruff check -- {[defs]pyfiles} + ruff check --config config/ruff-most/pyproject.toml -- {[defs]pyfiles} [testenv:ruff-all] skip_install = True tags = check deps = - ruff == 0.0.241 + ruff == 0.0.254 commands = - ruff check --config .config/ruff-all/pyproject.toml -- {[defs]pyfiles} - -[testenv:ruff-all-unchained] -skip_install = True -tags = - manual -deps = - ruff >= 0.0.241 -commands = - ruff check --config .config/ruff-all/pyproject.toml -- {[defs]pyfiles} + ruff check --config config/ruff-all/pyproject.toml -- {[defs]pyfiles} [testenv:black] skip_install = True @@ -56,6 +50,7 @@ commands = skip_install = True tags = format + manual deps = black >= 23, < 24 commands = @@ -132,12 +127,13 @@ commands = skip_install = True tags = check + manual deps = pyupgrade >= 3, < 4 allowlist_externals = sh commands = - sh -c 'pyupgrade --py37-plus src/parse_stages/*.py unit_tests/*.py' + sh -c 'pyupgrade --py38-plus src/parse_stages/*.py unit_tests/*.py' [testenv:unit-tests] tags = @@ -147,3 +143,26 @@ deps = -r requirements/test.txt commands = pytest {posargs} unit_tests + +[testenv:docs] +skip_install = True +tags = + docs + manual +deps = + mkdocs >= 1.4.2, < 2 + mkdocs-material >= 9.1.2, < 10 + mkdocstrings >= 0.20, < 0.21 + mkdocstrings-python >= 0.8.3, < 0.9 +commands = + mkdocs build + +[testenv:reuse] +skip_install = True +tags = + check + manual +deps = + reuse >= 1, < 2 +commands = + reuse lint diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index 6e03199..d3a9c44 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -1 +1,3 @@ -# noqa: D104 +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause +"""Unit test suite for the parse-stages library.""" diff --git a/unit_tests/test_eval.py b/unit_tests/test_eval.py index 7e2d24c..255c6d1 100644 --- a/unit_tests/test_eval.py +++ b/unit_tests/test_eval.py @@ -1,26 +1,5 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause """Test the evaluation of some simple expressions.""" # This is a test suite, right? diff --git a/unit_tests/test_parse.py b/unit_tests/test_parse.py index c0a7b7a..86fe5d4 100644 --- a/unit_tests/test_parse.py +++ b/unit_tests/test_parse.py @@ -1,26 +1,5 @@ -# Copyright (c) Peter Pentchev <roam@ringlet.net> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> +# SPDX-License-Identifier: BSD-2-Clause """Test some basic parsing functionality.""" # This is a test suite, right? |