Skip to content

Commit

Permalink
Add example project, update slides.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoules committed Sep 23, 2024
1 parent 7deb42a commit 849fbc4
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 63 deletions.
Binary file added 34_PyPackaging/assets/bit.ly_sciware-sep2024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 34_PyPackaging/assets/sample-layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions 34_PyPackaging/example_project_root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## This is just an example!
# You probably aren't using most of this tooling!

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Data files
*npy

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
coverage.lcov
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
python/test/unit/plots/*

# Translations
*.mo
*.pot

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# PyCharm project settings
.idea

# Rope project settings
.ropeproject

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.vscode
deprecated
setup*
4 changes: 4 additions & 0 deletions 34_PyPackaging/example_project_root/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This should almost certainly be one of the standard licenses.

Which one to pick is outside the scope of this session, but may
be discussed in future sessions about distributing your code.
5 changes: 5 additions & 0 deletions 34_PyPackaging/example_project_root/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# README

Note that this would be visible both on GitHub and
on the package distribution network you publish to
(e.g. [PyPI](https://pypi.org/), the Python Package Index).
10 changes: 10 additions & 0 deletions 34_PyPackaging/example_project_root/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Documentation

For your project would go here.

Documentation best practices and tooling are outside the
scope of this tutorial, however Sciware has other
presentations on these topics,
[Sciware 20](https://github.com/flatironinstitute/sciware/tree/main/20_Documentation)
in particular.

27 changes: 27 additions & 0 deletions 34_PyPackaging/example_project_root/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[project]
name = "SciwarePackage"
version = "0.0.1"
description = "Example package for Sciware 34"
authors = [
{ name = "Jeff Soules", email = "[email protected]" }
]
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
requires-python = ">=3.8"
dependencies = [
"numpy>=1.24.0",
]

[project.license]
file = "LICENSE"

[build-system]
requires = ["setuptools>=61.0"]
build-backend="setuptools.build_meta"

[tool.setuptools]
package-dir = {"" = "src"}
packages = ["SciwarePackage"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from SciwarePackage.api import *
24 changes: 24 additions & 0 deletions 34_PyPackaging/example_project_root/src/SciwarePackage/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

from SciwarePackage.util.formatting import canonicalize_string
from SciwarePackage.util.enums import Mode


def multiply(a: int | float, b: int | float):
return float(a * b)


def describe_operation(desc: str, left_operand: int | float, right_operand: int | float):
canonical_string = canonicalize_string(desc)
product = multiply(left_operand, right_operand)
print(f"{canonical_string}\n\t{product}")


def main(mode: Mode, l: int | float, r: int | float):
if mode == Mode.SIMPLE:
describe_operation("times", l, r)
else:
describe_operation("multiplication of two numbers", l, r)


if __name__ == "__main__":
main(Mode.ADVANCED, 3, 5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .mode import Mode as Mode
from .precision import Precision as Precision
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum

class Mode(Enum):
SIMPLE = 'simple'
ADVANCED = 'advanced'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum

class Precision(Enum):
LOW = 1
HIGH = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def canonicalize_string(base_string: str) -> str:
if (base_string == ''):
return "[empty string]"
return base_string.capitalize()
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit 849fbc4

Please sign in to comment.