diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index 7f71ca7..8c1389f 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 @@ -29,9 +29,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -r dev_requirements.txt - python -m pip install -r requirements.txt - python -m pip install . + python -m pip install .[dev] - name: Check with ruff run: ruff check . - name: Check types diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..f421134 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include grammar.lark diff --git a/README.md b/README.md index ec5b73a..e79be01 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,6 @@ By default, the computation assumes that draws are made without replacement. Thi Let's look at some examples. -

- constraints using AND -

- Suppose we want to draw _without replacement_ from an urn containing coloured marbles. We want to see the probability that we see _at least_ 2 red and _at most_ 5 blue: ``` urn> probability draw from red = 5, blue = 7, green = 3 where red >= 2 and blue <= 5; @@ -121,10 +117,6 @@ urn> probability draw 2..13 with replacement ``` Finally, we can use `OR` to specify any number of alternative constraints on our draw. -

- constraints using OR -

- ``` urn> probability draw 1..10 from red=5, blue=7, green=3 ... where red >= 2 and blue <= 3 diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index 71cc539..0000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest -ruff diff --git a/urn/grammar.lark b/grammar.lark similarity index 100% rename from urn/grammar.lark rename to grammar.lark diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8c96d73 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "urn-calculator" +version = "0.0.1" +description = "Multivariate hypergeometric command line calculator." +readme = "README.md" +authors = [{ name = "Alex Riley" }] +license = { file = "LICENSE" } +classifiers = [ + "Development Status :: 3 - Alpha", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Visualization", + "Topic :: Utilities", + "Typing :: Typed", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +keywords = ["calculator", "probability", "count", "draw", "random", "sample", "hypergeometric"] +dependencies = [ + "lark >= 1.1.5", + "sympy >= 1.12", + "tabulate >= 0.9.0", + "uniplot >= 0.10.0", +] +requires-python = ">=3.10" + +[project.optional-dependencies] +dev = ["pytest", "ruff"] + +[project.urls] +Homepage = "https://github.com/ajcr/urn" + +[project.scripts] +urn = "urn.cli:main" + +[tool.pytest.ini_options] +pythonpath = [ + "." +] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a93e4b6..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -lark==1.1.5 -sympy==1.12 -tabulate==0.9.0 -uniplot==0.10.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index aba4d91..0000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -from setuptools import setup, find_packages - -from urn import __version__ - -long_description = """ -... -""" - -setup( - name="urn", - version=__version__, - description="Quantity probability calculator", - long_description=long_description, - classifiers=[ - "Development Status :: 3 - Alpha", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Scientific/Engineering :: Visualization", - "Topic :: Utilities", - "Typing :: Typed", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - ], - keywords="calculator probability count draw odds hypergeometric", - project_urls={ - "Source": "https://github.com/ajcr/urn/", - "Tracker": "https://github.com/ajcr/urn/issues", - }, - python_requires=">=3.10.0", - author="Alex Riley", - license="MIT", - packages=find_packages(include=["urn", "urn.*"]), - tests_require=["pytest"], - zip_safe=False, - entry_points={"console_scripts": ["urn=urn.cli:main"]}, -) diff --git a/urn/__init__.py b/src/urn/__init__.py similarity index 100% rename from urn/__init__.py rename to src/urn/__init__.py diff --git a/urn/cli.py b/src/urn/cli.py similarity index 90% rename from urn/cli.py rename to src/urn/cli.py index b1f658b..cbc09e4 100644 --- a/urn/cli.py +++ b/src/urn/cli.py @@ -5,7 +5,7 @@ from urn import __version__ -DESCRIPTION = "Draw odds calculator." +DESCRIPTION = "Multivariate hypergeometric calculator." def parse_args() -> argparse.Namespace: @@ -30,7 +30,7 @@ def main() -> None: from urn.shell import run_shell from urn.evaluation import process_query - command_parser = lark.Lark.open("grammar.lark", rel_to=__file__) + command_parser = lark.Lark.open("grammar.lark", rel_to=__package__) if args.command or args.filename: diff --git a/urn/computation.py b/src/urn/computation.py similarity index 100% rename from urn/computation.py rename to src/urn/computation.py diff --git a/urn/constants.py b/src/urn/constants.py similarity index 100% rename from urn/constants.py rename to src/urn/constants.py diff --git a/urn/constraint.py b/src/urn/constraint.py similarity index 100% rename from urn/constraint.py rename to src/urn/constraint.py diff --git a/urn/evaluation.py b/src/urn/evaluation.py similarity index 100% rename from urn/evaluation.py rename to src/urn/evaluation.py diff --git a/urn/output.py b/src/urn/output.py similarity index 100% rename from urn/output.py rename to src/urn/output.py diff --git a/urn/parsing.py b/src/urn/parsing.py similarity index 100% rename from urn/parsing.py rename to src/urn/parsing.py diff --git a/urn/shell.py b/src/urn/shell.py similarity index 100% rename from urn/shell.py rename to src/urn/shell.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 4859768..82b7607 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -8,9 +8,8 @@ @pytest.fixture(scope="session") -def parser(request): - rel_to = request.config.rootdir.join("urn").join("urn") - return lark.Lark.open("grammar.lark", rel_to=str(rel_to)) +def parser(): + return lark.Lark.open("grammar.lark") @pytest.mark.parametrize(