diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1511cd5..eb1bf8e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -6,19 +6,11 @@ name: Check on: push: - branches: [ master, dev ] - paths-ignore: - - '**/RELEASE*' - - '**/README*' - - '**/LICENSE*' - - 'recipe' - - 'docs' - - '.gitignore' - - '.github' - - '!.github/workflows/check*' - - '**/_version.py' + branches: [ main, master, dev ] + paths: + - '**.py' pull_request: - branches: [ master ] + branches: [ main, master ] jobs: @@ -39,4 +31,5 @@ jobs: - name: Checking package run: | cd ci - make check-inconda + make check-buildenv env=check + conda run -n check make check diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 59fec6e..875899f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,44 +2,119 @@ name: Publish on: push: - tags: releases/[1-9]+.[0-9]+.[0-9]+ - branches: [ stable ] + branches: + - stable + paths: + - '**.py' + - '!tests/**' jobs: - Publish: + Conda-Build_Test: runs-on: ubuntu-latest - - env: - ANACONDA_TOKEN: ${{secrets.ANACONDA_TOKEN}} - ANACONDA_USER: ${{secrets.ANACONDA_USER}} - steps: - uses: actions/checkout@v2 - - uses: docker://continuumio/miniconda3 - - - name: Updating conda - run: conda update --all -y - - name: Installing make - run: conda install -y make - - - name: Building package + run: | + sudo apt-get update + sudo apt-get -y install make + - name: Build conda package run: | cd ci make conda-build - - - name: Testing package + - name: Test conda package run: | cd ci make conda-test - - name: Converting to other platforms - run: | - cd ci - make conda-convert + Tag: + needs: [Conda-Build_Test] + runs-on: ubuntu-latest + outputs: # Create variable usable from another job + new_tag: ${{ steps.tag_version.outputs.new_tag }} + steps: + ## CREATE TAG/RELEASE + - uses: actions/checkout@v2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v5.6 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + release_branches: stable + tag_prefix: + - name: Create Release + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + release_name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ## UPDATE CHANGELOG + - uses: actions/checkout@v2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - uses: actions/setup-ruby@v1 + # with: + # ruby-version: '2.6' # Version range or exact version of a Ruby version to use, using semvers version range syntax. + - name: Generate CHANGELOG + env: + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gem install github_changelog_generator + github_changelog_generator -u brsynth -p rrparser --no-unreleased + - name: Update _version.py + env: + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ steps.tag_version.outputs.new_tag }} + run: | + folder=`dirname $(find . -name _version.py)` + echo "__version__ = \"$TAG\"" > $folder/_version.py + - name: Commit files + run: | + git config --local user.email "$GITHUB_EMAIL" + git config --local user.name "$GITHUB_USERNAME" + git commit -m "doc(CHANGELOG): update" -a + env: + GITHUB_USERNAME: brsynth + GITHUB_EMAIL: joan.herisson@univ-evry.fr + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} - - name: Uploading to anaconda - run: | - cd ci - make conda-publish + ## UPDATE CONDA-FORGE FEEDSTOCK + Feedstock: + needs: [Tag] + runs-on: ubuntu-latest + steps: + - name: Checkout feedstock fork + uses: actions/checkout@v2 + with: + repository: conda-forge/rrparser-feedstock + persist-credentials: false + fetch-depth: 0 + - name: Update recipe + run: | + wget -O- https://github.com/brsynth/rrparser/archive/refs/tags/$VERSION.tar.gz | shasum -a 256 > sha.txt + sha=`python -c "f = open('sha.txt'); print(f.read().split()[0]); f.close()"` + rm -f sha.txt + sed -i -E "s/(\{% set version = \")[^>]+(\" %\})/\1$VERSION\2/" recipe/meta.yaml + sed -i -E "s/(sha256: )[^>]+/\1$sha/" recipe/meta.yaml + git config --local user.email "$GITHUB_EMAIL" + git config --local user.name "$GITHUB_USERNAME" + git commit -m "chore(meta.yml): update version" -a + env: + GITHUB_USERNAME: brsynth + GITHUB_EMAIL: joan.herisson@univ-evry.fr + VERSION: ${{ needs.tag.outputs.new_tag }} + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.FEEDSTOCK }} + push-to-fork: brsynth/rrparser-feedstock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5dbe728..fb91fd4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,19 +6,11 @@ name: Test on: push: - branches: [ master, dev ] - paths-ignore: - - '**/RELEASE*' - - '**/README*' - - '**/LICENSE*' - - 'recipe' - - 'docs' - - '.gitignore' - - '.github' - - '!.github/workflows/test*' - - '**/_version.py' + branches: [ main, master, dev ] + paths: + - '**.py' pull_request: - branches: [ master ] + branches: [ main, master ] jobs: @@ -39,4 +31,5 @@ jobs: - name: Testing package run: | cd ci - make test-inconda + make test-buildenv env=test + conda run -n test make test diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..12124e4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +## [2.4.1] \ No newline at end of file diff --git a/README.md b/README.md index 14aaa68..b1e07af 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ -# RRParser +# rrparser +Reaction Rules Parser +| Name | Downloads | Version | Platforms | +| --- | --- | --- | --- | +| [![Conda Recipe](https://img.shields.io/badge/recipe-rrparser-green.svg)](https://anaconda.org/conda-forge/rrparser) | [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/rrparser.svg)](https://anaconda.org/conda-forge/rrparser) | [![Conda Version](https://img.shields.io/conda/vn/conda-forge/rrparser.svg)](https://anaconda.org/conda-forge/rrparser) | [![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/rrparser.svg)](https://anaconda.org/conda-forge/rrparser) | -[![Anaconda-Server Badge](https://anaconda.org/brsynth/rrparser/badges/latest_release_date.svg)](https://anaconda.org/brsynth/rrparser) ![Test](https://github.com/brsynth/RRulesParser/workflows/Test/badge.svg) [![Anaconda-Server Badge](https://anaconda.org/brsynth/rrparser/badges/version.svg)](https://anaconda.org/brsynth/rrparser) - -Reaction Rules Parser. If no input reaction files is provided, retrieves the reaction rules from [RetroRules](https://retrorules.org). +## Description +*Reaction Rules Parser*. If no input reaction files is provided, retrieves the reaction rules from [RetroRules](https://retrorules.org). ## Input @@ -17,7 +20,7 @@ Reaction Rules Parser. If no input reaction files is provided, retrieves the rea ## Install ### From Conda ```sh -[sudo] conda install -c brsynth rrparser +[sudo] conda install -c conda-forge rrparser ``` ## Use @@ -26,12 +29,14 @@ Reaction Rules Parser. If no input reaction files is provided, retrieves the rea ```python from rrparser import parse_rules -outfile = parse_rules(, - , - input_format=<'csv' | 'tsv'>, - rule_type=<'all' | 'retro' | 'forward'>, - diameters=<'2,4,6,8,10,12,14,16'>, - output_format=<'csv' | 'tsv'>) +outfile = parse_rules( + , + , + input_format=<'csv' | 'tsv'>, + rule_type=<'all' | 'retro' | 'forward'>, + diameters=<'2,4,6,8,10,12,14,16'>, + output_format=<'csv' | 'tsv'> +) ``` If parameters from CLI have to be parsed, the function `build_args_parser` is available: @@ -59,8 +64,7 @@ Test can be run with the following commands: ### Natively ```bash -cd tests -pytest -v +python -m pytest -v ``` # CI/CD diff --git a/ci/.env b/ci/.ci_env similarity index 100% rename from ci/.env rename to ci/.ci_env diff --git a/ci/LICENSE b/ci/LICENSE index 9894a3c..259197b 100644 --- a/ci/LICENSE +++ b/ci/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Jean-Loup Faulon's group & INRA +Copyright (c) 2020 Jean-Loup Faulon's group & INRAE Copyright (c) 2020 University of Evry / Paris-Saclay Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/ci/Makefile b/ci/Makefile index 804b56b..04d55aa 100644 --- a/ci/Makefile +++ b/ci/Makefile @@ -1,8 +1,9 @@ SHELL := /bin/bash SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +PACKAGE = $(shell python ../setup.py --name) + +include $(SELF_DIR)/.ci_env -include $(SELF_DIR)/.env -include $(SELF_DIR)/../extras/.env # HELP # This will output the help for each task @@ -34,14 +35,20 @@ check: ## Test code with 'pytest', this is the fastest way to test the code test: ## Test code with 'pytest', this is the fastest way to test the code @$(MAKE_CMD) -f test.mk test args="$(args)" -%-inconda: ## Test conda package +%-buildenv: ## Test conda package ifneq ($(strip $(env)),) $(eval env=${PACKAGE}_$*) endif - @$(MAKE_CMD) -f conda.mk check-environment-$* env=$(env) - @$(MAKE_CMD) -f conda.mk conda-run-env env=$(env) \ - cmd="make -C .. $*" \ - args="$(args)" + @$(MAKE_CMD) -f conda.mk build-environment-$* env=$(env) + +# %-inconda: ## Test conda package +# ifneq ($(strip $(env)),) +# $(eval env=${PACKAGE}_$*) +# endif +# @$(MAKE_CMD) -f conda.mk check-environment-$* env=$(env) +# @$(MAKE_CMD) -f conda.mk conda-run-env env=$(env) \ +# cmd="make -C .. $*" \ +# args="$(args)" conda-all: conda-build conda-test conda-convert conda-publish ## (default) Perform all conda process (build, test, convert, publish) @@ -64,3 +71,6 @@ conda-check-recipe: ## Check conda recipe conda-create-run_env: ## Make an conda environment to run program @$(MAKE_CMD) -f conda.mk check-environment-test env=${PACKAGE}_test + +doc-pdoc: + cd .. ; rm -rf chemlite/__pycache__ ; pdoc --force --html -o docs chemlite \ No newline at end of file diff --git a/ci/makefiles/conda.mk b/ci/makefiles/conda.mk index 2363524..a247abd 100644 --- a/ci/makefiles/conda.mk +++ b/ci/makefiles/conda.mk @@ -1,12 +1,21 @@ -include ../../extras/.env -include ../.env +include ../.ci_env SHELL := /bin/bash - -tmpfile := $(shell mktemp -u) -tmpdir := $(shell dirname $(tmpfile)) - +PACKAGE = $(shell python ../../setup.py --name) PLATFORM = $(shell conda info | grep platform | awk '{print $$3}') +recipe := ../recipe +meta := meta.yaml + +build-recipe: + echo "{% set name = \"${PACKAGE}\" %}" > $(recipe)/$(meta) + cat $(recipe)/_meta1.yaml >> $(recipe)/$(meta) + sed -ne '/^dependencies:$$/{:a' -e 'n;p;ba' -e '}' ../../environment.yaml | awk '{print " - "$$2}' >> $(recipe)/$(meta) + cat $(recipe)/_meta2.yaml >> $(recipe)/$(meta) + $(MAKE_CMD) -f test.mk test-deps >> $(recipe)/$(meta) + cat $(recipe)/_meta3.yaml >> $(recipe)/$(meta) + echo " - `$(MAKE_CMD) -f test.mk test-cmd`" >> $(recipe)/$(meta) + cat $(recipe)/_meta4.yaml >> $(recipe)/$(meta) + awk '/channels/,/dependencies/{if(/dependencies|channels/) next; print}' ../../environment.yaml | awk '{print $$2}' > $(recipe)/conda_channels.txt # HELP # This will output the help for each task @@ -25,14 +34,15 @@ help-advanced: ## Advanced help. ARGS = $(filter-out $@,$(MAKECMDGOALS)) CONDA_BUILD_ARGS = --quiet --numpy 1.11 MAKE_CMD = $(MAKE) -s --no-print-directory -ECHO = echo -n ">>>" +ECHO = echo ">>>" clean: conda-clean-build #python_versions = $(shell cat ../recipe/conda_build_config.yaml | awk 'NR>1 {print $$2}') -recipe_channels = $(shell cat ../../recipe/conda_channels.txt) +recipe_channels = $(shell cat $(recipe)/conda_channels.txt) conda_channels = $(shell conda config --show channels | awk '{print $2}') + define check $(1) && echo OK endef @@ -59,7 +69,7 @@ endif ### check recipe conda-recipe-check: @$(ECHO) "Checking the recipe... " - @conda build --check $(CONDA_BUILD_ARGS) ../../recipe > /dev/null \ + @conda build --check $(CONDA_BUILD_ARGS) $(recipe) > /dev/null \ && echo OK ### clean build products conda-clean-build: @@ -80,9 +90,9 @@ endif ## CONDA BUILD ### build only -conda-build-only: check-environment-build +conda-build-only: check-environment-build build-recipe @$(ECHO) "Building conda package... " - @conda run --name ${PACKAGE}_build conda build --no-test $(CONDA_BUILD_ARGS) $(VARIANTS) --output-folder ${CONDA_BLD_PATH} ../../recipe > /dev/null \ + @conda run --name ${PACKAGE}_build conda build --no-test $(CONDA_BUILD_ARGS) $(VARIANTS) --output-folder ${CONDA_BLD_PATH} $(recipe) > /dev/null \ && echo OK conda-test-only: check-environment-build conda-add-channels @@ -94,7 +104,7 @@ conda-test-only: check-environment-build conda-add-channels conda-build: conda-build-test conda-build: check-environment-build conda-add-channels @$(ECHO) "Building and Testing conda package... " - @conda run --name ${PACKAGE}_build conda build $(CONDA_BUILD_ARGS) $(VARIANTS) --output-folder ${CONDA_BLD_PATH} ../../recipe > /dev/null \ + @conda run --name ${PACKAGE}_build conda build $(CONDA_BUILD_ARGS) $(VARIANTS) --output-folder ${CONDA_BLD_PATH} $(recipe) > /dev/null \ && echo OK conda-convert: check-conda @@ -150,7 +160,7 @@ else endif check-conda-build: ifeq (False,$(HAS_CONDA_BUILD)) - echo conda env -n $(PACKAGE)_build create -f ../../recipe/conda_build_env.yaml + echo conda env -n $(PACKAGE)_build create -f $(recipe)/conda_build_env.yaml endif ## Check anaconda-client @@ -164,35 +174,24 @@ ifeq (False,$(HAS_ANACONDA_CLIENT)) @$(MAKE_CMD) -f conda.mk conda-install-anaconda-client channel=conda-forge endif -ifeq (,$(shell conda list | grep pyyaml)) - HAS_PYYAML=False -else - HAS_PYYAML=True -endif -## Check pyyaml -check-pyyaml: -ifeq (False,$(HAS_PYYAML)) - @$(MAKE_CMD) -f conda.mk conda-install-pyyaml channel=conda-forge -endif -build_env_file := ../../recipe/conda_build_env.yaml +build_env_file := $(recipe)/conda_build_env.yaml check_env_file := ../test/check-environment.yml -test_env_file := $(tmpdir)/$(shell mktemp -u XXXXXX-${PACKAGE}_test_env.yml) -build_env_file: - @ -check_env_file: - @ -test_env_file: check-pyyaml - @python3 ../$(TEST_PATH)/parse_recipe.py req > $(test_env_file) -check-environment-%: check-conda %_env_file +test_env_file := ../../environment.yaml + + +check-environment-%: check-conda build-environment-% + @$(ECHO) OK + +build-environment-%: check-conda ifneq ("$(wildcard $(MY_ENV_DIR))","") # check if the directory is there - @$(ECHO) "'$(env)' environment already exists.\n" + @$(ECHO) "'$(env)' environment already exists." else - @$(ECHO) "Creating '$(env)' environment... " - @conda env create -n $(env) -f $($(*)_env_file) > /dev/null - @echo OK + @$(ECHO) "Creating '$(env)' environment... " + @conda env create -n $(env) -f $($(*)_env_file) > /dev/null + @conda run --name $(env) conda install `make -f test.mk test-deps | awk {'print $$2'} | tr '\n' ' '` > /dev/null + @echo OK endif - @rm -f $(test_env_file) conda-run-env: ifneq ($(strip $(cmd)),) diff --git a/ci/makefiles/test.mk b/ci/makefiles/test.mk index c57dd83..b99c7d1 100644 --- a/ci/makefiles/test.mk +++ b/ci/makefiles/test.mk @@ -1,5 +1,4 @@ -include ../../extras/.env -include ../.env +include ../.ci_env SHELL := /bin/bash @@ -13,9 +12,28 @@ help: .DEFAULT_GOAL := all -MAKE_CMD = $(MAKE) -s --no-print-directory -ECHO = echo -n ">>>" +MAKE_CMD = $(MAKE) -f test.mk -s --no-print-directory +ECHO = echo ">>>" +PACKAGE = $(shell python ../../setup.py --name) + +ifeq ($(args),) + test_src := tests +else + test_src = $(args) +endif +test_cmd := python -m pytest -v --cov --cov-report term-missing +define test_deps + - pytest + - pytest-cov + - pytest-mock +endef +export test_deps + +test-cmd: + @echo $(test_cmd) +test-deps: + @echo "$$test_deps" all: check test ## Run check and test code @@ -26,25 +44,22 @@ bandit: ## Run bandit over code # -lll to only catch the higher level security issues @bandit -r -lll ../../${PACKAGE} flake: ## Run flake over code and tests - @echo "=== FLAKE REPORT ===" + echo "=== FLAKE REPORT ===" # stop the build if there are Python syntax errors or undefined names - @flake8 ../../${PACKAGE} --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 ../../${PACKAGE} --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - @flake8 ../../${PACKAGE} --count --ignore=E272,E501,E266,E241,E226,E251,E303,E221 --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 ../../${PACKAGE} --count --ignore=E272,E501,E266,E241,E226,E251,E303,E221 --exit-zero --max-complexity=10 --max-line-length=127 --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - @flake8 ../../tests --count --ignore=E272,E501,E266,E241,E226,E251,E303,E221,E122,E211,E302 --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 ../../$(test_src) --count --ignore=E272,E501,E266,E241,E226,E251,E303,E221,E122,E211,E302 --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# TEST -$(eval test_cmd := $(shell python3 ../test/parse_recipe.py test cmd)) -ifeq ($(args),) - test_src = $(shell python3 ../test/parse_recipe.py test src) -else - test_src = $(args) -endif +# TEST test: ## Test code with 'pytest' - @$(ECHO) "Testing...\n" @export PYTHONPATH=$$PWD/../.. ; \ cd ../.. ; \ - $(test_cmd) -p no:cacheprovider $(test_src) \ - && echo OK + $(test_cmd) -p no:cacheprovider $(test_src) ; \ + res_test=$$? ; \ + if [ $$res_test -eq 0 ] || [ $$res_test -eq 5 ] ; then \ + exit 0 ; \ + fi + diff --git a/ci/recipe/.gitignore b/ci/recipe/.gitignore new file mode 100644 index 0000000..472c7ed --- /dev/null +++ b/ci/recipe/.gitignore @@ -0,0 +1,3 @@ +meta.yml +conda_channels.txt +meta.yaml \ No newline at end of file diff --git a/ci/recipe/_meta1.yaml b/ci/recipe/_meta1.yaml new file mode 100644 index 0000000..4aba52a --- /dev/null +++ b/ci/recipe/_meta1.yaml @@ -0,0 +1,18 @@ +{% set data = load_setup_py_data() %} + +package: + name: {{ name|lower }} + version: {{ data['version'] }} + +source: + path: ../.. + +build: + number: 0 + script: {{ PYTHON }} -m pip install --no-deps --ignore-installed -vv . + +requirements: + host: + - python {{ python }} + run: + - python {{ python }} diff --git a/ci/recipe/_meta2.yaml b/ci/recipe/_meta2.yaml new file mode 100644 index 0000000..ed1c736 --- /dev/null +++ b/ci/recipe/_meta2.yaml @@ -0,0 +1,7 @@ + +test: + source_files: + - tests + imports: + - {{ name|lower }} + requires: diff --git a/ci/recipe/_meta3.yaml b/ci/recipe/_meta3.yaml new file mode 100644 index 0000000..8646caa --- /dev/null +++ b/ci/recipe/_meta3.yaml @@ -0,0 +1,2 @@ + commands: + - python -m {{ name|lower }} --help diff --git a/ci/recipe/_meta4.yaml b/ci/recipe/_meta4.yaml new file mode 100644 index 0000000..dcc65a1 --- /dev/null +++ b/ci/recipe/_meta4.yaml @@ -0,0 +1,12 @@ + +about: + home: https://github.com/brsynth/{{ name|lower }} + summary: {{ data['description'] }} + license: {{ data.get('license') }} + license_file: LICENSE + +extra: + recipe-maintainers: + # GitHub IDs for maintainers of the recipe. + # Always check with the people listed below if they are OK becoming maintainers of the recipe. (There will be spam!) + - breakthewall diff --git a/recipe/conda_build_config.yaml b/ci/recipe/conda_build_config.yaml similarity index 80% rename from recipe/conda_build_config.yaml rename to ci/recipe/conda_build_config.yaml index 43e465c..293f77e 100644 --- a/recipe/conda_build_config.yaml +++ b/ci/recipe/conda_build_config.yaml @@ -1,5 +1,4 @@ python: - - 3.6 - 3.7 - 3.8 - 3.9 diff --git a/recipe/conda_build_env.yaml b/ci/recipe/conda_build_env.yaml similarity index 90% rename from recipe/conda_build_env.yaml rename to ci/recipe/conda_build_env.yaml index 91e3173..135c3b3 100644 --- a/recipe/conda_build_env.yaml +++ b/ci/recipe/conda_build_env.yaml @@ -5,4 +5,4 @@ channels: dependencies: - python < 3.9 # TD: anaconda upload has troubles with python 3.9 (base64.encodestring alias removed) - conda-build - - anaconda-client +# - anaconda-client diff --git a/ci/test/parse_recipe.py b/ci/test/parse_recipe.py deleted file mode 100644 index 85c5fc7..0000000 --- a/ci/test/parse_recipe.py +++ /dev/null @@ -1,79 +0,0 @@ -from yaml import safe_load as yaml_safe_load -from yaml import YAMLError -from os import path as os_path -from shutil import copyfile -from tempfile import NamedTemporaryFile -from sys import argv as sys_argv - -current_folder = os_path.dirname(os_path.realpath(__file__)) - -# input files -channels_file = current_folder+'/../../recipe/conda_channels.txt' -recipe_file = current_folder+'/../../recipe/meta.yaml' -bld_cfg_file = current_folder+'/../../recipe/conda_build_config.yaml' - -def parse_meta(filename): - - recipe = '' - with open(filename, 'r') as f: - line = f.readline() - while line: - # filter all non-YAML elements - if not line.startswith('{%') and '{{' not in line: - recipe += line - line = f.readline() - - requirements = [] - tests = {} - try: - try: requirements += yaml_safe_load(recipe)['requirements']['host'] - except TypeError: pass - try: requirements += yaml_safe_load(recipe)['requirements']['run'] - except TypeError: pass - try: requirements += yaml_safe_load(recipe)['test']['requires'] - except TypeError: pass - tests['commands'] = yaml_safe_load(recipe)['test']['commands'] - tests['source_files'] = yaml_safe_load(recipe)['test']['source_files'] - except YAMLError as exc: - print(exc) - - return requirements, tests - - - - -if __name__ == '__main__': - - requirements, tests = parse_meta(recipe_file) - - if any(arg in sys_argv for arg in ['test']): - if len(sys_argv) < 3: - args = 'commands sources' - else: - args = sys_argv - if any(arg in args for arg in ['commands', 'cmd']): - print(' && '.join(tests['commands']), end=' ') - if any(arg in args for arg in ['sources', 'src']): - print(' '.join(['../'+e for e in tests['source_files']])) - else: - print() - - if any(arg in sys_argv for arg in ['requirements', 'req']): - print('channels:') - print('\n'.join([' - '+c for c in open(channels_file, 'r').read().split()])) - print('dependencies:') - print('\n'.join([' - '+c for c in requirements])) - print(' - pyyaml') - exit() - - print(' '.join(['-c '+c for c in open(channels_file, 'r').read().split()])) - if len(sys_argv) < 3: - args = 'channels packages' - else: - args = sys_argv - if any(arg in args for arg in ['channels']): - print(' '.join(['-c '+c for c in open(channels_file, 'r').read().split()]), end=' ') - if any(arg in args for arg in ['packages', 'pkg']): - print(' '.join(requirements)) - else: - print() diff --git a/ci/workflows/github/check.yml b/ci/workflows/github/check.yml deleted file mode 100644 index 7170665..0000000 --- a/ci/workflows/github/check.yml +++ /dev/null @@ -1,41 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Check - -on: - - push: - branches: [ main, master, dev ] - paths-ignore: - - '**/RELEASE*' - - '**/README*' - - '**/LICENSE*' - - 'recipe' - - 'docs' - - '.gitignore' - - '.github' - - '!.github/workflows/check*' - pull_request: - branches: [ master ] - -jobs: - - Check: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: docker://continuumio/miniconda3 - - - name: Updating conda - run: conda update --all -y - - - name: Installing make - run: conda install -y make - - - name: Checking package - run: | - cd ci - make check-inconda diff --git a/ci/workflows/github/publish.yml b/ci/workflows/github/publish.yml deleted file mode 100644 index 59fec6e..0000000 --- a/ci/workflows/github/publish.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Publish - -on: - push: - tags: releases/[1-9]+.[0-9]+.[0-9]+ - branches: [ stable ] - -jobs: - - Publish: - runs-on: ubuntu-latest - - env: - ANACONDA_TOKEN: ${{secrets.ANACONDA_TOKEN}} - ANACONDA_USER: ${{secrets.ANACONDA_USER}} - - steps: - - uses: actions/checkout@v2 - - uses: docker://continuumio/miniconda3 - - - name: Updating conda - run: conda update --all -y - - - name: Installing make - run: conda install -y make - - - name: Building package - run: | - cd ci - make conda-build - - - name: Testing package - run: | - cd ci - make conda-test - - - name: Converting to other platforms - run: | - cd ci - make conda-convert - - - name: Uploading to anaconda - run: | - cd ci - make conda-publish diff --git a/ci/workflows/github/test.yml b/ci/workflows/github/test.yml deleted file mode 100644 index f4287d3..0000000 --- a/ci/workflows/github/test.yml +++ /dev/null @@ -1,41 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Test - -on: - - push: - branches: [ main, master, dev ] - paths-ignore: - - '**/RELEASE*' - - '**/README*' - - '**/LICENSE*' - - 'recipe' - - 'docs' - - '.gitignore' - - '.github' - - '!.github/workflows/test*' - pull_request: - branches: [ master ] - -jobs: - - Test: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: docker://continuumio/miniconda3 - - - name: Updating conda - run: conda update --all -y - - - name: Installing make - run: conda install -y make - - - name: Testing package - run: | - cd ci - make test-inconda diff --git a/environment.yaml b/environment.yaml new file mode 100644 index 0000000..68c48be --- /dev/null +++ b/environment.yaml @@ -0,0 +1,8 @@ +name: rrparser-dev +channels: + - conda-forge +dependencies: + - python + - brs_utils + - pandas + - colorlog diff --git a/extras/.env b/extras/.env deleted file mode 100644 index 112894d..0000000 --- a/extras/.env +++ /dev/null @@ -1,6 +0,0 @@ -PACKAGE=rrparser -URL=https://github.com/brsynth/RRulesParser -AUTHORS='Thomas Duigou, Melchior du Lac, Joan Hérisson' -CORR_AUTHOR=joan.herisson@univ-evry.fr -DESCR='Reaction Rules Parser' -HOMEDIR=/home diff --git a/recipe/conda_channels.txt b/recipe/conda_channels.txt deleted file mode 100644 index 80eb489..0000000 --- a/recipe/conda_channels.txt +++ /dev/null @@ -1,2 +0,0 @@ -brsynth -conda-forge diff --git a/recipe/meta.yaml b/recipe/meta.yaml deleted file mode 100644 index c2d7a67..0000000 --- a/recipe/meta.yaml +++ /dev/null @@ -1,46 +0,0 @@ -{% set name = "rrparser" %} -{% set data = load_setup_py_data() %} - -package: - name: {{ name|lower }} - version: {{ data['version'] }} - -source: - path: .. - -build: - number: 0 - script: {{ PYTHON }} -m pip install --no-deps --ignore-installed -vv . - -requirements: - host: - - python {{ python }} - run: - - python {{ python }} - - pandas - - brs_utils - - colorlog - -test: - source_files: - - tests - imports: - - {{ name|lower }} - requires: - - pytest - commands: - - python -m {{ name|lower }} --help - - cd tests - - python -m pytest -v - -about: - home: https://github.com/brsynth/{{ name|lower }} - summary: {{ data['description'] }} - license: {{ data.get('license') }} - license_file: LICENSE - -extra: - recipe-maintainers: - # GitHub IDs for maintainers of the recipe. - # Always check with the people listed below if they are OK becoming maintainers of the recipe. (There will be spam!) - - breakthewall diff --git a/setup.py b/setup.py index 1b9373d..2e7aa65 100644 --- a/setup.py +++ b/setup.py @@ -1,58 +1,60 @@ from setuptools import setup -from os import path as os_path -from re import search as re_search +from os import path as os_path -_readme = 'README.md' -with open(_readme, 'r', encoding='utf-8') as f: - long_description = f.read() - -_extras_path = 'extras' -with open(_extras_path+'/.env', 'r', encoding='utf-8') as f: - for line in f: - if line.startswith('PACKAGE='): - _package = line.splitlines()[0].split('=')[1].lower() - if line.startswith('URL='): - _url = line.splitlines()[0].split('=')[1].lower() - if line.startswith('AUTHORS='): - _authors = line.splitlines()[0].split('=')[1].lower() - if line.startswith('DESCR='): - _descr = line.splitlines()[0].split('=')[1].lower() - if line.startswith('CORR_AUTHOR='): - _corr_author = line.splitlines()[0].split('=')[1].lower() +## INFOS ## +package = 'rrparser' +descr = 'Reaction Rules Parser' +url = 'https://github.com/brsynth/rrparser' +authors = 'Joan Hérisson, Melchior du Lac, Thomas Duigou' +corr_author = 'joan.herisson@univ-evry.fr' -_release = 'RELEASE' -_version = os_path.join( - _package, - '_version.py' -) -# with open(_release, 'r') as f: -# _version = f.readline().split()[0] -with open(_version, 'r') as f: - m = re_search('"(.+)"', f.readline().split('=')[1]) - if m: - version = m.group(1) +## LONG DESCRIPTION +with open( + os_path.join( + os_path.dirname(os_path.realpath(__file__)), + 'README.md' + ), + 'r', + encoding='utf-8' +) as f: + long_description = f.read() +def get_version(): + with open( + os_path.join( + os_path.dirname(os_path.realpath(__file__)), + 'CHANGELOG.md' + ), + 'r' + ) as f: + lines = f.readlines() + for line in lines: + if line.startswith('##'): + from re import search + m = search("\[(.+)\]", line) + if m: + return m.group(1) setup( - name = _package, - version = version, - author = _authors, - author_email = _corr_author, - description = _descr, + name = package, + version = get_version(), + author = authors, + author_email = corr_author, + description = descr, long_description = long_description, long_description_content_type = 'text/markdown', - url = _url, - packages = [_package], - package_dir = {_package: _package}, + url = url, + packages = [package], + package_dir = {package: package}, include_package_data = True, - # install_requires = required, test_suite = 'pytest', license = 'MIT', - classifiers=[ + classifiers = [ 'Programming Language :: Python :: 3', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', ], - python_requires = '>=3.5', + python_requires = '>=3.7', ) +