Skip to content

Commit

Permalink
Replace template code and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bsweger committed Aug 9, 2024
1 parent 0023970 commit aa3bd0a
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 105 deletions.
59 changes: 7 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
# reichlab-python-template
# Standardize Repo Settings

[REPLACE WITH A DESCRIPTION OF YOUR PROJECT]
Tools to standardize repository settings in a specific GitHub organization.

A Python template for Reich Lab projects.
For the Reich Lab repos, we've decided to:

This repo contains a Python package with minimal functionality. It serves as a starting point for new projects (it can be selected as the template when creating a new repo in the Reich Lab org).

There as some opinionated choices here (explained below) which people should override as needed. The main goal is to have a consistent starting point to get up and running with a new Python code base.

## Getting started

[REMOVE THIS SECTION AFTER FOLLOWING THE INSTRUCTIONS BELOW]

If you're using this repo as a template for a new project, make the following changes:

1. Replace all instances of `reichlab-python-template` with the name of your repo/project.

2. Replace all instances of `reichlab_python_template` with the name of your module (remember that Python module names cannot contain hyphens).

3. Update [`pyproject.toml`](pyproject.toml). This file is required and will describe several aspects of your project. `pyproject.toml` replaces `setup.py` and is described in detail on [Python's packaging website](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/).

4. Follow the _Setup for local development_ instructions below to ensure that everything works as expected.


## Installing and running the package (no development)

To install this package via pip:

```bash
pip install git+[GITHUB LINK TO YOUR REPO]
```

To run it:
```bash
reichlab_python_template
```
* Disallow direct pushes to the main branch
* Allow repo write access to all members of the Reich Lab organization
* Require code reviews before merging to the main branch

## Setup for local development

Expand All @@ -56,7 +28,7 @@ Developers will be using a Python virtual environment that:
2. Change to the repo's root directory:

```bash
cd reichlab-python-template
cd standardize-repo-settings
```

3. Make sure the correct version of Python is currently active, and create a Python virtual environment:
Expand Down Expand Up @@ -131,20 +103,3 @@ To add a dependency to the project:
# alternately, you can use uv to install the dependencies: it is faster and has a
# a handy sync option that will cleanup unused dependencies
uv pip sync requirements/requirements-dev.txt
## Opinionated notes on Python tooling
[REMOVE THIS SECTION]
The Python ecosystem is overwhelming! Current opinionated preferences, subject to change:
- To install and manage various versions of Python: [pyenv](https://github.com/pyenv/pyenv) + a local .python-version file
- To install Python packages that are available from anywhere on the machine, regardless of which Python environment is activated: [pipx](https://pipx.pypa.io/stable/)
- To create and manage Python virtual environments: [venv](https://docs.python.org/3/library/venv.html).
- I like having the environment packages right there in the project directory
- Everything single third-party tool for managing virtual environments (_e.g._, poetry, PDM, pipenv) does _too much_ and gets in my way
- To generate requirements files from `pyproject.toml`: ['uv'](https://github.com/astral-sh/uv?tab=readme-ov-file#getting-started). I don't usually recommend things this new, but it's orders of magnitude faster than `pip-compile`.
- To install dependencies: uv again (again, mostly due to speed; good old pip is another fine option)
- Logging: [structlog](https://www.structlog.org/en/stable/). I recently stopped fighting Python's built-in logging module and haven't looked back.
- Linting and formatting: [ruff](https://github.com/astral-sh/ruff) because it does both and is fast.
- Pre-commit hooks: [pre-commit](https://pre-commit.com/).
16 changes: 6 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "reichlab-python-template"
description = "Python template for Reich Lab projects"
name = "standardize-repo-settings"
description = "Standardize GitHub repository settings"
license = {text = "MIT License"}
readme = "README.md"
requires-python = '>=3.10'
Expand All @@ -13,31 +13,27 @@ dynamic = ["version"]
dependencies = [
"structlog",
"rich",
"toml"
]

[project.optional-dependencies]
dev = [
"coverage",
"freezegun",
"mypy",
"pre-commit",
"pytest",
"ruff",
"types-toml",
]

[project.entry-points."console_scripts"]
reichlab_python_template = "reichlab_python_template.app:main"
standardize_repo_settings = "standardize_repo_settings.app:main"

[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"]

[tools.setuptools]
packages = ["reichlab_python_template"]
packages = ["standardize_repo_settings"]

[tool.reichlab_python_template]
[tool.standardize_repo_settings]
# to write json-formatted logs to disk, uncomment the following line specify the file location
# log_file = "/path/to/log/files/rechlab_python_template.log"

Expand All @@ -52,4 +48,4 @@ inline-quotes = "double"
quote-style = "double"

[tool.setuptools.dynamic]
version = {attr = "reichlab_python_template.__version__"}
version = {attr = "standardize_repo_settings.__version__"}
37 changes: 10 additions & 27 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt
#
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --extra dev -o requirements/requirements-dev.txt
cfgv==3.4.0
# via pre-commit
coverage==7.5.1
# via python-app (pyproject.toml)
distlib==0.3.8
# via virtualenv
filelock==3.14.0
# via virtualenv
freezegun==1.5.0
# via python-app (pyproject.toml)
identify==2.5.36
# via pre-commit
iniconfig==2.0.0
Expand All @@ -23,7 +15,7 @@ markdown-it-py==3.0.0
mdurl==0.1.2
# via markdown-it-py
mypy==1.10.0
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
mypy-extensions==1.0.0
# via mypy
nodeenv==1.8.0
Expand All @@ -35,31 +27,22 @@ platformdirs==4.2.1
pluggy==1.5.0
# via pytest
pre-commit==3.7.0
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
pygments==2.18.0
# via rich
pytest==8.2.0
# via python-app (pyproject.toml)
python-dateutil==2.9.0.post0
# via freezegun
# via standardize-repo-settings (pyproject.toml)
pyyaml==6.0.1
# via pre-commit
rich==13.7.1
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
ruff==0.4.3
# via python-app (pyproject.toml)
six==1.16.0
# via python-dateutil
# via standardize-repo-settings (pyproject.toml)
setuptools==72.1.0
# via nodeenv
structlog==24.1.0
# via python-app (pyproject.toml)
toml==0.10.2
# via python-app (pyproject.toml)
types-toml==0.10.8.20240310
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
typing-extensions==4.11.0
# via mypy
virtualenv==20.26.1
# via pre-commit

# The following packages are considered to be unsafe in a requirements file:
# setuptools
14 changes: 4 additions & 10 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements/requirements.txt
#
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml -o requirements/requirements.txt
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
pygments==2.18.0
# via rich
rich==13.7.1
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
structlog==24.1.0
# via python-app (pyproject.toml)
toml==0.10.2
# via python-app (pyproject.toml)
# via standardize-repo-settings (pyproject.toml)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import structlog

from reichlab_python_template.util.date import get_current_date
from reichlab_python_template.util.logs import setup_logging
from standardize_repo_settings.util.date import get_current_date
from standardize_repo_settings.util.logs import setup_logging

setup_logging()
logger = structlog.get_logger()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import structlog

import reichlab_python_template
import standardize_repo_settings


def add_custom_info(logger, method_name, event_dict):
event_dict["version"] = reichlab_python_template.__version__
event_dict["version"] = standardize_repo_settings.__version__
return event_dict


Expand Down
2 changes: 1 addition & 1 deletion tests/reichlab_python_template/test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from freezegun import freeze_time
from reichlab_python_template.app import main
from standardize_repo_settings.app import main


@freeze_time("2019-07-13")
Expand Down
2 changes: 1 addition & 1 deletion tests/reichlab_python_template/unit/util/test_date.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unit tests for the date module."""

from freezegun import freeze_time
from reichlab_python_template.util.date import get_current_date
from standardize_repo_settings.util.date import get_current_date


@freeze_time("2024-01-02")
Expand Down

0 comments on commit aa3bd0a

Please sign in to comment.