Skip to content

Commit

Permalink
feat: add packaging functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lpm0073 committed Nov 27, 2023
1 parent dfecfeb commit bb6856c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
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)

0 comments on commit bb6856c

Please sign in to comment.