Skip to content

Commit

Permalink
refactored to internal modules to keep names and added an infinite ge…
Browse files Browse the repository at this point in the history
…nerator for python as well as a possbile combinations calc
  • Loading branch information
nicelgueta committed Jun 19, 2024
1 parent 87550c0 commit 97afe6f
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 103 deletions.
153 changes: 153 additions & 0 deletions .github/workflows/pyci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# This file is autogenerated by maturin v1.6.0
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, musllinux, windows, macos]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/target
venv/
.venv/
__pycache__/
.pytest_cache/
.mypy_cache/
.mypy_cache/
.pypirc
.vscode
*.ipynb
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustyrs"
version = "0.3.2"
version = "0.4.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
15 changes: 14 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
import init, { random_slugs } from "./pkg/rustyrs.js";
init();
export const test = () => {
const slugs = random_slugs(2, 10);
const word_length = document.getElementById("word_len_inp").value;
const slugs = random_slugs(word_length, 10);

// const word_combos = combinations(word_length);

// const wl = document.getElementById("wl");
// wl.textContent = word_length;

// const wlr = document.getElementById("wlr");
// wlr.textContent = word_combos;

const slugsElement = document.getElementById("slugs");
slugsElement.innerHTML = "";
slugs.forEach(slug => {
Expand All @@ -20,6 +30,9 @@
};
document.getElementById("test").addEventListener("click", test);
</script>
<p>Enter length of slug in words (min 1, max 5)</p>
<input type="number" id="word_len_inp" max="5" min="1" />
<!-- <p>Possible combinations with <span id="wl"></span> word(s): <span id="wlr"></span></p> -->
<button id="test">Get 10 slugs</button>
<ul id="slugs"></ul>
</body>
Expand Down
30 changes: 30 additions & 0 deletions rustyrs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class SlugGenerator(object):
"""
A generator that yields slugs of a given word length forever.
"""
def __new__(cls, word_length: int) -> SlugGenerator: ...
def __iter__(self) -> SlugGenerator: ...
def __next__(self) -> str: ...

def get_slug(word_length: int) -> str:
"""
Creates a slug of a given word length.
Args:
word_length: The length of the slug in words
"""
...
def random_slugs(word_length: int, num_outputs: int = 1) -> list[str]:
"""
Creates a list of random slugs of a given word length.
Args:
word_length: The length of the slug in words
num_outputs: The number of slugs to generate
"""
...
def combinations(word_length: int) -> int:
"""
Calculates the number of possible combinations for a given word length.
Args:
word_length: The length of the slug in words
"""
...
Loading

0 comments on commit 97afe6f

Please sign in to comment.