From 54bd28795bab7e9b258c34ecda8b74f5490db49e Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 31 Jul 2022 19:35:09 -0400 Subject: [PATCH] Package bitmask using hatch --- .gitignore | 3 ++ README.md | 45 ++++++++++++++++ bitmask/__about__.py | 4 ++ bitmask/__init__.py | 4 ++ bitmask.py => bitmask/bitmask.py | 25 +-------- test_bitmask.py => bitmask/test_bitmask.py | 3 ++ pyproject.toml | 63 ++++++++++++++++++++++ 7 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 README.md create mode 100644 bitmask/__about__.py create mode 100644 bitmask/__init__.py rename bitmask.py => bitmask/bitmask.py (83%) rename test_bitmask.py => bitmask/test_bitmask.py (99%) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index c18dd8d..942a634 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ __pycache__/ +dist +tags +.coverage diff --git a/README.md b/README.md new file mode 100644 index 0000000..6646da7 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Bitmask + +Implementation of a Bitmask class in Python, allowing easy manipulation of EnumFlag values. + +## Features + +* create bitmasks from any EnumFlag type + +* simple "flag in Bitmask" syntax + +* bitwise operations, e.g. AND (&), OR (|), XOR (^) + +* assignment with operators (+=, -=, &=, etc.) + +* convenience functions like Bitmask.add(), or Bitmask.discard() + +For development and tinkering: + +* included unit tests + +* ample documentation and examples in code + +## Example usage + +```python +from bitmask import Bitmask +from enum import IntFlag + +class Desc(IntFlag): + SMALL = 1 + ROUND = 1 << 1 + FUNKY = 1 << 2 + LARGE = 1 << 3 + +marble = Bitmask(Desc, Desc.SMALL, Desc.ROUND, Desc.FUNKY) + +Desc.SMALL in marble +>>> True + +Desc.LARGE in marble +>>> False + +Bitmask(Desc, Desc.SMALL, Desc.ROUND) in marble +>>> True +``` diff --git a/bitmask/__about__.py b/bitmask/__about__.py new file mode 100644 index 0000000..42fdfde --- /dev/null +++ b/bitmask/__about__.py @@ -0,0 +1,4 @@ +# Copyright 2022 dogeystamp +# See LICENSE file for more details. + +__version__ = "0.0.1" diff --git a/bitmask/__init__.py b/bitmask/__init__.py new file mode 100644 index 0000000..318c42c --- /dev/null +++ b/bitmask/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 dogeystamp +# See LICENSE file for more details. + +from .bitmask import Bitmask diff --git a/bitmask.py b/bitmask/bitmask.py similarity index 83% rename from bitmask.py rename to bitmask/bitmask.py index 8cd621b..7173d99 100644 --- a/bitmask.py +++ b/bitmask/bitmask.py @@ -1,26 +1,5 @@ -# Copyright 2022 dogeystamp -# -# 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. +# Copyright 2022 dogeystamp +# See LICENSE file for more details. """Utilities for manipulating bitmasks.""" diff --git a/test_bitmask.py b/bitmask/test_bitmask.py similarity index 99% rename from test_bitmask.py rename to bitmask/test_bitmask.py index d28ade8..0cdc8b5 100644 --- a/test_bitmask.py +++ b/bitmask/test_bitmask.py @@ -1,3 +1,6 @@ +# Copyright 2022 dogeystamp +# See LICENSE file for more details. + from bitmask import Bitmask from enum import IntFlag import unittest diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d243d0d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,63 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "bitmask" +description = 'Featureful bitmask implementation.' +readme = "README.md" +requires-python = ">=3.7" +license = "MIT" +keywords = [] +authors = [ + { name = "dogeystamp", email = "dogeystamp@disroot.org" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [] +dynamic = ["version"] + +[project.urls] +Documentation = "https://github.com/dogeystamp/bitmask#readme" +Issues = "https://github.com/dogeystamp/bitmask/issues" +Source = "https://github.com/dogeystamp/bitmask" + +[tool.hatch.version] +path = "bitmask/__about__.py" + +[tool.hatch.build.targets.sdist] +[tool.hatch.build.targets.wheel] + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "pytest-cov", +] +[tool.hatch.envs.default.scripts] +cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=bitmask --cov=tests" +no-cov = "cov --no-cov" + +[[tool.hatch.envs.test.matrix]] +python = ["37", "38", "39", "310"] + +[tool.coverage.run] +branch = true +parallel = true +omit = [ + "bitmask/__about__.py", +] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +]