From 07611aee3e6f3309bc386a5b22a158e29cf2ace1 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:08:34 -0500 Subject: [PATCH 01/18] Created ACME packing slip for order #1. --- pyproject.toml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8fab1ef --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[project] +name = "acme_corp" +description = "A package, or box, created by the Acme Corporation for all of your Road Runner hunting needs." + +readme = "README.md" +requires-python = ">=3.9" +maintainers = [{name = "G. C. Runner", email = "runner@californian.us"}] +authors = [{name = "G. C. Runner", email = "runner@californian.us"}] + +keywords = ["Piano", "Anvil", "Instant Tunnel"] + +dependencies = ["pyyaml"] + +[project.optional-dependencies] +test =["pytest"] + +[project.urls] +Homepage = "https://github.com/cnerg/py-template" + +[build-system] +requires = ["setuptools>=64.0.0"] +build-backend = "setuptoos.build_meta" + +[tools.pytest.ini_options] +minversion = "6.0" +junit_logging = "all" From b5c7341d569462b96abc818e193d0f88b37050ef Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:09:42 -0500 Subject: [PATCH 02/18] Built box for order #1. --- acme_corp/__init__.py | 0 tests/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 acme_corp/__init__.py create mode 100644 tests/__init__.py diff --git a/acme_corp/__init__.py b/acme_corp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 00f9f6719fce028a87cdc8b39484dd4232acb1df Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:17:09 -0500 Subject: [PATCH 03/18] Built piano for order 1 --- acme_corp/__init__.py | 2 ++ acme_corp/piano.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 acme_corp/piano.py diff --git a/acme_corp/__init__.py b/acme_corp/__init__.py index e69de29..6758cf7 100644 --- a/acme_corp/__init__.py +++ b/acme_corp/__init__.py @@ -0,0 +1,2 @@ +# make piano a top-level class +from .piano import Piano diff --git a/acme_corp/piano.py b/acme_corp/piano.py new file mode 100644 index 0000000..c6a2e60 --- /dev/null +++ b/acme_corp/piano.py @@ -0,0 +1,22 @@ +class Piano: + """ + A grand piano proudly built by ACME corporation. + + Weighing half a ton be careful when hoisting this precariously over + sidewalks. + + .. warning:: + Always use proper rigging techniques when hoisting this above + above any paths that may be occupied any Road Runners. + """ + + def __init__(self): + self._weight = 1_000 + # start on ground level + self._height = 0 + + def lift(self): + self._height = 3 # [m] + + def drop(self): + pass From c3af5d12ea79896ff83e6e5b301f51f3e27cdab8 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:20:35 -0500 Subject: [PATCH 04/18] Made package executable. --- acme_corp/__main__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 acme_corp/__main__.py diff --git a/acme_corp/__main__.py b/acme_corp/__main__.py new file mode 100644 index 0000000..8ae9e5d --- /dev/null +++ b/acme_corp/__main__.py @@ -0,0 +1,19 @@ +from . import Piano + +""" +This is a special file that makes this package executable. + +It will only be ran when this package is ran from the command line, i.e., + +``python -m acme_corp`` +""" + + +def set_trap(): + piano = Piano() + piano.lift() + return piano + + +if __name__ == "__main__": + trap = set_trap() From fac136fe1005a6bf40cdb9b6060f2e51a4f3f4e5 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:34:56 -0500 Subject: [PATCH 05/18] Exposed piano properties to fulfill order 1 spec. --- acme_corp/piano.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/acme_corp/piano.py b/acme_corp/piano.py index c6a2e60..27efab6 100644 --- a/acme_corp/piano.py +++ b/acme_corp/piano.py @@ -20,3 +20,23 @@ def lift(self): def drop(self): pass + + @property + def weight(self): + """ + The current weight of the piano. + + :returns: the current weight. + :rtype: float + """ + return self._weight + + @property + def height(self): + """ + The current height of the piano. + + :returns: the current height. + :rtype: float + """ + return self._height From 2965da0612fb488f34ce544103ef25ff930865d5 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:35:19 -0500 Subject: [PATCH 06/18] Tested piano against spec for order 1 --- tests/test_piano.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test_piano.py diff --git a/tests/test_piano.py b/tests/test_piano.py new file mode 100644 index 0000000..b21437c --- /dev/null +++ b/tests/test_piano.py @@ -0,0 +1,22 @@ +import acme_corp + +import pytest + + +@pytest.fixture +def blank_piano(): + return acme_corp.Piano() + + +def test_piano_init(blank_piano): + assert blank_piano.weight == pytest.approx(1_000.0) + assert blank_paino.height == pytest.approx(0.0) + + +def test_lifting_piano(blank_piano): + piano.lift() + assert blank_piano.height == pytest.approx(3) + + +def test_dropping_piano(blank_piano): + pass From ca1b00ff6fd3d1e0e0392c587ef577499d799f94 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Wed, 17 Jul 2024 10:36:23 -0500 Subject: [PATCH 07/18] I can't spell. --- tests/test_piano.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_piano.py b/tests/test_piano.py index b21437c..9965782 100644 --- a/tests/test_piano.py +++ b/tests/test_piano.py @@ -10,11 +10,11 @@ def blank_piano(): def test_piano_init(blank_piano): assert blank_piano.weight == pytest.approx(1_000.0) - assert blank_paino.height == pytest.approx(0.0) + assert blank_piano.height == pytest.approx(0.0) def test_lifting_piano(blank_piano): - piano.lift() + blank_piano.lift() assert blank_piano.height == pytest.approx(3) From faafe99b1c4316ba4d84b94e7939b9e18463fd65 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:11:04 -0500 Subject: [PATCH 08/18] Removed top level scripts. --- do_task.py => acme_corp/do_task.py | 0 test_do_task.py => tests/test_do_task.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename do_task.py => acme_corp/do_task.py (100%) rename test_do_task.py => tests/test_do_task.py (100%) diff --git a/do_task.py b/acme_corp/do_task.py similarity index 100% rename from do_task.py rename to acme_corp/do_task.py diff --git a/test_do_task.py b/tests/test_do_task.py similarity index 100% rename from test_do_task.py rename to tests/test_do_task.py From 6b7e05e276844e5808b419f313b8190255ce1977 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:13:19 -0500 Subject: [PATCH 09/18] Updated do_task tests for move. --- tests/test_do_task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_do_task.py b/tests/test_do_task.py index 74c0348..b73727e 100644 --- a/tests/test_do_task.py +++ b/tests/test_do_task.py @@ -1,4 +1,4 @@ -import do_task +import acme_corp.do_task as do_task def test_perform_action(): args = 'foo' @@ -10,4 +10,4 @@ def test_perform_action(): assert exp == obs - \ No newline at end of file + From 65667a091346072127249ff46ec35d05ac74f185 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:24:01 -0500 Subject: [PATCH 10/18] Added an entry point script. --- pyproject.toml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8fab1ef..58f53aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,9 @@ +# reference: [project] name = "acme_corp" description = "A package, or box, created by the Acme Corporation for all of your Road Runner hunting needs." +# use semantic versioning: +version = "0.0.1" readme = "README.md" requires-python = ">=3.9" @@ -9,17 +12,23 @@ authors = [{name = "G. C. Runner", email = "runner@californian.us"}] keywords = ["Piano", "Anvil", "Instant Tunnel"] +# these will be install with `pip install .` dependencies = ["pyyaml"] +# these will only be installed with `pip install .[test]` [project.optional-dependencies] test =["pytest"] +[project.scripts] +do_thing = "acme_corp:do_task.do_task" + +# these show up on the left bar on pypi.org [project.urls] Homepage = "https://github.com/cnerg/py-template" [build-system] requires = ["setuptools>=64.0.0"] -build-backend = "setuptoos.build_meta" +build-backend = "setuptools.build_meta" [tools.pytest.ini_options] minversion = "6.0" From dc4e4d0f16c5064b9174d5d9cf172c033f61fc35 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:24:27 -0500 Subject: [PATCH 11/18] Also demonstrated building and installing as part of test suite. --- .github/workflows/ci.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edc70e4..48d0c25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,10 +22,21 @@ jobs: shell: bash run: | pip3 install numpy \ - pytest + pytest \ + build - name: Test shell: bash run: | pytest -v . - \ No newline at end of file + + - name: build + run: python -m build . + + - name: install + run: | + pip install . + do_thing -h + + + From 4555e40c90013dba2d3896635b8b3c4edff2f965 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:28:36 -0500 Subject: [PATCH 12/18] Switched doc strings to sphinx style. --- acme_corp/do_task.py | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/acme_corp/do_task.py b/acme_corp/do_task.py index e572987..5952f64 100644 --- a/acme_corp/do_task.py +++ b/acme_corp/do_task.py @@ -4,6 +4,7 @@ logger = logging.getLogger(__name__) +# using Sphinx docstrings style: def perform_action(args, input_data): """Perform some action @@ -11,15 +12,12 @@ def perform_action(args, input_data): Following the principle of separation of concerns, this method only performs the action, but does not have any input or output. - inputs - ------ - args : argparse object with many possible members based on argparse configuration - input_data : dictionary of input data read from YAML file - - outputs - -------- - string that describes the input quantities - + :param args: argparse object with many possible members based on argparse configuration + :type args: argparse.ArgumentParser + :param input_data: dictionary of input data read from YAML file + :type input_data: dict + :returns: string that describes the input quantities + :rtype: str """ return f"Some results based on args:\n{args}\n and input_data:\n{input_data}\n" @@ -31,16 +29,12 @@ def report_results(args, input_data, results): Following the principle of separation of concerns, this method only performs output and does not do any actions. - inputs - ------ - args : argparse object with many possible members based on argparse configuration - input_data : dictionary of input data read from YAML file - results : the results of the action - - outputs - -------- - None + :param args: argparse object with many possible members based on argparse configuration + :type args: argparse.ArgumentParser + :param input_data: dictionary of input data read from YAML file + :type input_data: dict + :returns: None """ logger.info( @@ -56,13 +50,8 @@ def task_args(): `filename` : required positional argument `verbose` : optional keyword argument - inputs - ------- - None - - outputs - -------- - argparse object with various members depending on configuration + :returns: argparse object with various members depending on configuration + :rtype: argparse.ArgumentParser """ parser = argparse.ArgumentParser( @@ -86,7 +75,10 @@ def read_input(input_filename): inputs ------- - input_filename : a string with a filename/path accessible from the current location + :param input_filename: a string with a filename/path accessible from the current location + :type input_filename: str + :returns: the data from the YAML file. + :rtype: dict """ with open(input_filename, "r") as yaml_file: From ec8a70cc4199d4ab5d540b53976b23246ec9cfac Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:30:01 -0500 Subject: [PATCH 13/18] debugging install failure. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48d0c25..218effb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: run: python -m build . - name: install + shell: bash run: | pip install . do_thing -h From dcf8c72133124417ed2fe5ab8e151ab08b8313f9 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:32:23 -0500 Subject: [PATCH 14/18] Fixed install -issue is that pip isn't updating setuptools -work around: just install wheel. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 218effb..2dad602 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: - name: install shell: bash run: | - pip install . + pip install build/*.whl do_thing -h From f4f7553048d32143e347f73927695b75687fb7ce Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:34:10 -0500 Subject: [PATCH 15/18] Forgot that files don't persist. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dad602..d63e523 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: - name: install shell: bash run: | + python -m build . pip install build/*.whl do_thing -h From 844a084cd4eed5cbd776e46f5eb1bece6fd8dc96 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Fri, 16 Aug 2024 13:36:11 -0500 Subject: [PATCH 16/18] It's dist not build. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d63e523..6a0a07a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,8 +36,7 @@ jobs: - name: install shell: bash run: | - python -m build . - pip install build/*.whl + pip install dist/*.whl do_thing -h From 9c5520edbd5b352d705de54ad0daa02d5b537d57 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 21 Aug 2024 08:35:36 -0500 Subject: [PATCH 17/18] typo corrections. Co-authored-by: Paul Wilson --- acme_corp/piano.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acme_corp/piano.py b/acme_corp/piano.py index 27efab6..1a86d3b 100644 --- a/acme_corp/piano.py +++ b/acme_corp/piano.py @@ -7,7 +7,7 @@ class Piano: .. warning:: Always use proper rigging techniques when hoisting this above - above any paths that may be occupied any Road Runners. + above any paths that may be occupied by any Road Runners. """ def __init__(self): From 9162956138e061678a43aae45f80fbeeb0b95cc4 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 21 Aug 2024 09:25:54 -0500 Subject: [PATCH 18/18] Verbs are hard. Co-authored-by: Paul Wilson --- acme_corp/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acme_corp/__main__.py b/acme_corp/__main__.py index 8ae9e5d..de2e579 100644 --- a/acme_corp/__main__.py +++ b/acme_corp/__main__.py @@ -3,7 +3,7 @@ """ This is a special file that makes this package executable. -It will only be ran when this package is ran from the command line, i.e., +It will only be run when this package is run from the command line, i.e., ``python -m acme_corp`` """