Skip to content

Commit 87bcd3f

Browse files
committed
feat: gather common classes for trame
1 parent e8da741 commit 87bcd3f

26 files changed

+1606
-0
lines changed

.codespellrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[codespell]
2+
skip = CHANGELOG.md

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"

.github/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
exclude:
3+
authors:
4+
- dependabot
5+
- pre-commit-ci
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Test and Release
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
# Many color libraries just need this to be set to any value, but at least
16+
# one distinguishes color depth, where "3" -> "256-bit color".
17+
FORCE_COLOR: 3
18+
19+
jobs:
20+
pre-commit:
21+
name: Format
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.x"
30+
- uses: pre-commit/action@v3.0.1
31+
with:
32+
extra_args: --hook-stage manual --all-files
33+
- name: Run Lint
34+
run: pipx run nox -s lint
35+
- name: Run Tests
36+
run: pipx run nox -s tests
37+
38+
checks:
39+
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
40+
runs-on: ${{ matrix.runs-on }}
41+
needs: [pre-commit]
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
python-version: ["3.9", "3.10", "3.13"]
46+
runs-on: [ubuntu-latest, windows-latest, macos-14]
47+
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- uses: actions/setup-python@v5
54+
with:
55+
python-version: ${{ matrix.python-version }}
56+
allow-prereleases: true
57+
58+
- name: Install package
59+
run: python -m pip install .[test]
60+
61+
- name: Test package
62+
run: >-
63+
python -m pytest -ra --cov --cov-report=xml --cov-report=term
64+
--durations=20
65+
66+
- name: Upload coverage report
67+
uses: codecov/codecov-action@v5.4.0
68+
with:
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
71+
release:
72+
needs: [pre-commit, checks]
73+
name: Distribution build
74+
runs-on: ubuntu-latest
75+
if: github.event_name == 'push'
76+
permissions:
77+
id-token: write
78+
attestations: write
79+
contents: write
80+
environment:
81+
name: pypi
82+
url: https://pypi.org/p/trame-common
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
with:
87+
fetch-depth: 0
88+
- name: Python Semantic Release
89+
id: release
90+
uses: python-semantic-release/python-semantic-release@v9.21.0
91+
with:
92+
github_token: ${{ secrets.GITHUB_TOKEN }}
93+
# for debug output
94+
# root_options: "-vv"
95+
96+
- name: Generate artifact attestation for sdist and wheel
97+
if: steps.release.outputs.released == 'true'
98+
uses: actions/attest-build-provenance@v2.2.3
99+
with:
100+
subject-path: "dist/*"
101+
102+
- uses: pypa/gh-action-pypi-publish@release/v1
103+
if: steps.release.outputs.released == 'true'

.pre-commit-config.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
ci:
2+
autoupdate_commit_msg: "chore: update pre-commit hooks"
3+
autofix_commit_msg: "style: pre-commit fixes"
4+
5+
exclude: ^.cruft.json|.copier-answers.yml$
6+
7+
repos:
8+
- repo: https://github.com/adamchainz/blacken-docs
9+
rev: "1.19.1"
10+
hooks:
11+
- id: blacken-docs
12+
additional_dependencies: [black==24.*]
13+
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: "v5.0.0"
16+
hooks:
17+
- id: check-added-large-files
18+
- id: check-case-conflict
19+
- id: check-merge-conflict
20+
- id: check-symlinks
21+
- id: check-yaml
22+
- id: debug-statements
23+
- id: end-of-file-fixer
24+
- id: mixed-line-ending
25+
- id: name-tests-test
26+
args: ["--pytest-test-first"]
27+
- id: requirements-txt-fixer
28+
- id: trailing-whitespace
29+
30+
- repo: https://github.com/pre-commit/pygrep-hooks
31+
rev: "v1.10.0"
32+
hooks:
33+
- id: rst-backticks
34+
- id: rst-directive-colons
35+
- id: rst-inline-touching-normal
36+
37+
- repo: https://github.com/rbubley/mirrors-prettier
38+
rev: "v3.4.2"
39+
hooks:
40+
- id: prettier
41+
types_or: [yaml, markdown, html, css, scss, javascript, json]
42+
args: [--prose-wrap=always]
43+
44+
- repo: https://github.com/astral-sh/ruff-pre-commit
45+
rev: "v0.9.1"
46+
hooks:
47+
- id: ruff
48+
args: ["--fix", "--show-fixes"]
49+
- id: ruff-format
50+
51+
- repo: https://github.com/codespell-project/codespell
52+
rev: "v2.3.0"
53+
hooks:
54+
- id: codespell
55+
56+
- repo: https://github.com/shellcheck-py/shellcheck-py
57+
rev: "v0.10.0.1"
58+
hooks:
59+
- id: shellcheck
60+
61+
- repo: local
62+
hooks:
63+
- id: disallow-caps
64+
name: Disallow improper capitalization
65+
language: pygrep
66+
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
67+
exclude: .pre-commit-config.yaml
68+
69+
- repo: https://github.com/abravalheri/validate-pyproject
70+
rev: "v0.23"
71+
hooks:
72+
- id: validate-pyproject
73+
additional_dependencies: ["validate-pyproject-schema-store[all]"]
74+
75+
- repo: https://github.com/python-jsonschema/check-jsonschema
76+
rev: "0.31.0"
77+
hooks:
78+
- id: check-dependabot
79+
- id: check-github-workflows
80+
- id: check-readthedocs

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHANGELOG.md

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# trame-common: common code for any trame package
2+
3+
Trame is rapidly evolving and having a dependency-less package to provide helper
4+
functions and classes across trame's eco-system is important for its future
5+
health. Initially some of those classes were created inside **trame-client**,
6+
**trame-server** or even **trame**, but we reached a point where some of those
7+
should become even more mainstream so they could easily be used on server,
8+
client, widget and more. That is where **trame-common** comes to play by
9+
providing a central location that any package can depend on. By default,
10+
**trame** remain the meta package that will impose some minimum version on
11+
**trame-common**, **trame-client** and **trame-server** and expose via some
12+
common namespace various pieces of those 3 dependencies. But if you need any
13+
piece of **trame-common**, feel free to depend on it.
14+
15+
Trame-common is not meant to be installed by itself, but instead be used by any
16+
trame package that may require one of its function or helper class. While some
17+
of the module may require extra dependency, we are not listing them in this
18+
package purposely but the using code, should properly describe such dependency.
19+
20+
## Content
21+
22+
**trame-common** is composed of several packages to split the current set of
23+
classes and function in meaningful groups.
24+
25+
- **trame_common.assets**: Contains anything related to local and remote file
26+
including possible associated mime types.
27+
- **trame_common.decorators**: Contains all decorators for functions, classes
28+
and methods.
29+
- **trame_common.exec**: Contains helpers for handling code execution (i.e.
30+
async, throttle, debounce, thread, process).
31+
- **trame_common.obj**: Contains helpers for common trame objects (i.e.
32+
Component, App, Widget, Singleton)
33+
34+
## License
35+
36+
trame-common is made available under the Apache License, Version 2.0. For more
37+
details, see
38+
[LICENSE](https://github.com/Kitware/trame-common/blob/master/LICENSE).
39+
40+
## Development steps
41+
42+
- Clone the repository using `git clone`
43+
- Install pre-commit via `pip install pre-commit` or `pip install -e ".[dev]"`
44+
- Run `pre-commit install` to set up pre-commit hooks
45+
- Run `pre-commit install --hook-type commit-msg` to register commit-msg hook
46+
- Make changes to the code, and commit your changes to a separate branch. Use
47+
[conventional commit messages](https://www.conventionalcommits.org/en/v1.0.0/).
48+
- Create a fork of the repository on GitHub
49+
- Push your branch to your fork, and open a pull request
50+
51+
**Tips**
52+
53+
- When first creating a new project, it is helpful to run
54+
`pre-commit run --all-files` to ensure all files pass the pre-commit checks.
55+
- A quick way to fix `ruff` issues is by installing ruff (`pip install ruff`)
56+
and running the `ruff check --fix .` or `ruff format` command at the root of
57+
your repository.
58+
- A quick way to fix `codespell` issues is by installing codespell
59+
(`pip install codespell`) and running the `codespell -w` command at the root
60+
of your directory.
61+
- The
62+
`.codespellrc file <https://github.com/codespell-project/codespell#using-a-config-file>`\_
63+
can be used fix any other codespell issues, such as ignoring certain files,
64+
directories, words, or regular expressions.

noxfile.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import shutil
2+
from pathlib import Path
3+
4+
import nox
5+
6+
DIR = Path(__file__).parent.resolve()
7+
8+
nox.needs_version = ">=2024.3.2"
9+
nox.options.sessions = ["lint", "tests"]
10+
nox.options.default_venv_backend = "uv|virtualenv"
11+
12+
13+
@nox.session
14+
def lint(session: nox.Session) -> None:
15+
"""
16+
Run the linter.
17+
"""
18+
session.install("pre-commit")
19+
session.run(
20+
"pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs
21+
)
22+
23+
24+
@nox.session
25+
def tests(session: nox.Session) -> None:
26+
"""
27+
Run the unit and regular tests.
28+
"""
29+
session.install(".[test]")
30+
session.run("pytest", *session.posargs)
31+
32+
33+
@nox.session
34+
def build(session: nox.Session) -> None:
35+
"""
36+
Build an SDist and wheel.
37+
"""
38+
39+
build_path = DIR.joinpath("build")
40+
if build_path.exists():
41+
shutil.rmtree(build_path)
42+
43+
session.install("build")
44+
session.run("python", "-m", "build")

0 commit comments

Comments
 (0)