Repository: chanzuckerberg/cellxgene-ontology-guide (language: python)

Issue:
feat(API): Setup python API package
# Need: 
This package will be released to pypi and will contain the API for accessing the Ontology Data Release. 

# DOD:

- [x] - Create pyproject.toml
- [x] - Setup release tools
- [x] - Setup release process
- [x] - GHA to release to pypi with major, minor, or patch options. Manually triggered
- [x] - Document release process in readme
- [ ] - Setup slack alert if release errors. <- skiping for MVP

# Note:
- https://realpython.com/pypi-publish-python-package/ 
feat(API): Setup testing
# DOD
- Instructions to run locally in readme
- GHA to run on push
- Could be a simple hello world test initially.



Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index e69de29b..47afac9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,1 @@
+/api/python/src/cellxgene_ontology_guide/_version.py
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f96d6bb0..6436fbf5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -34,4 +34,4 @@ repos:
       - id: mypy
         args: [--strict, --ignore-missing-imports]
         additional_dependencies: [types-PyYAML]
-        files: ^(api/python|tools/ontology-builder/src)/
+        files: ^(api/python/src|tools/ontology-builder/src)/
diff --git a/api/python/cellxgene-ontology/src/__init__.py b/api/__init__.py
similarity index 100%
rename from api/python/cellxgene-ontology/src/__init__.py
rename to api/__init__.py
diff --git a/api/python/Makefile b/api/python/Makefile
new file mode 100644
index 00000000..74c381aa
--- /dev/null
+++ b/api/python/Makefile
@@ -0,0 +1,11 @@
+install:
+	pip install -e .
+
+install-dev:
+	pip install -e .[test]
+
+clean:
+	rm -rf ./build ./src/cellxgene_ontology_guide.egg-info
+
+unit-tests:
+	python -m pytest tests
diff --git a/api/python/README.md b/api/python/README.md
new file mode 100644
index 00000000..942350c6
--- /dev/null
+++ b/api/python/README.md
@@ -0,0 +1,14 @@
+# Python API
+
+# Install
+
+```bash
+make install
+```
+
+# Run Unit Tests
+
+```bash
+make install-dev
+make unit-tests
+```
diff --git a/api/python/cellxgene-ontology/tests/__init__.py b/api/python/__init__.py
similarity index 100%
rename from api/python/cellxgene-ontology/tests/__init__.py
rename to api/python/__init__.py
diff --git a/api/python/cellxgene-ontology/pyproject.toml b/api/python/cellxgene-ontology/pyproject.toml
deleted file mode 100644
index 1a9338a1..00000000
--- a/api/python/cellxgene-ontology/pyproject.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[build-system]
-requires = ["setuptools>=69", "setuptools-scm>=8"]
-build-backend = "setuptools.build_meta"
-
-[project]
-name = "cellxgene-ontology"
-dynamic = ["version"]
-description = "Access ontology data used by CZ cellxgene"
-authors = [
-    { name = "Chan Zuckerberg Initiative Foundation", email = "cellxgene@chanzuckerberg.com" }
-]
-license = { text = "MIT" }
-readme = "README.md"
-requires-python = "~= 3.11"
diff --git a/api/python/pyproject.toml b/api/python/pyproject.toml
new file mode 100644
index 00000000..1788e498
--- /dev/null
+++ b/api/python/pyproject.toml
@@ -0,0 +1,35 @@
+[build-system]
+requires = ["setuptools>=69", "setuptools-scm>=8"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "cellxgene_ontology_guide"
+dynamic = ["version"]
+description = "Access ontology data used by CZ cellxgene"
+authors = [
+    { name = "Chan Zuckerberg Initiative Foundation", email = "cellxgene@chanzuckerberg.com" }
+]
+license = { text = "MIT" }
+readme = "README.md"
+requires-python = "~= 3.11"
+dependencies = [
+    "owlready2"
+]
+
+[project.optional-dependencies]
+test = ["pytest"]
+
+[tool.setuptools.packages.find]
+where = ["src"]
+include = ["cellxgene_ontology_guide"]
+
+[tool.pytest.ini_options]
+pythonpath = ["src/cellxgene_ontology_guide"]
+
+[tool.setuptools_scm]
+version_file = "src/cellxgene_ontology_guide/_version.py"
+version_scheme = "python-simplified-semver"
+root = "../.."
+relative_to = "__file__"
+#TODO: setup the github tag for the pypi releases so setuptools-SCM can identify it using a python regex
+#tag_regex="^python-api-(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$')"
diff --git a/api/python/src/cellxgene_ontology_guide/__init__.py b/api/python/src/cellxgene_ontology_guide/__init__.py
new file mode 100644
index 00000000..ad2ffa4a
--- /dev/null
+++ b/api/python/src/cellxgene_ontology_guide/__init__.py
@@ -0,0 +1,3 @@
+import _version
+
+__version__ = _version.__version__
diff --git a/tools/ontology-builder/src/ontology-references/all_ontology.json.gz b/tools/ontology-builder/src/ontology-references/all_ontology.json.gz
index 3529481d..d60a47f7 100644
Binary files a/tools/ontology-builder/src/ontology-references/all_ontology.json.gz and b/tools/ontology-builder/src/ontology-references/all_ontology.json.gz differ


Test patch:
diff --git a/.github/workflows/push-tests.yml b/.github/workflows/push-tests.yml
index 2fe6396d..ffb00c7f 100644
--- a/.github/workflows/push-tests.yml
+++ b/.github/workflows/push-tests.yml
@@ -48,6 +48,33 @@ jobs:
         run: |
           pip install -r tools/ontology-builder/requirements.txt
           pip install -r tools/ontology-builder/requirements-dev.txt
-      - name: Ontology Dry Run Unit Tests
+      - name: Ontology builder unit tests
         run: |
           cd tools/ontology-builder && make unit-tests
+
+  unit-test-python-api:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+        with:
+          ref: ${{ github.event.pull_request.head.ref }}
+      - name: Set up Python
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.11
+      - name: Python cache
+        uses: actions/cache@v1
+        with:
+          path: ~/.cache/pip
+          key: ${{ runner.os }}-pip-${{ hashFiles('**/api/python/pyproject.toml') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+      - name: Install dependencies
+        run: |
+          cd api/python
+          make install-dev
+      - name: Python API unit tests
+        run: |
+          cd api/python
+          make unit-tests
diff --git a/api/python/cellxgene-ontology/README.md b/api/python/tests/__init__.py
similarity index 100%
rename from api/python/cellxgene-ontology/README.md
rename to api/python/tests/__init__.py
diff --git a/api/python/tests/test_version.py b/api/python/tests/test_version.py
new file mode 100644
index 00000000..c8cd9e05
--- /dev/null
+++ b/api/python/tests/test_version.py
@@ -0,0 +1,5 @@
+import cellxgene_ontology_guide
+
+
+def test_version():
+    assert cellxgene_ontology_guide.__version__