Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example pyproject and package. #11

Merged
merged 19 commits into from
Aug 22, 2024

Conversation

MicahGale
Copy link
Contributor

@MicahGale MicahGale commented Jul 17, 2024

Added an example package with a pyproject.toml file.

This a variety of levels of concepts that may or not be appropriate for this scope.

  1. a pyproject.toml file that covers:
    1. base metadata
    2. dependencies
    3. setuptools/build metadata: python -m build and pip install . should work on it.
    4. Configuring third-party plugins (pytest).
    5. Specifying optional dependencies
  2. Packaging covering:
    1. having an __init__.py
    2. Importing a class to be top-level from a submodule
    3. Making the module executable via __main__.py
    4. Internal package imports
    5. Testing a package
  3. OOP:
    1. Using _private
    2. Making @property getters
    3. Doc strings with sphinx directives
  4. Testing:
    1. Structure and imports
    2. pytest.fixture
    3. Using pytest.approx for float comparisons
  5. Amusing myself.

Fixes #3.

@MicahGale MicahGale added the enhancement New feature or request label Jul 17, 2024
@MicahGale MicahGale requested a review from gonuke July 17, 2024 15:21
@MicahGale MicahGale self-assigned this Jul 17, 2024
@MicahGale MicahGale linked an issue Jul 17, 2024 that may be closed by this pull request
@MicahGale MicahGale marked this pull request as ready for review July 17, 2024 15:37
@gonuke
Copy link
Member

gonuke commented Jul 17, 2024

Can we implement this on the files in #1 (and thus merge that ASAP if ready) including moving those files as appropriate?

@MicahGale
Copy link
Contributor Author

MicahGale commented Jul 17, 2024

Yes, I was thinking this should be based on #1, but I didn't want to deal with a second remote. So I'll make this a draft again until that is merged.

Can we implement this on the files in #1 (and thus merge that ASAP if ready) including moving those files as appropriate?

By this do you mean moving the current files in #1 into the package or not? I was thinking of including some top level files that show good practices for scripting, and then this being an independent-ish folder and showing packaging.

@MicahGale MicahGale marked this pull request as draft July 17, 2024 15:48
@gonuke
Copy link
Member

gonuke commented Jul 17, 2024

Can we implement this on the files in #1 (and thus merge that ASAP if ready) including moving those files as appropriate?

By this do you mean moving the current files in #1 into the package or not? I was thinking of including some top level files that show good practices for scripting, and then this being an independent-ish folder and showing packaging.

I guess I don't need to get too complicated. It's meant for people starting new projects from scratch without a lot of prior experience. Happy to debate what that minimal case looks like, so I'll see how it all fits. Don't want you to go too far down a rabbit hole though.

@MicahGale MicahGale marked this pull request as ready for review July 19, 2024 20:17
@MicahGale
Copy link
Contributor Author

Add example of pyproject scripts/entry points?

@MicahGale
Copy link
Contributor Author

Todo: move do_task.py and test_do_task.py into acme_corp. Harmonize doc strings.

@MicahGale MicahGale marked this pull request as draft July 19, 2024 21:40
-issue is that pip isn't updating setuptools
-work around: just install wheel.
@MicahGale MicahGale marked this pull request as ready for review August 16, 2024 18:38
Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of typos and reminder about docstring format.

acme_corp/__main__.py Outdated Show resolved Hide resolved
@@ -4,22 +4,20 @@

logger = logging.getLogger(__name__)

# using Sphinx docstrings style: <https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we decide to switch to numpy docstring style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we decided to make that a separate PR #12.

acme_corp/piano.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest isn't happy without it. I can't remember if python has removed the need for this file or not. There might be a workaround, but I'm thinking: "if it ain't broke..."

========================================================================= test session starts ==========================================================================
platform linux -- Python 3.10.13, pytest-7.4.0, pluggy-1.3.0
rootdir: /home/mgale/dev/py-template
plugins: anyio-4.0.0, profiling-1.7.0
collected 0 items / 2 errors

================================================================================ ERRORS ================================================================================
________________________________________________________________ ERROR collecting tests/test_do_task.py ________________________________________________________________
ImportError while importing test module '/home/mgale/dev/py-template/tests/test_do_task.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../mambaforge/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_do_task.py:1: in <module>
    import acme_corp.do_task as do_task
E   ModuleNotFoundError: No module named 'acme_corp'
_________________________________________________________________ ERROR collecting tests/test_piano.py _________________________________________________________________
ImportError while importing test module '/home/mgale/dev/py-template/tests/test_piano.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../mambaforge/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_piano.py:1: in <module>
    import acme_corp
E   ModuleNotFoundError: No module named 'acme_corp'
======================================================================= short test summary info ========================================================================
ERROR tests/test_do_task.py
ERROR tests/test_piano.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================== 2 errors in 0.11s ===========================================================================

MicahGale and others added 2 commits August 21, 2024 08:35
Co-authored-by: Paul Wilson <[email protected]>
Co-authored-by: Paul Wilson <[email protected]>
@MicahGale MicahGale requested a review from gonuke August 21, 2024 19:33
Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MicahGale

@gonuke gonuke merged commit 861800a into main Aug 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pyproject.toml and arrange files per standards
2 participants