dev: add type hints to source code for better IDE support - #32
dev: add type hints to source code for better IDE support#32NobleCoder69 wants to merge 7 commits into
Conversation
- Create examples/ directory with 3 sample GA4GH policy documents - Add examples/DEMO.md with step-by-step instructions - Create examples/run_demo.py script demonstrating full pipeline - Demo processes 12 chunks and shows 3 sample compliance queries - Fixes ga4gh#20
types-all includes types-pkg-resources which no longer exists on PyPI. Since we're using --ignore-missing-imports, we don't need it anyway.
- Create .env.example with all required and optional variables - Create ENV_SETUP.md with comprehensive setup instructions - Add security best practices and common issues - Fixes ga4gh#23
- Add lint.yml: Run pre-commit hooks on every PR - Add tests.yml: Run pytest on multiple Python versions (3.8-3.12) - Add format.yml: Auto-fix code quality issues and commit - Add .github/workflows/README.md with workflow documentation - Automated testing and linting on every PR - Auto-fixes with PR comments - Coverage reporting with Codecov - Fixes ga4gh#24
There was a problem hiding this comment.
Pull request overview
This PR aims to improve developer ergonomics via Python type hints and introduces a full “code quality + CI” setup (formatting, linting, type checking) along with demo assets/docs for running the project.
Changes:
- Added type annotations to
src/main.pyfor improved IDE/static analysis support. - Introduced Black/Ruff/isort/mypy configuration plus pre-commit hooks.
- Added GitHub Actions workflows, demo script, sample data, and supporting documentation.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
src/main.py |
Adds type annotations to class attributes and method return types. |
pyproject.toml |
Central config for Black/isort/Ruff/mypy. |
examples/run_demo.py |
Adds an end-to-end demo script for sample policy documents. |
examples/data/sample_consent_policy.txt |
Adds sample consent policy text for the demo. |
examples/data/sample_privacy_policy.txt |
Adds sample privacy/security policy text for the demo. |
examples/data/sample_genomic_framework.txt |
Adds sample genomic sharing framework text for the demo. |
examples/DEMO.md |
Documents how to run the demo. |
README.md |
Adds a “Code Quality” section describing the tooling. |
ENV_SETUP.md |
Adds environment variable setup guide and .env usage notes. |
CODE_QUALITY.md |
Adds code-quality tooling guide (Black/Ruff/isort/mypy/pre-commit). |
.pre-commit-config.yaml |
Adds pre-commit hooks for formatting, linting, typing, and basic hygiene checks. |
.gitignore |
Ignores venv/caches and .env. |
.github/workflows/tests.yml |
Adds a multi-Python-version test workflow with coverage upload. |
.github/workflows/lint.yml |
Adds a pre-commit-based lint workflow. |
.github/workflows/format.yml |
Adds an auto-fix workflow that commits formatting/lint fixes back to the PR branch. |
.github/workflows/README.md |
Documents the included GitHub Actions workflows. |
.env.example |
Provides a template for required environment variables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,110 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
The file starts with a UTF-8 BOM (the invisible character before the shebang). This can break the shebang on Unix-like systems (it won’t be recognized as an executable script). Please remove the BOM so the first bytes are exactly "#!/usr/bin/env python3".
| #!/usr/bin/env python3 | |
| #!/usr/bin/env python3 |
| @@ -0,0 +1,52 @@ | |||
| name: Tests | |||
There was a problem hiding this comment.
Line 1 contains a UTF-8 BOM (invisible character before name:). BOMs have caused YAML parsing issues in some tooling; removing it avoids flaky workflow loading.
| name: Tests | |
| name: Tests |
| ### Black | ||
| **Purpose:** Automatic code formatter | ||
| - Enforces consistent code style | ||
| - Line length: 100 characters | ||
| - Run: \lack src/\ | ||
|
|
||
| ### Ruff | ||
| **Purpose:** Fast Python linter | ||
| - Checks PEP 8 compliance | ||
| - Catches common errors | ||
| - Fixes issues automatically | ||
| - Run: \uff check --fix src/\ | ||
|
|
There was a problem hiding this comment.
The command examples contain control characters (backspace / carriage return), causing tool names like black/ruff to render incorrectly (e.g., \b lack, \r uff). Please remove these control characters and format commands with backticks or fenced code blocks so the instructions are accurate.
| with open(f) as file: | ||
| content = file.read() | ||
| lines = len(content.split("\n")) |
There was a problem hiding this comment.
Files are opened without specifying an encoding. On Windows (or non-UTF-8 locales) this can raise decode errors. Prefer encoding="utf-8" (and optionally newline="") when reading the sample text files.
| @@ -0,0 +1,16 @@ | |||
| GA4GH CONSENT POLICY - SAMPLE EXCERPT (POL 002 v2.0) | |||
There was a problem hiding this comment.
This sample text file starts with a UTF-8 BOM (invisible character before the first letter). If these files are later embedded/parsed, the BOM becomes part of the text and can affect chunking/search. Consider saving the file as UTF-8 without BOM.
| GA4GH CONSENT POLICY - SAMPLE EXCERPT (POL 002 v2.0) | |
| GA4GH CONSENT POLICY - SAMPLE EXCERPT (POL 002 v2.0) |
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: '⚠️ Linting failed. Please run \pre-commit run --all-files\ locally and push fixes.' |
There was a problem hiding this comment.
The PR comment body contains backslashes around the command (\pre-commit run --all-files\), which will render as literal backslashes. Use Markdown inline code formatting (backticks) so the command is copy/pastable and renders correctly.
| body: '⚠️ Linting failed. Please run \pre-commit run --all-files\ locally and push fixes.' | |
| body: '⚠️ Linting failed. Please run `pre-commit run --all-files` locally and push fixes.' |
| @@ -0,0 +1,55 @@ | |||
| name: Auto-format and Fix Issues | |||
There was a problem hiding this comment.
Line 1 contains a UTF-8 BOM (invisible character before name:). Removing it avoids potential YAML parsing issues in GitHub Actions and local tooling.
| name: Auto-format and Fix Issues | |
| name: Auto-format and Fix Issues |
|
|
||
|
|
There was a problem hiding this comment.
The fenced code block opened at line 27 isn’t closed until the end of the file, so the entire Roadmap renders as code. Close the ```bash block right after the last command (after pre-commit run --all-files) and keep the Roadmap as normal Markdown text.
| @@ -0,0 +1,47 @@ | |||
| # Pre-commit hooks configuration | |||
There was a problem hiding this comment.
This file begins with a UTF-8 BOM (invisible character before #). BOMs aren’t needed in UTF-8 and can show up as odd characters in some renderers/tools; please remove it.
| # Pre-commit hooks configuration | |
| # Pre-commit hooks configuration |
| @@ -0,0 +1,17 @@ | |||
| FRAMEWORK FOR RESPONSIBLE SHARING OF GENOMIC DATA - SAMPLE EXCERPT | |||
There was a problem hiding this comment.
This sample text file starts with a UTF-8 BOM (invisible character before the first letter). Removing the BOM keeps the sample content clean for any text processing/embedding.
| FRAMEWORK FOR RESPONSIBLE SHARING OF GENOMIC DATA - SAMPLE EXCERPT | |
| FRAMEWORK FOR RESPONSIBLE SHARING OF GENOMIC DATA - SAMPLE EXCERPT |
Added type hints to src/main.py to improve IDE support and static analysis.
Changes:
This helps with mypy checks and better developer experience.
Closes #31