Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup automated semantic releases and python packaging #3

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/tests/python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ runs:
- name: Install dependencies
shell: bash
run: |
cp -R ./api/terraform/python/layer_genai/openai_utils ${{ env.SITE_PACKAGES_PATH }}
pip install -r ./requirements.txt
env:
SITE_PACKAGES_PATH: ${{ env.SITE_PACKAGES_PATH }}
Expand Down
16 changes: 14 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
labels:
- "dependencies"
- "python"
Expand All @@ -18,7 +18,19 @@ updates:
- "dependencies"
- "automated pr"
schedule:
interval: "daily"
interval: "weekly"
assignees:
- "lpm0073"
reviewers:
- "lpm0073"
- package-ecosystem: "npm"
directory: "/"
labels:
- "dependencies"
- "javascript"
- "automated pr"
schedule:
interval: "weekly"
assignees:
- "lpm0073"
reviewers:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semanticVersionBump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
env:
VERSION_FILE: __version__.py
PACKAGE_PATH: ${{ github.workspace }}/api/terraform/python/layer_genai/openai_utils/
PACKAGE_PATH: ${{ github.workspace }}/grader/

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ all: help
analyze:
cloc . --exclude-ext=svg,json,zip --vcs=git
init:
npm install && \
python3.11 -m venv venv && \
source venv/bin/activate && \
pip install --upgrade pip && \
Expand Down
2 changes: 2 additions & 0 deletions grader/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "0.0.0"
18 changes: 18 additions & 0 deletions grader/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""Setup for automated_grader package."""
from setup_utils import get_semantic_version # pylint: disable=import-error
from setuptools import find_packages, setup


setup(
name="automated_grader",
version=get_semantic_version(),
description="Automated grader for Canvas environments",
author="Lawrence McDaniel",
author_email="[email protected]",
packages=find_packages(),
package_data={
"automated_grader": ["*.md", "data/*"],
},
install_requires=[],
)
18 changes: 18 additions & 0 deletions grader/setup_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""Test setup.py."""
import subprocess
import unittest


class TestSetup(unittest.TestCase):
"""Test setup.py."""

def test_setup_syntax(self):
"""Test setup.py syntax."""
result = subprocess.run(["python", "setup.py", "check"], capture_output=True, text=True, check=False)
assert result.returncode == 0, f"setup.py failed with output:\n{result.stdout}\n{result.stderr}"
assert not result.stderr, "Expected no error output"


if __name__ == "__main__":
unittest.main()
49 changes: 49 additions & 0 deletions grader/setup_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# pylint: disable=duplicate-code
# pylint: disable=duplicate-code
"""Lawrence McDaniel https://lawrencemcdaniel.com."""
import importlib.util
import os
import re
from typing import Dict


HERE = os.path.abspath(os.path.dirname(__file__))

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))


def load_version() -> Dict[str, str]:
"""Stringify the __version__ module."""
version_file_path = os.path.join(HERE, "__version__.py")
spec = importlib.util.spec_from_file_location("__version__", version_file_path)
version_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(version_module)
return version_module.__dict__


VERSION = load_version()


def get_semantic_version() -> str:
"""
Return the semantic version number.

Example valid values of __version__.py are:
0.1.17
0.1.17-next.1
0.1.17-next.2
0.1.17-next.123456
0.1.17-next-major.1
0.1.17-next-major.2
0.1.17-next-major.123456

Note:
- pypi does not allow semantic version numbers to contain a dash.
- pypi does not allow semantic version numbers to contain a 'v' prefix.
- pypi does not allow semantic version numbers to contain a 'next' suffix.
"""
version = VERSION["__version__"]
version = re.sub(r"-next\.\d+", "", version)
return re.sub(r"-next-major\.\d+", "", version)
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.3",
"@semantic-release/release-notes-generator": "^12.1.0",
"typescript": "^5.2.2"
}
}
Loading