Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions examples/pure-setuptools/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[project]
name = "examplePy"
authors = [
Expand All @@ -10,15 +6,47 @@ authors = [
maintainers = [
{name = "All the contributors"},
]
description = "An example Python package used to support Python packaging tutorials"
description = "A setuptools example Python package used to support Python packaging tutorials"
keywords = ["pyOpenSci", "python packaging"]
readme = "README.md"
license = "BSD-3-Clause"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Intended Audience :: Science/Research",
]
dependencies = [
"dependency-package-name-1",
"dependency-package-name-2",
dependencies = []
dynamic = [
"version",
]


[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?

requires = [
"setuptools>=61",
"wheel",
]
build-backend = "setuptools.build_meta"


[tool.setuptools]
zip-safe = true
include-package-data = false
Comment on lines +33 to +34
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?


[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

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?

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 ?)


test = [
"pytest",
"numpy",
"pandas",
"ruff",
]

contrib = [
"pre-commit>=4.1.0",
]
Empty file.
26 changes: 26 additions & 0 deletions examples/pure-setuptools/src/examplePy/temperature.py
Original file line number Diff line number Diff line change
@@ -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:

"""
Convert temperature from Celsius to Fahrenheit.

Parameters:
celsius (float): Temperature in Celsius.

Returns:
float: Temperature in Fahrenheit.
"""
fahrenheit = (celsius * 9 / 5) + 32
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:

"""
Convert temperature from Fahrenheit to Celsius.

Parameters:
fahrenheit (float): Temperature in Fahrenheit.

Returns:
float: Temperature in Celsius.
"""
celsius = (fahrenheit - 32) * 5 / 9
return celsius
18 changes: 18 additions & 0 deletions examples/pure-setuptools/src/examplePy/temporal-raw.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.

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...

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Sequence

import pandas

from examplePy.temperature import fahrenheit_to_celsius


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?

# Calculate the mean temperature for each year
yearly_means = df.groupby("Year").mean()

# Calculate the final mean temperature across all years
final_mean = yearly_means.mean()

# Return a converted value
return fahrenheit_to_celsius(yearly_means), fahrenheit_to_celsius(final_mean)
18 changes: 18 additions & 0 deletions examples/pure-setuptools/src/examplePy/temporal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Sequence

Comment on lines +1 to +2
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?

import pandas

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]:

"""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?

# 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.

yearly_means = df.groupby("Year").mean()

# Calculate the final mean temperature across all years
final_mean = yearly_means.mean()

# Return a converted value
return fahrenheit_to_celsius(yearly_means), fahrenheit_to_celsius(final_mean)
Loading
Loading