From 5b3e8c01a86e640964c0d9684b083805d59782c7 Mon Sep 17 00:00:00 2001 From: mumo-dev Date: Sat, 19 Apr 2025 07:36:08 +0300 Subject: [PATCH 1/9] add python distribution build workflow --- .github/workflows/pypackage_build.yml | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/pypackage_build.yml diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml new file mode 100644 index 00000000..3f6ea14c --- /dev/null +++ b/.github/workflows/pypackage_build.yml @@ -0,0 +1,80 @@ +name: Build and publish python package + +on: + push: + tags: + - "*" + +# Define permissions needed for the workflow GITHUB_TOKEN +permissions: + contents: read # Allow checkout + packages: write # Allow publishing to GitHub Packages + + +jobs: + build: + name: Build Python Package + runs-on: ubuntu-20.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Hatch + run: pip install hatch + + - name: Build distributions + run: hatch build # Uses pyproject.toml to build sdist and wheel into dist/ + + - name: Upload distributions artifact + uses: actions/upload-artifact@v4 # Action to save artifacts between jobs + with: + name: como-distribution-package # Name for the artifact + path: dist/ # Path to the directory to upload + + publish: + name: Publish to GitHub Packages + runs-on: ubuntu-latest + needs: build # Depends on the build job succeeding + # IMPORTANT: Only run the publish job when a tag starting with 'v' is pushed + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + + + permissions: # Explicit permissions needed for this job + packages: write # Required to write to GitHub Packages registry + contents: read # Needed if accessing repo content (e.g., for download artifact) + + steps: + - name: Download distributions artifact + uses: actions/download-artifact@v4 # Action to retrieve artifacts from previous job. + with: + name: como-distribution-package + path: dist/ + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Twine + run: pip install twine + + - name: Publish package to GitHub Packages + env: + # Use __token__ as username and the automatically generated GITHUB_TOKEN as password + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + run: | + echo "Uploading to GitHub Packages for repository: ${{ github.repository }}" + # Construct the repository URL dynamically using the repository owner + TWINE_REPOSITORY_URL="https://pypi.pkg.github.com/${{ github.repository_owner }}" + python -m twine upload --verbose --repository-url ${TWINE_REPOSITORY_URL} dist/* + + + From 373a056631f7b94c3feb9e6cf122a62862196d68 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:01:16 -0500 Subject: [PATCH 2/9] feat: added builds for macos and windows Signed-off-by: Josh Loecker --- .github/workflows/pypackage_build.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml index 3f6ea14c..b5d25672 100644 --- a/.github/workflows/pypackage_build.yml +++ b/.github/workflows/pypackage_build.yml @@ -1,4 +1,4 @@ -name: Build and publish python package +name: Build and publish python package on: push: @@ -13,8 +13,14 @@ permissions: jobs: build: - name: Build Python Package - runs-on: ubuntu-20.04 + strategy: + matrix: + operating-system: [macos-latest, ubuntu-latest, windows-latest] + python-version: [ 3.10, 3.11, 3.12, 3.13 ] + + name: Build Python Package (${{ matrix.operating-system }}, Python ${{ matrix.python-version }}) + runs-on: ${{ matrix.operating-system }} + steps: - name: Checkout Code uses: actions/checkout@v4 @@ -35,10 +41,15 @@ jobs: - name: Upload distributions artifact uses: actions/upload-artifact@v4 # Action to save artifacts between jobs with: - name: como-distribution-package # Name for the artifact + name: como-distribution-package-${{ matrix.operating-system }}-${{ matrix.python-version }} # Name for the artifact path: dist/ # Path to the directory to upload publish: + strategy: + matrix: + python-version: [ 3.10, 3.11, 3.12, 3.13 ] + operating-system: [macos-latest, windows-latest, ubuntu-latest] + name: Publish to GitHub Packages runs-on: ubuntu-latest needs: build # Depends on the build job succeeding @@ -54,8 +65,8 @@ jobs: - name: Download distributions artifact uses: actions/download-artifact@v4 # Action to retrieve artifacts from previous job. with: - name: como-distribution-package - path: dist/ + name: como-distribution-package-${{ matrix.operating-system }}-${{ matrix.python-version }} + path: dist/ - name: Set up Python 3.11 uses: actions/setup-python@v5 From 46b020f84ea9145753d9452c6945fd1e1cc3ecc6 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:01:59 -0500 Subject: [PATCH 3/9] feat: set name of job based on OS & Python version Signed-off-by: Josh Loecker --- .github/workflows/pypackage_build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml index b5d25672..3570f7de 100644 --- a/.github/workflows/pypackage_build.yml +++ b/.github/workflows/pypackage_build.yml @@ -23,14 +23,14 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v4 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} - - name: Set up Python 3.11 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: ${{ matrix.python-version }} - name: Install Hatch run: pip install hatch @@ -53,6 +53,7 @@ jobs: name: Publish to GitHub Packages runs-on: ubuntu-latest needs: build # Depends on the build job succeeding + # IMPORTANT: Only run the publish job when a tag starting with 'v' is pushed if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') @@ -71,7 +72,7 @@ jobs: - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: ${{ matrix.python-version }} - name: Install Twine run: pip install twine From fb28848eda422eb90f8d8cda9218fdad7691b050 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:04:29 -0500 Subject: [PATCH 4/9] chore: bump scanpy version Signed-off-by: Josh Loecker --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 155641be..a328bb4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ "loguru>=0.7.2", "pandas>=1.3.5", "plotly>=5.24.1", - "scanpy>=1.9.8", + "scanpy>=1.11.1", "scipy>=1.7.3", "scikit-learn>=1.5.2", "setuptools<60.0", @@ -49,4 +49,4 @@ packages = ["main/como"] allow-direct-references = true [tool.pytest.ini_options] -pythonpath = [ "main/src" ] \ No newline at end of file +pythonpath = [ "main/src" ] From a8283483d547d8fc6e7988e8914bf674dc8af2b1 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:11:13 -0500 Subject: [PATCH 5/9] chore: bump statsmodels version Signed-off-by: Josh Loecker --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a328bb4e..3bb1d01b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ dependencies = [ "scipy>=1.7.3", "scikit-learn>=1.5.2", "setuptools<60.0", + "statsmodels>=0.14", "openpyxl>=3.1.5", "aiofiles>=24.1.0", "aioftp>=0.23.1", From ca8e809690d298e652fc78956c0b235672bea2be Mon Sep 17 00:00:00 2001 From: JoshLoecker <47901540+JoshLoecker@users.noreply.github.com> Date: Wed, 30 Apr 2025 17:12:24 +0000 Subject: [PATCH 6/9] style: format code, Jupyter Notebook(s), and Python imports with `ruff` --- main/como/create_context_specific_model.py | 4 ++-- main/como/rnaseq.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/main/como/create_context_specific_model.py b/main/como/create_context_specific_model.py index c072404c..4e483985 100644 --- a/main/como/create_context_specific_model.py +++ b/main/como/create_context_specific_model.py @@ -172,7 +172,7 @@ def _gene_rule_logical(gpr_expression: str, level: int = 0) -> str: inner_string = inner_string.replace("[", "") inner_string = inner_string.replace("]", "") - expression_out = f"{gpr_expression[:loc_l]}{inner_string}{gpr_expression[loc_r + 1:]}" + expression_out = f"{gpr_expression[:loc_l]}{inner_string}{gpr_expression[loc_r + 1 :]}" expression_out = _gene_rule_logical(expression_out, level + 1) return expression_out @@ -384,7 +384,7 @@ def _map_expression_to_reaction( continue for gid in gene_ids: if gid in gene_expressions.index: - rep_val = f' {gene_expressions.at[gid, "active"]} ' + rep_val = f" {gene_expressions.at[gid, 'active']} " else: rep_val = f" {unknown_val!s} " gene_reaction_rule = f" {gene_reaction_rule} " # pad white space to prevent gene matches inside floats diff --git a/main/como/rnaseq.py b/main/como/rnaseq.py index 8afa9779..45fc669b 100644 --- a/main/como/rnaseq.py +++ b/main/como/rnaseq.py @@ -418,8 +418,7 @@ def zfpkm_transform( cores = multiprocessing.cpu_count() - 2 logger.debug(f"Processing {total:,} samples through zFPKM transform using {cores} cores") logger.debug( - f"Will update every {update_per_step:,} steps as this is approximately " - f"{update_every_percent:.1%} of {total:,}" + f"Will update every {update_per_step:,} steps as this is approximately {update_every_percent:.1%} of {total:,}" ) with Pool(processes=cores) as pool: From 7985e19248fa05eda6bf17985a234443a4546ada Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:24:51 -0500 Subject: [PATCH 7/9] fix: quote python versions Signed-off-by: Josh Loecker --- .github/workflows/pypackage_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml index 3570f7de..9b541c69 100644 --- a/.github/workflows/pypackage_build.yml +++ b/.github/workflows/pypackage_build.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: operating-system: [macos-latest, ubuntu-latest, windows-latest] - python-version: [ 3.10, 3.11, 3.12, 3.13 ] + python-version: [ "3.10", "3.11", '3.12', "3.13" ] name: Build Python Package (${{ matrix.operating-system }}, Python ${{ matrix.python-version }}) runs-on: ${{ matrix.operating-system }} From e5a6b81ca890c7599b0bed22cfc7972061b8ed07 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:25:26 -0500 Subject: [PATCH 8/9] chore: use double quotes Signed-off-by: Josh Loecker --- .github/workflows/pypackage_build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml index 9b541c69..fcf1a00c 100644 --- a/.github/workflows/pypackage_build.yml +++ b/.github/workflows/pypackage_build.yml @@ -15,8 +15,8 @@ jobs: build: strategy: matrix: - operating-system: [macos-latest, ubuntu-latest, windows-latest] - python-version: [ "3.10", "3.11", '3.12', "3.13" ] + operating-system: [ macos-latest, ubuntu-latest, windows-latest ] + python-version: [ "3.10", "3.11", "3.12", "3.13" ] name: Build Python Package (${{ matrix.operating-system }}, Python ${{ matrix.python-version }}) runs-on: ${{ matrix.operating-system }} @@ -48,7 +48,7 @@ jobs: strategy: matrix: python-version: [ 3.10, 3.11, 3.12, 3.13 ] - operating-system: [macos-latest, windows-latest, ubuntu-latest] + operating-system: [ macos-latest, windows-latest, ubuntu-latest ] name: Publish to GitHub Packages runs-on: ubuntu-latest From 9e40b3114465a88bf447281d9695a0914101e4f0 Mon Sep 17 00:00:00 2001 From: Josh Loecker Date: Wed, 30 Apr 2025 12:33:03 -0500 Subject: [PATCH 9/9] fix: forgot double quotes for publishing matrix Signed-off-by: Josh Loecker --- .github/workflows/pypackage_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pypackage_build.yml b/.github/workflows/pypackage_build.yml index fcf1a00c..07b7873c 100644 --- a/.github/workflows/pypackage_build.yml +++ b/.github/workflows/pypackage_build.yml @@ -47,7 +47,7 @@ jobs: publish: strategy: matrix: - python-version: [ 3.10, 3.11, 3.12, 3.13 ] + python-version: [ "3.10", "3.11", "3.12", "3.13" ] operating-system: [ macos-latest, windows-latest, ubuntu-latest ] name: Publish to GitHub Packages