Skip to content
Merged
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
13 changes: 0 additions & 13 deletions .coveragerc

This file was deleted.

24 changes: 7 additions & 17 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ jobs:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions/checkout@v7

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install tox
run: uv tool install tox --with tox-uv
run: python -m pip install tox

- name: Test
run: tox -e default
Expand All @@ -40,20 +35,15 @@ jobs:
name: Build Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions/checkout@v7

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install tox
run: uv tool install tox --with tox-uv
run: python -m pip install tox

- name: Build docs
run: tox -e docs
Expand All @@ -62,7 +52,7 @@ jobs:
run: touch ./docs/_build/html/.nojekyll

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v5
with:
path: ./docs/_build/html

Expand All @@ -77,7 +67,7 @@ jobs:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: python-package-distributions
path: dist/
Expand All @@ -98,4 +88,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v5
21 changes: 7 additions & 14 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,20 @@ jobs:
runs-on: ${{ matrix.platform }}
name: Python ${{ matrix.python }}, ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install tox
run: uv tool install tox --with tox-uv

- name: Install dependencies
run: uv sync --all-extras --python ${{ matrix.python }}
run: python -m pip install tox coverage

- name: Run tests
run: |
tox -e default -- --cov --cov-branch --cov-report=xml
run: >-
tox
-- -rFEx --durations 10 --color yes --cov --cov-branch --cov-report=xml # pytest args

- name: Check for codecov token availability
id: codecov-check
Expand All @@ -71,7 +64,7 @@ jobs:
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v7
if: ${{ steps.codecov-check.outputs.codecov == 'true' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
flags: ${{ matrix.platform }} - py${{ matrix.python }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.0

- `uv` is an optional dependency. defaults to using pip and tox for most commands.

## 0.1.0 - 0.1.3

- Switch to copier and modify the templates
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ To create a brand new repository, you can use the `hatchit` CLI command:
hatchit my-awesome-package --description "A robust new tool" --license MIT
```

By default, `hatchit` builds standard `tox` environments with pip installation. If you want to use the blazing fast `uv` ecosystem instead, just add `--use-uv`:

```bash
hatchit my-awesome-package --description "A robust new tool" --license MIT --use-uv
```

Alternatively, since `hatchit` is a 100% compatible Copier template, you can use `copier` directly to render the project!

```bash
Expand Down Expand Up @@ -50,13 +56,15 @@ That's it! You're ready to start writing code.

## Development Process

`hatchit` structures your project around `tox` and `uv`. To run your tests during development:
`hatchit` structures your project around `tox` for automated testing. To run your tests during development:

```bash
cd my-awesome-package
tox -e default
```

If you configured the project with `--use-uv`, tox will automatically use `uv` under the hood!

To build your documentation locally and preview:
```bash
tox -e docs
Expand Down
9 changes: 8 additions & 1 deletion copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ github_username:
type: str
default: "YOUR_ORG_OR_USERNAME"
help: GitHub Organization or Username
use_uv:
type: bool
default: false
help: "Use uv for dependency management and tox running?"
choices:
"No": false
"Yes": true

# Tasks to run after generation
_tasks:
- "uv lock"
- "{% if use_uv %}uv lock{% else %}echo Skip uv lock{% endif %}"
- "git init"
- "git add ."
# Use ignore_errors because git commit might fail if git user isn't configured, or we can just run it.
Expand Down
5 changes: 5 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sphinx>=7.0.0
furo
myst-nb
sphinx-autodoc-typehints
linkify-it-py
51 changes: 38 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ authors = [
]
requires-python = ">=3.10"
dependencies = [
"uv",
"copier>=9.0.0",
]
keywords = [
"scaffold",
"uv",
"hatch",
"project",
"generator",
Expand All @@ -38,6 +36,10 @@ classifiers = [
"Topic :: Software Development :: Code Generators",
]


[project.license]
file = "LICENSE.md"

[project.urls]
Homepage = "https://github.com/biocpy/hatchit"
Documentation = "https://biocpy.github.io/hatchit"
Expand Down Expand Up @@ -94,19 +96,42 @@ docstring-code-line-length = 20
strict = true

[tool.pytest.ini_options]
addopts = "--cov --cov-report term-missing"
addopts = "--cov=hatchit --cov-report term-missing"
testpaths = [
"tests",
]

[dependency-groups]
dev = [
"pytest",
"pytest-cov",
"sphinx",
"myst-nb",
"furo",
"sphinx-autodoc-typehints",
"linkify-it-py",
"mypy",
[project.optional-dependencies]
testing = [
"pytest>=9.1.1",
"pytest-cov>=7.1.0",
"uv",
]

[tool.bandit]
exclude_dirs = ["tests"]
skips = ["B110"]

[tool.coverage.run]
source_pkgs = ["hatchit"]
branch = true
parallel = true
omit = ["tests/*"]
disable_warnings = ["module-not-measured"]

[tool.coverage.paths]
hatchit = [
"src/hatchit",
"*/site-packages/hatchit"
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self\\.debug",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:"
]
3 changes: 2 additions & 1 deletion src/hatchit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def main():
parser.add_argument("project_path", help="Path where the new project should be created.")
parser.add_argument("--description", default="Add a short description here!", help="Optional project description.")
parser.add_argument("--license", default="MIT", help="License to use. Defaults to MIT.")
parser.add_argument("--use-uv", action="store_true", help="Use uv for dependency management and tox running.")

args = parser.parse_args()

Expand All @@ -24,7 +25,7 @@ def main():
sys.exit(1)

print(f"Hatching project at {project_path}...")
create_hatchit_repository(project_path=project_path, description=args.description, license=args.license)
create_hatchit_repository(project_path=project_path, description=args.description, license=args.license, use_uv=args.use_uv)
print("Success! 🚀 💥")


Expand Down
15 changes: 8 additions & 7 deletions src/hatchit/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__license__ = "MIT"


def create_hatchit_repository(project_path: str, description: str, license: str) -> None:
def create_hatchit_repository(project_path: str, description: str, license: str, use_uv: bool = False) -> None:
"""Create a new Python project using uv and hatch.

This function initializes a new Python project at the specified `project_path`
Expand All @@ -25,6 +25,9 @@ def create_hatchit_repository(project_path: str, description: str, license: str)
license:
The license to use for the project.

use_uv:
Whether to use uv for dependency management. Defaults to False.

Example:
>>> create_hatchit_repository(
... "my_project",
Expand All @@ -43,12 +46,9 @@ def create_hatchit_repository(project_path: str, description: str, license: str)
git_name = "First Author"
git_email = "first.author@example.com"

try:
# Check if gh CLI is installed for github username, or extract from remote if any.
# Defaults to a placeholder
github_username = "YOUR_ORG_OR_USERNAME"
except Exception:
github_username = "YOUR_ORG_OR_USERNAME"
# Check if gh CLI is installed for github username, or extract from remote if any.
# Defaults to a placeholder
github_username = "YOUR_ORG_OR_USERNAME"

proj_name = Path(project_path).parts[-1]

Expand All @@ -59,6 +59,7 @@ def create_hatchit_repository(project_path: str, description: str, license: str)
"author_name": git_name,
"author_email": git_email,
"github_username": github_username,
"use_uv": use_uv,
}

template_dir = Path(__file__).parent.parent.parent
Expand Down
13 changes: 0 additions & 13 deletions template/.coveragerc

This file was deleted.

2 changes: 1 addition & 1 deletion template/.github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: actions/setup-python@v5
with:
python-version: '3.12'
Expand Down
Loading
Loading