Skip to content

add setuptools files for example package mentioned in Issue 248#659

Open
sosey wants to merge 2 commits into
pyOpenSci:mainfrom
sosey:issue248
Open

add setuptools files for example package mentioned in Issue 248#659
sosey wants to merge 2 commits into
pyOpenSci:mainfrom
sosey:issue248

Conversation

@sosey
Copy link
Copy Markdown
Contributor

@sosey sosey commented May 18, 2026

This adds example package files for setuptools, as mentioned in #248.
The examplePy package builds and tests pass with pytest.

Copy link
Copy Markdown
Collaborator

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @sosey for the contribution.

Tagging Leah for a final review 😄

@willingc willingc requested a review from lwasser May 20, 2026 18:41
@lwasser lwasser moved this to pyconus-2026 in pyOpenSci sprints 2023-2026 May 22, 2026
@lwasser
Copy link
Copy Markdown
Member

lwasser commented May 28, 2026

This looks great @sosey i'm going to see if @ucodery has time to review only because he started the package examples but if not I will review soon! Good to see you again at our sprints! i'm sorry we didn't' get to chat during the day.

@lwasser lwasser requested a review from ucodery May 28, 2026 17:21
Copy link
Copy Markdown
Contributor

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

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

looks good! with some minor comments and questions. i'm not sure of the context for this example or what the surrounding info is, so if my questions are covered by other material elsewhere already, feel free to ignore!


def calc_annual_mean(df: pandas.DataFrame):
"""Function to calculate the mean temperature for each year and the final mean"""
# TODO: make this a bit more robust so we can write integration test examples??
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# TODO: make this a bit more robust so we can write integration test examples??

do we need this todo?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hyphen in filename, wouldn't import, looks like a duplicate of temporal.py? can this be removed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I did this for some other example code and the hyphen was intentional. In sphinx we can use diff-file blocks to show, well diffs of how to modify code to fit best practice, but that involves having both files present in the repo. Also, we want these example files linted and tested to make sure they are high-quality, however the -raw files are often intentionally bad style.

Not sure if that is that is what is going on here, as I don't see any documentation references to this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, OK. Didn't know that, thanks for the context. I didn't diff them but they look the same? Maybe a leftover from another example or something.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tried to capture the purpose of examples/ in https://github.com/pyOpenSci/python-package-guide/blob/main/CONTRIBUTING.md#annex, although it looks like I failed to mention anything about diffing...


def calc_annual_mean(df: pandas.DataFrame):
"""Function to calculate the mean temperature for each year and the final mean"""
# TODO: make this a bit more robust so we can write integration test examples??
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# TODO: make this a bit more robust so we can write integration test examples??

similarly, do we need this todo?

Comment on lines +3 to +60
import math

from examplePy import temperature


def test_fahrenheit_to_celsius_positive():
"""Test F to C calculation for positive values"""
value = 95
expected_result = 35
result = temperature.fahrenheit_to_celsius(value)

assert result == expected_result


def test_fahrenheit_to_celsius_negative():
"""Test F to C calculation for negative values"""
value = -13
expected_result = -25
result = temperature.fahrenheit_to_celsius(value)

assert result == expected_result


def test_fahrenheit_to_celsius_zero():
"""Test F to C calculation for zero"""
value = 0
expected_result = -17.7778
result = temperature.fahrenheit_to_celsius(value)

# Test that the result is close to the expected value, within tolerances
assert math.isclose(result, expected_result, abs_tol=0.0001)


def test_celsius_to_fahrenheit_positive():
"""Test C to F calculation for positive values"""
value = 100
expected_result = 212
result = temperature.celsius_to_fahrenheit(value)

assert result == expected_result


def test_celsius_to_fahrenheit_negative():
"""Test C to F calculation for negative values"""
value = -20
expected_result = -4
result = temperature.celsius_to_fahrenheit(value)

assert result == expected_result


def test_celsius_to_fahrenheit_zero():
"""Test C to F calculation for zero"""
value = 0
expected_result = 32
result = temperature.celsius_to_fahrenheit(value)

assert result == expected_result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
import math
from examplePy import temperature
def test_fahrenheit_to_celsius_positive():
"""Test F to C calculation for positive values"""
value = 95
expected_result = 35
result = temperature.fahrenheit_to_celsius(value)
assert result == expected_result
def test_fahrenheit_to_celsius_negative():
"""Test F to C calculation for negative values"""
value = -13
expected_result = -25
result = temperature.fahrenheit_to_celsius(value)
assert result == expected_result
def test_fahrenheit_to_celsius_zero():
"""Test F to C calculation for zero"""
value = 0
expected_result = -17.7778
result = temperature.fahrenheit_to_celsius(value)
# Test that the result is close to the expected value, within tolerances
assert math.isclose(result, expected_result, abs_tol=0.0001)
def test_celsius_to_fahrenheit_positive():
"""Test C to F calculation for positive values"""
value = 100
expected_result = 212
result = temperature.celsius_to_fahrenheit(value)
assert result == expected_result
def test_celsius_to_fahrenheit_negative():
"""Test C to F calculation for negative values"""
value = -20
expected_result = -4
result = temperature.celsius_to_fahrenheit(value)
assert result == expected_result
def test_celsius_to_fahrenheit_zero():
"""Test C to F calculation for zero"""
value = 0
expected_result = 32
result = temperature.celsius_to_fahrenheit(value)
assert result == expected_result
import math
import pytest
from examplePy import temperature
@pytest.mark.parametrize(
"value,expected",
[
pytest.param(95, 35, id="positive"),
pytest.param(-13, -25, id="negative"),
pytest.param(0, 17.7778, id="zero"),
]
)
def test_fahrenheit_to_celsius(value, expected):
"""Test F to C calculation"""
result = temperature.fahrenheit_to_celsius(value)
assert math.isclose(result, expected, abs_tol=0.0001)
@pytest.mark.parametrize(
"value,expected",
[
pytest.param(100, 212, id="positive"),
pytest.param(-20, -4, id="negative"),
pytest.param(0, 32, id="zero"),
]
)
def test_celsius_to_fahrenheit(value, expected):
"""Test C to F calculation"""
result = temperature.celsius_to_fahrenheit(value)
assert math.isclose(result, expected, abs_tol=0.0001)

just for the sake of demoing how one might write this in a real package/reducing duplication/etc. take or leave, not sure of the context/audience for this example.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is fine, but as an aside on more generally how we structure example tests in guides, i've seen one of the major learning hurdles for learning how to write tests be "how to avoid magic number tests that are actually just testing that some value in a file doesn't change rather than function correctness." super common pattern that people will just throw a huge end-to-end thing in a test function and assert that some value that comes out of it remains a hardcoded value in the test body, rather than something where a known input is coupled to an expected output, and then they struggle with how to add additional cases to protect against regressions/having to tiptoe around the test data file to avoid trivial changes that break e.g. string comparisons.

include-package-data = false

[tool.setuptools_scm]
write_to = "src/examplePy/_version.py"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe some comment on how this is used? like e.g. this might be imported in __init__ to set a __version__ or something?

Comment on lines +33 to +34
zip-safe = true
include-package-data = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comments on what these do, or links to docs?

Copy link
Copy Markdown
Contributor

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

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

sorry one more thing i am just sort of a big type annotations fan and think it's really good for newcomers to learn because they help you think through your code and let your IDE help you avoid bugs that can be very frustrating. also take or leave.

@@ -0,0 +1,26 @@
def celsius_to_fahrenheit(celsius):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def celsius_to_fahrenheit(celsius):
def celsius_to_fahrenheit(celsius: float) -> float:

return fahrenheit


def fahrenheit_to_celsius(fahrenheit):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def fahrenheit_to_celsius(fahrenheit):
def fahrenheit_to_celsius(fahrenheit: float) -> float:

from examplePy.temperature import fahrenheit_to_celsius


def calc_annual_mean(df: pandas.DataFrame):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def calc_annual_mean(df: pandas.DataFrame):
def calc_annual_mean(df: pandas.DataFrame) -> tuple[pandas.DataFrame, pandas.Series]:

Comment on lines +1 to +2
from typing import Sequence

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
from typing import Sequence

appears unused?

Copy link
Copy Markdown
Collaborator

@ucodery ucodery left a comment

Choose a reason for hiding this comment

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

GitHub is having serious issues loading, well issues, right now so I can't read the original motivation for this issue. I did a general pass on it, but will probably come back to it next week too.

zip-safe = true
include-package-data = false

[tool.setuptools_scm]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this project wants to use setuptools-scm then that needs to be in the build-system.requires

]


[build-system]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why did this section get moved down?

version_scheme = "release-branch-semver"


[project.optional-dependencies]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I personally like and use optional-dependencies, but the new thing to do here is use [dependency-groups](https://packaging.python.org/en/latest/specifications/dependency-groups/) (not sure if you have a preference based on the tutorials @lwasser ?)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I did this for some other example code and the hyphen was intentional. In sphinx we can use diff-file blocks to show, well diffs of how to modify code to fit best practice, but that involves having both files present in the repo. Also, we want these example files linted and tested to make sure they are high-quality, however the -raw files are often intentionally bad style.

Not sure if that is that is what is going on here, as I don't see any documentation references to this file.

def calc_annual_mean(df: pandas.DataFrame):
"""Function to calculate the mean temperature for each year and the final mean"""
# TODO: make this a bit more robust so we can write integration test examples??
# Calculate the mean temperature for each year
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe this is okay for an example project. But I would block this as over-commented for a deployed library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: pyconus-2026

Development

Successfully merging this pull request may close these issues.

5 participants