Skip to content

Commit

Permalink
feat: resolve conflicts, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
manmartgarc committed Apr 28, 2024
2 parents 7593dea + a8c6e14 commit 19b390e
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 260 deletions.
8 changes: 0 additions & 8 deletions .bumpversion.cfg

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
73 changes: 73 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!-- Inspired by https://github.com/burnash/gspread/blob/master/.github/CONTRIBUTING.md -->
# Contributing Guide

- Check the [GitHub Issues](https://github.com/manmartgarc/stochatreat/issues) for open issues that need attention.
- Follow the [How to submit a contribution](https://opensource.guide/how-to-contribute/#how-to-submit-a-contribution) Guide.

- Make sure unit tests pass. Please read how to run unit tests [below](#tests).

- If you are fixing a bug:
- If you are resolving an existing issue, reference the issue ID in a commit message `(e.g., fixed #XXXX)`.
- If the issue has not been reported, please add a detailed description of the bug in the Pull Request (PR).
- Please add a regression test case to check the bug is fixed.

- If you are adding a new feature:
- Please open a suggestion issue first.
- Provide a convincing reason to add this feature and have it greenlighted before working on it.
- Add tests to cover the functionality.

- Please follow [Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/).

## Setting up development environment

You can install the development environment, i.e. all the dependencies required to run all tests and checks that are run when you submit a PR, by following these steps:

1. [Install](https://hatch.pypa.io/1.9/install/#installation) `hatch`.
2. Clone the repository:
```bash
git clone https://github.com/manmartgarc/stochatreat
cd stochatreat
```
3. Confirm `hatch` picked up the project:
```bash
hatch status
```

## Tests

To run tests in the default environment:

```bash
hatch run default:test
```

To run tests in all environments:

```bash
hatch run all:test
```

## Format

When submitting a PR, the CI will run `make format` and also `make lint` to check the format of the code. You can run this locally by running:

```bash
hatch fmt
```

## Release

- Run `hatch` to update the version number file and create a new tag:

```bash
hatch version [major|minor|patch]
```

- Commit the changes and push them to your fork.
- Tag the new version:
```bash
git tag -a v0.0.0 -m "v0.0.0"
git push origin v0.0.0
```
- Submit a PR.
- Once the PR is merged, run `hatch publish` to create a new release in PyPI.
32 changes: 17 additions & 15 deletions .github/workflows/test.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: test
name: Release CI

on:
push:
Expand All @@ -14,28 +14,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
- name: Install hatch
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Lint with Ruff
python -m pip install hatch
- name: Check lint and format
run: |
make lint
- name: Check style with Black
run: |
make style
hatch fmt --check
- name: Type-checking with Mypy
run: |
make test/mypy
- name: Test with pytest
hatch run types:check
- name: Run tests with pytest
run: |
make test/pytest
hatch run +py=${{ matrix.python-version }} all:test-cov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: coverage.json
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode
*.ps1
coverage.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
49 changes: 0 additions & 49 deletions Makefile

This file was deleted.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

| | |
|---|---|
|Build|[![Main Branch Tests](https://github.com/manmartgarc/stochatreat/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/manmartgarc/stochatreat/actions/workflows/test.yml)
|Build|[![Main Branch Tests](https://github.com/manmartgarc/stochatreat/actions/workflows/release.yml/badge.svg?branch=main)](https://github.com/manmartgarc/stochatreat/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/manmartgarc/stochatreat/graph/badge.svg?token=llPoW2rWIN)](https://codecov.io/gh/manmartgarc/stochatreat)
|PyPI| [![pypi](https://img.shields.io/pypi/v/stochatreat?logo=pypi)](https://pypi.org/project/stochatreat/) ![pypi-downloads](https://img.shields.io/pypi/dm/stochatreat?logo=pypi)
|conda-forge| [![Conda](https://img.shields.io/conda/v/conda-forge/stochatreat?logo=conda-forge)](https://anaconda.org/conda-forge/stochatreat) ![conda-downloads](https://img.shields.io/conda/dn/conda-forge/stochatreat?logo=conda-forge)
|Meta| [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![code style - Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![types - Mypy](https://img.shields.io/badge/types-Mypy-blue.svg)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-9400d3.svg)](https://spdx.org/licenses/)
|Meta| [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![types - Mypy](https://img.shields.io/badge/types-Mypy-blue.svg)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-9400d3.svg)](https://spdx.org/licenses/)

---

Expand Down Expand Up @@ -119,6 +119,10 @@ nhood dummy
1 35 68
```

## Contributing

If you'd like to contribute to the package, make sure you read the [contributing guide](https://github.com/manmartgarc/stochatreat/blob/main/.github/CONTRIBUTING.md).

## References

- `stochatreat` is totally inspired by [Alvaro Carril's](https://acarril.github.io/) fantastic STATA package: [`randtreat`](https://acarril.github.io/posts/randtreat), which was published in [The Stata Journal](https://www.stata-journal.com/article.html?article=st0490).
Expand Down
78 changes: 43 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "stochatreat"
version = "0.0.15"
dynamic = ["version"]
description = 'Stratified random assignment using pandas'
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
keywords = [
"randomization",
"block randomization",
"stratified randomization",
"stratified random assignment",
"strata"
]
authors = [
{ name = "Manuel Martinez", email = "[email protected]" },
"strata",
]
authors = [{ name = "Manuel Martinez", email = "[email protected]" }]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
]
dependencies = ["pandas"]

[project.optional-dependencies]
dev = [
"black",
"build",
"bump2version",
"mypy",
"ruff",
"pytest",
"pytest-cov"
]
dependencies = ["pandas>=2.2"]

[project.urls]
Documentation = "https://github.com/manmartgarc/stochatreat/blob/main/README.md"
Issues = "https://github.com/manmartgarc/stochatreat/issues"
Source = "https://github.com/manmartgarc/stochatreat/"

[tools.setuptools.packages.find]
where = ["src"]
namespaces = false
[tool.hatch.version]
path = "src/stochatreat/__about__.py"

[tool.hatch.envs.default]
installer = "uv"
dependencies = ["pytest", "pytest-cov", "pytest-xdist", "coverage[toml]>=6.5"]
[tool.hatch.envs.default.scripts]
test-cov = "pytest --cov=src/stochatreat tests/ --cov-report json -n auto"
test = "test-cov --no-cov"

[tool.hatch.envs.all]
installer = "uv"

[[tool.hatch.envs.all.matrix]]
python = ["3.9", "3.10", "3.11", "3.12"]

[tool.black]
[tool.hatch.envs.types]
dependencies = ["mypy>=1.0.0"]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive src/stochatreat tests/"

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHEKCING",
"__version__ = ",
]

[tool.ruff]
line-length = 79

[tool.ruff.lint]
ignore = ["TRY003"]

[tool.mypy]
python_version = 3.8
check_untyped_defs = true
show_error_codes = true
pretty = true
ignore_missing_imports = true
packages = ["src"]

[tool.pytest.ini_options]
addopts = [
"--cov=stochatreat",
"--cov-branch",
"--cov-report=term-missing",
"--durations=5"
]
3 changes: 2 additions & 1 deletion src/stochatreat/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = "0.0.14"
# pragma: no cover
__version__ = "0.0.19"
14 changes: 2 additions & 12 deletions src/stochatreat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 10 12:16:55 2019
from stochatreat.stochatreat import stochatreat

===============================================================================
@author: Manuel Martinez
@project: stochatreat
===============================================================================
"""
from stochatreat.stochatreat import stochatreat # noqa: F401

__version__ = "0.0.14"
__author__ = "Manuel Martinez"
__all__ = ["stochatreat"]
Empty file added src/stochatreat/py.typed
Empty file.
Loading

0 comments on commit 19b390e

Please sign in to comment.