From 941ecb1b13eb5a77105b2f12707b600bf9d7f2ea Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Mon, 17 Feb 2025 19:32:25 +0000 Subject: [PATCH] Initial commit, copied from autoBIGS.engine-bioconda --- .devcontainer/Dockerfile | 16 ++++++++++ .devcontainer/devcontainer.json | 24 ++++++++++++++ .devcontainer/noop.txt | 3 ++ .vscode/launch.json | 19 +++++++++++ Jenkinsfile | 53 +++++++++++++++++++++++++++++++ autobigs-cli/meta.yaml | 50 +++++++++++++++++++++++++++++ autobigs-engine/meta.yaml | 44 +++++++++++++++++++++++++ environment.yml | 10 ++++++ scripts/adapt_names.py | 32 +++++++++++++++++++ scripts/package_latest_version.py | 30 +++++++++++++++++ 10 files changed, 281 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/noop.txt create mode 100644 .vscode/launch.json create mode 100644 Jenkinsfile create mode 100644 autobigs-cli/meta.yaml create mode 100644 autobigs-engine/meta.yaml create mode 100644 environment.yml create mode 100644 scripts/adapt_names.py create mode 100644 scripts/package_latest_version.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..808f11b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/devcontainers/miniconda:1-3 + +# Copy environment.yml (if found) to a temp location so we update the environment. Also +# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists. +COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/ +RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \ + && rm -rf /tmp/conda-tmp + +# [Optional] Uncomment to install a different version of Python than the default +# RUN conda install -y python=3.6 \ +# && pip install --no-cache-dir pipx \ +# && pipx reinstall-all + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..43d26c5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,24 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda +{ + "name": "Miniconda (Python 3)", + "build": { + "context": "..", + "dockerfile": "Dockerfile" + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "python --version", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/noop.txt b/.devcontainer/noop.txt new file mode 100644 index 0000000..abee195 --- /dev/null +++ b/.devcontainer/noop.txt @@ -0,0 +1,3 @@ +This file is copied into the container along with environment.yml* from the +parent folder. This is done to prevent the Dockerfile COPY instruction from +failing if no environment.yml is found. \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5045d5b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python Debugger: Current File with Arguments", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": [ + "${command:pickArgs}" + ] + } + ] +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..295bd87 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,53 @@ +pipeline { + agent { + kubernetes { + cloud 'rsys-devel' + defaultContainer 'miniforge3' + inheritFrom 'miniforge' + } + } + stages { + stage("prepare") { + parallel { + stage("recipes repo") { + steps { + sh 'git clone https://github.com/Syph-and-VPD-Lab/bioconda-recipes.git' + dir('bioconda-recipes') { + sh 'git pull' + sh 'git pull origin update-autobigs-cli' + sh 'git checkout update-autobigs-cli' + } + } + } + stage("conda") { + steps { + sh 'conda env update -n base --file environment.yml' + } + } + } + } + stage("generate recipe") { + steps { + sh 'grayskull pypi autobigs.cli --maintainers "Harrison Deng"' + sh 'python scripts/adapt_names.py autobigs.cli' + } + } + stage("build") { + steps { + sh 'conda build autobigs-cli' + } + } + stage("commit") { + environment { + TOKEN = credentials('github.com') + } + steps { + dir('bioconda-recipes') { + sh 'cp -r ../autobigs-cli/* recipes/autobigs-cli/.' + sh 'git commit -a -m "Automatically updated autobigs-cli bioconda recipe to $(python ../scripts/package_latest_version.py autoBIGS.cli)."' + sh 'git push https://${TOKEN}@github.com/Syph-and-VPD-Lab/bioconda-recipes.git update-autobigs-cli' + } + } + } + } +} \ No newline at end of file diff --git a/autobigs-cli/meta.yaml b/autobigs-cli/meta.yaml new file mode 100644 index 0000000..3271e92 --- /dev/null +++ b/autobigs-cli/meta.yaml @@ -0,0 +1,50 @@ +{% set name = "autoBIGS.cli" %} +{% set version = "0.4.2" %} + +package: + name: {{ name|lower|replace(".", "-") }} + version: {{ version }} + +source: + url: https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/autobigs_cli-{{ version }}.tar.gz + sha256: fc7bf6c604974796f5c8aae52fd9ab9924f5490f4f207a26be803217aae30c82 + +build: + entry_points: + - autoBIGS = autobigs.cli.program:run + noarch: python + script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation + number: 0 + run_exports: + - {{ pin_subpackage( name|lower|replace(".", "-"), max_pin="x.x") }} + +requirements: + host: + - python >=3.12 + - setuptools >=64 + - setuptools-scm >=8 + - pip + run: + - python >=3.12 + - autobigs-engine + +test: + imports: + - autobigs + commands: + - pip check + - autoBIGS --help + - autoBIGS info -h + - autoBIGS st -h + requires: + - pip + +about: + home: https://github.com/RealYHD/autoBIGS.cli + summary: A CLI tool to rapidly fetch fetch MLST profiles given sequences for various diseases. + license: GPL-3.0-or-later + license_file: LICENSE + +extra: + recipe-maintainers: + - Harrison Deng diff --git a/autobigs-engine/meta.yaml b/autobigs-engine/meta.yaml new file mode 100644 index 0000000..75457f3 --- /dev/null +++ b/autobigs-engine/meta.yaml @@ -0,0 +1,44 @@ +{% set name = "autobigs.engine" %} +{% set version = "0.11.0" %} + +package: + name: {{ name|lower|replace(".", "-") }} + version: {{ version }} + +source: + url: https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/autobigs_engine-{{ version }}.tar.gz + sha256: d479b0bce5fcf2c3eb2e666b780b55d0c8a2c03293c9200db9eeac74e869f47b + +build: + noarch: python + script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation + number: 0 + +requirements: + host: + - python >=3.12 + - setuptools >=64 + - setuptools-scm >=8 + - pip + run: + - python >=3.12 + - biopython ==1.85 + - aiohttp ==3.11.* + +test: + imports: + - autobigs + commands: + - pip check + requires: + - pip + +about: + summary: A library to rapidly fetch fetch MLST profiles given sequences for various diseases. + dev_url: https://github.com/RealYHD/autoBIGS.engine + license: GPL-3.0 + license_file: LICENSE + +extra: + recipe-maintainers: + - RealYHD diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..a055fbd --- /dev/null +++ b/environment.yml @@ -0,0 +1,10 @@ +name: base +channels: + - conda-forge + - bioconda +dependencies: + - conda-build + - grayskull + - bioconda-utils + - python=3.10 + - git \ No newline at end of file diff --git a/scripts/adapt_names.py b/scripts/adapt_names.py new file mode 100644 index 0000000..5d1d91c --- /dev/null +++ b/scripts/adapt_names.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import argparse +from os import fdopen, path +import os +import re +import shutil +from sys import argv +import tempfile + +def update_naming_scheme(recipe_path): + original_recipe = path.abspath(recipe_path) + original_meta = path.join(original_recipe, "meta.yaml") + new_fd, new_file_path = tempfile.mkstemp() + with fdopen(new_fd, "w") as new_file_handle: + with open(original_meta, "r") as original_file_handle: + for line in original_file_handle: + matches = re.finditer(r"\{\{\s*name\|lower()\s+\}\}", line) + modified_line = line + for match in matches: + modified_line = modified_line[:match.start(1)] + r'|replace(".", "-")' + modified_line[match.end(1):] + new_file_handle.write(modified_line) + shutil.move(new_file_path, original_meta) + new_recipe_name = path.join( + path.dirname(original_recipe), + path.basename(original_recipe).replace(".", "-").lower()) + shutil.rmtree(new_recipe_name, ignore_errors=True) + os.replace(original_recipe, + new_recipe_name) + +if __name__ == "__main__": + update_naming_scheme(argv[1]) \ No newline at end of file diff --git a/scripts/package_latest_version.py b/scripts/package_latest_version.py new file mode 100644 index 0000000..550dcaa --- /dev/null +++ b/scripts/package_latest_version.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import sys +import requests +import json +try: + from packaging.version import parse +except ImportError: + from pip._vendor.packaging.version import parse + + +URL_PATTERN = 'https://pypi.python.org/pypi/{package}/json' + + +def get_version(package, url_pattern=URL_PATTERN): + """Return version of package on pypi.python.org using json.""" + req = requests.get(url_pattern.format(package=package)) + version = parse('0') + if req.status_code == requests.codes.ok: + j = json.loads(req.text.encode(req.encoding or "utf-8")) + releases = j.get('releases', []) + for release in releases: + ver = parse(release) + if not ver.is_prerelease: + version = max(version, ver) + return version + + +if __name__ == '__main__': + print(get_version(sys.argv[1]), end="") \ No newline at end of file