Skip to content

Commit

Permalink
rework module, rework build, add docs, swap to poetry for build (#20)
Browse files Browse the repository at this point in the history
* rework module, rework build, add docs

* remove archives check

* fix more actions

* more tweaks

* install poetry?

* fix poetry run
  • Loading branch information
jpetrucciani authored Mar 8, 2024
1 parent 5e1a2e8 commit 2314371
Show file tree
Hide file tree
Showing 26 changed files with 1,816 additions and 459 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
watch_file ./poetry.lock
use nix
export _SITE_PKGS="$(dirname $(dirname $(which python)))/lib/python3.11/site-packages"
export PYTHONPATH="$_SITE_PKGS"
31 changes: 16 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up python
uses: actions/setup-python@v2
- uses: actions/[email protected]
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
sed -i -E "s#VERSION#${GITHUB_REF/refs\/tags\//}#g" ./setup.py
python-version: '3.11'
- name: build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
run: poetry publish --build -n -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }}
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v25
- run: nix run -f . scripts.docs
- uses: actions/configure-pages@v4
- uses: actions/upload-pages-artifact@v3
with:
path: 'docs/build/html'
- id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR is stale because it has been open 7 days with no activity. Remove stale label or comment or this will be closed in 7 days'
Expand Down
30 changes: 12 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,37 @@ on:
workflow_dispatch:

jobs:
archives:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: jpetrucciani/archives-check@main
with:
path: 'gamble/'
mypy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
- uses: jpetrucciani/mypy-check@master
with:
path: gamble
black:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
- uses: jpetrucciani/black-check@master
ruff:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.1
- uses: jpetrucciani/ruff-check@main
tests:
runs-on: ubuntu-22.04
needs: [archives, mypy, black, ruff]
needs: [mypy, black, ruff]
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
name: python ${{ matrix.python-version }} tests
steps:
- uses: actions/checkout@v4
- name: setup python
uses: actions/setup-python@v3
- uses: actions/checkout@v4.1.1
- run: pipx install poetry
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: install requirements
run: pip install -r requirements.dev.txt
- name: run Tox
run: tox -e py
cache: 'poetry'
- run: poetry install
- run: poetry run pytest ./tests -s --cov gamble --cov-report html --cov-report term --cov-report xml:coverage.xml --junitxml=report.xml
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ ENV/

# End of https://www.gitignore.io/api/python

report.xml
# vscode
.history/
.vscode/

# direnv
.direnv/

# docs
docs/build
docs/source/gamble
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Jacobi Petrucciani
Copyright (c) 2024 Jacobi Petrucciani

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[![PyPI
version](https://badge.fury.io/py/gamble.svg)](https://badge.fury.io/py/gamble)
[![Code style:
black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Python 3.10+
supported](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/release/python-3100/)
[![Documentation style:
archives](https://img.shields.io/badge/docstyle-archives-lightblue.svg)](https://github.com/jpetrucciani/archives)
[![PyPI version](https://badge.fury.io/py/gamble.svg)](https://badge.fury.io/py/gamble)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Python 3.10+ supported](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/release/python-3100/)

**gamble** is a simple library that implements a collection of some
common gambling-related classes
Expand Down
71 changes: 51 additions & 20 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
{ pkgs ? import
(fetchTarball {
name = "jpetrucciani-2023-10-17";
url = "https://github.com/jpetrucciani/nix/archive/d944b2ed0e17f5e8e12332d21d226038ccb77ccb.tar.gz";
sha256 = "0dzcqs7614pd0z0n17d3y6n6w1snk0x54pj8m740w4657i538g7s";
name = "jpetrucciani-2024-03-07";
url = "https://github.com/jpetrucciani/nix/archive/b063a2ae8e915ef8047fc2c3c486a6ec46f22c38.tar.gz";
sha256 = "0r9x2ghcvi4nrh4g8qf73616972g13b82k3zj3ij77rx3cs7p81q";
})
{ }
}:
let
name = "gamble";

python = (pkgs.poetry2nix.mkPoetryEnv {
projectDir = ./.;
python = pkgs.python311;
overrides = pkgs.poetry2nix.overrides.withDefaults (final: prev: { });
editablePackageSources = {
"gamble" = ./gamble;
};
preferWheels = true;
});

tools = with pkgs; {
cli = [
nixpkgs-fmt
];
python = [
ruff
(python311.withPackages (p: with p; [
colorama
pytest
pytest-cov
setuptools
tox
]))
];
scripts = [
(writeShellScriptBin "test_actions" ''
export DOCKER_HOST=$(${pkgs.docker-client}/bin/docker context inspect --format '{{.Endpoints.docker.Host}}')
${pkgs.act}/bin/act --container-architecture linux/amd64 -r --rm
'')
poetry
python
];
scripts = pkgs.lib.attrsets.attrValues scripts;
};

scripts =
let
inherit (pkgs.writers) writeBashBin;
repo = "$(${pkgs.git}/bin/git rev-parse --show-toplevel)";
in
{
test_actions = writeBashBin "test_actions" ''
export DOCKER_HOST=$(${pkgs.docker-client}/bin/docker context inspect --format '{{.Endpoints.docker.Host}}')
${pkgs.act}/bin/act --container-architecture linux/amd64 -r --rm
'';
_test = writeBashBin "_test" ''
export PYTEST_RUNNING=1
${python}/bin/pytest ./tests \
-s \
--cov ${name} \
--cov-report term \
--cov-report html \
--cov-report xml:coverage.xml \
--junitxml=report.xml \
"$@"
'';
docs = writeBashBin "docs" ''
cd "${repo}/docs" || exit 1
rm -rf ./build
${python}/bin/sphinx-build -M html source build
'';
};
paths = pkgs.lib.flatten [ (builtins.attrValues tools) ];
env = python.env.overrideAttrs (_: {
buildInputs = paths;
});
in
pkgs.buildEnv {
inherit name paths;
buildInputs = paths;
}
(env.overrideAttrs (_: {
inherit name;
NIXUP = "0.0.6";
})) // { inherit scripts; }

11 changes: 11 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# docs

This directory configures [sphinx](https://www.sphinx-doc.org/en/master/) documentation for gamble

---

## In this directory

### [source/](./source/)

This contains the configuration and source files for the documentation that will be generated
4 changes: 4 additions & 0 deletions docs/source/_static/css/overrides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import 'theme.css';
.wy-nav-content {
max-width: 100% !important;
}
70 changes: 70 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
sphinx config
"""

import os
import sys
from datetime import date


sys.path.insert(0, os.path.abspath("../../"))

project = "gamble"
copyright = f"{date.today().year} jpetrucciani"
author = "jpetrucciani"
master_doc = "index"

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx_rtd_theme",
]
autodoc_type_aliases = {}
autodoc_typehints = "both"
autodoc_typehints_format = "fully-qualified"
autodoc_default_options = {
"show-inheritance": True,
"members": True,
}

autosummary_generate = True
napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True
napoleon_include_special_with_doc = True
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True

pygments_style = "sphinx"
show_sphinx = False

templates_path = ["_templates"]
exclude_patterns = []

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
html_style = "css/overrides.css"

html_theme_options = {
"logo_only": False,
"display_version": True,
"prev_next_buttons_location": "bottom",
"style_external_links": False,
"vcs_pageview_mode": "",
# Toc options
"collapse_navigation": True,
"sticky_navigation": True,
"navigation_depth": 4,
"includehidden": True,
"titles_only": False,
}
12 changes: 12 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
gamble documentation
===================================

.. autosummary::
:toctree: gamble
:recursive:

gamble

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
50 changes: 47 additions & 3 deletions gamble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
"""
@author jacobi petrucciani
@desc gamble module
gamble module
"""
from gamble.models import * # noqa

from gamble.models import (
# cards
BlackJackDeck,
Card,
Deck,
EuchreDeck,
Hand,
MultiDeck,
Rank,
Suit,
Value,
# dice
Die,
Dice,
RiggedDie,
# golf
Course,
Group,
HCC,
Hole,
Player,
)

__all__ = [
# cards
"BlackJackDeck",
"Card",
"Deck",
"EuchreDeck",
"Hand",
"MultiDeck",
"Rank",
"Suit",
"Value",
# dice
"Die",
"Dice",
"RiggedDie",
# golf
"Course",
"Group",
"HCC",
"Hole",
"Player",
]
Loading

0 comments on commit 2314371

Please sign in to comment.