diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 273eef7a..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,116 +0,0 @@ -# Python CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-python/ for more details - -# Environment variables required: -# - PYPI_USER / PYPI_PASSWORD: for publishing package to PyPi - -version: 2 - -common: &common - working_directory: ~/python-seed - steps: - # Get Code from github - - checkout - - # Install deps - - run: - name: install dependencies - command: pip install tox codecov pre-commit --user - - # Run tests using TOX - - run: - name: run tox - command: ~/.local/bin/tox - - # Run pre-commit (only for python-3.7) - - run: - name: run pre-commit - command: | - if [[ "$CIRCLE_JOB" == "python-3.7" ]]; then - ~/.local/bin/pre-commit run --all-files - fi - - # Upload code coverage (only if env have UPLOAD_COVERAGE=1) - - run: - name: upload coverage report - command: | - if [[ "$UPLOAD_COVERAGE" == 1 ]]; then - ~/.local/bin/coverage xml - ~/.local/bin/codecov - fi - when: always - - -jobs: - "python-3.6": - <<: *common - docker: - - image: circleci/python:3.6.5 - environment: - - TOXENV=py36 - - "python-3.7": - <<: *common - docker: - - image: circleci/python:3.7.2 - environment: - - TOXENV=py37 - - UPLOAD_COVERAGE=1 - - "python-3.8": - <<: *common - docker: - - image: circleci/python:3.8.4 - environment: - - TOXENV=py38 - - deploy: - docker: - - image: circleci/python:3.7.2 - environment: - - TOXENV=release - working_directory: ~/python-seed - steps: - - checkout - - # We Only deploy to PyPi if github tag match the python version - - run: - name: verify git tag vs. version - command: | - VERSION=$(python setup.py --version) - if [ "$VERSION" = "$CIRCLE_TAG" ]; then exit 0; else exit 3; fi - - - run: - name: init .pypirc - command: | - echo -e "[pypi]" >> ~/.pypirc - echo -e "username = $PYPI_USER" >> ~/.pypirc - echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc - - - run: - name: install dependencies - command: pip install tox --user - - - run: - name: run tox - command: ~/.local/bin/tox - -workflows: - version: 2 - build_and_deploy: - jobs: - - "python-3.6" - - "python-3.7": - filters: # required since `deploy` has tag filters AND requires `build` - tags: - only: /.*/ - - "python-3.8" - - deploy: - requires: - - "python-3.7" - filters: - tags: - only: /^[0-9]+.*/ - branches: - ignore: /.*/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..6e9aae1c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,74 @@ +name: CI + +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox codecov pre-commit + + # Run tox using the version of Python in `PATH` + - name: Run Tox + run: tox -e py + + # Run pre-commit (only for python-3.7) + - name: run pre-commit + if: matrix.python-version == 3.7 + run: pre-commit run --all-files + + - name: Upload Results + if: success() + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + flags: unittests + name: ${{ matrix.platform }}-${{ matrix.tox-env }} + fail_ci_if_error: false + + publish: + needs: [tests] + runs-on: ubuntu-latest + if: contains(github.ref, 'tags') + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox + + - name: Set tag version + id: tag + # https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + + - name: Set module version + id: module + # https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + run: echo ::set-output name=version::$(python setup.py --version) + + - name: Build and publish + if: steps.tag.outputs.tag == steps.module.outputs.version + env: + TOXENV: release + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: tox diff --git a/MANIFEST.in b/MANIFEST.in index c7aa7370..e28fe9f9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ -include python_seed/template/* -include python_seed/template/pyseed/* -include python_seed/template/tests/* \ No newline at end of file +include python_seed/template/ci/* +include python_seed/template/cov/* +include python_seed/template/module/pyseed/* +include python_seed/template/module/tests/* +include python_seed/template/module/* diff --git a/README.md b/README.md index 8a655d37..2e0fca24 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Starter kit for creating a new python package.

- - Test + + Test Coverage @@ -64,18 +64,38 @@ Usage: pyseed create [OPTIONS] NAME Create new python seed skeleton. Options: - --help Show this message and exit. + --ci [circleci|github] Add CI configuration + --help Show this message and exit. ``` Create a new python project ```bash -# Create a project +# Create a project without CI $ pyseed create awesomepythonproject # List files created $ ls -1 awesomepythonproject -.circleci/ +.pre-commit-config.yaml +README.md +awesomepythonproject/ +requirements-dev.txt +requirements.txt +setup.py +tests/ +tox.ini +``` + +With CI framework + +```bash +# Create a project github actions +$ pyseed create awesomepythonproject --ci github + +# List files created +$ ls -1 awesomepythonproject +.github/workflows/ci.yml +codecov.yml .pre-commit-config.yaml README.md awesomepythonproject/ @@ -90,14 +110,15 @@ tox.ini ``` my-project/ - ├── .circleci/ - CircleCI configuration. + ├── .circleci/ or .github/ - CI configuration. + ├── codecov.yml - codecov configuration (only if CI is added). ├── .pre-commit-config.yaml - pre-commit configuration. ├── README.md - project readme. ├── my_project/ - core python module. ├── tests/ - tests suite placeholder for your module. ├── requirements.txt - python requirements (!!! by default requirements are written in setup.py) ├── requirements-dev.txt - python dev requirements (!!! by default requirements are written in setup.py) - ├──tox.ini - TOX configuration. + └──tox.ini - TOX configuration. ``` diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..c61977e2 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +comment: off + +coverage: + status: + project: + default: + target: auto + threshold: 5 diff --git a/python_seed/scripts/cli.py b/python_seed/scripts/cli.py index 0e67953e..8869dc26 100644 --- a/python_seed/scripts/cli.py +++ b/python_seed/scripts/cli.py @@ -4,6 +4,7 @@ import shutil import click +import pkg_resources from .. import version @@ -17,12 +18,26 @@ def pyseed(): @pyseed.command(short_help="Create new python seed skeleton") @click.argument("name", type=str, nargs=1) -def create(name): +@click.option( + "--ci", type=click.Choice(["circleci", "github"]), help="Add CI configuration" +) +def create(name, ci): """Create new python seed skeleton.""" - template_dir = os.path.join(os.path.dirname(__file__), "../template") + template_dir = pkg_resources.resource_filename("python_seed", "template/module") shutil.copytree(template_dir, name) + if ci: + template_dir = pkg_resources.resource_filename( + "python_seed", f"template/ci/.{ci}" + ) + shutil.copytree(template_dir, f"{name}/.{ci}") + + covconfig = pkg_resources.resource_filename( + "python_seed", "template/cov/codecov.yml" + ) + shutil.copy2(covconfig, f"{name}/codecov.yml") + new_dir = name name = name.replace("-", "_") for root, _, files in os.walk(new_dir): diff --git a/python_seed/template/.circleci/config.yml b/python_seed/template/ci/.circleci/config.yml similarity index 100% rename from python_seed/template/.circleci/config.yml rename to python_seed/template/ci/.circleci/config.yml diff --git a/python_seed/template/ci/.github/workflows/ci.yml b/python_seed/template/ci/.github/workflows/ci.yml new file mode 100644 index 00000000..dabc8dff --- /dev/null +++ b/python_seed/template/ci/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: CI + +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox codecov pre-commit + + # Run tox using the version of Python in `PATH` + - name: Run Tox + run: tox -e py + + # Run pre-commit (only for python-3.7) + - name: run pre-commit + if: matrix.python-version == 3.7 + run: pre-commit run --all-files + + - name: Upload Results + if: success() + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + flags: unittests + name: ${{ matrix.platform }}-${{ matrix.tox-env }} + fail_ci_if_error: false + + + publish: + needs: [tests] + runs-on: ubuntu-latest + if: contains(github.ref, 'tags') + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox + + - name: Set tag version + id: tag + # https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + + - name: Set module version + id: module + # https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + run: echo ::set-output name=version::$(python setup.py --version) + + - name: Build and publish + if: steps.tag.outputs.tag == steps.module.outputs.version + env: + TOXENV: release + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: tox diff --git a/python_seed/template/cov/codecov.yml b/python_seed/template/cov/codecov.yml new file mode 100644 index 00000000..c61977e2 --- /dev/null +++ b/python_seed/template/cov/codecov.yml @@ -0,0 +1,8 @@ +comment: off + +coverage: + status: + project: + default: + target: auto + threshold: 5 diff --git a/python_seed/template/.pre-commit-config.yaml b/python_seed/template/module/.pre-commit-config.yaml similarity index 100% rename from python_seed/template/.pre-commit-config.yaml rename to python_seed/template/module/.pre-commit-config.yaml diff --git a/python_seed/template/README.md b/python_seed/template/module/README.md similarity index 100% rename from python_seed/template/README.md rename to python_seed/template/module/README.md diff --git a/python_seed/template/pyseed/__init__.py b/python_seed/template/module/pyseed/__init__.py similarity index 100% rename from python_seed/template/pyseed/__init__.py rename to python_seed/template/module/pyseed/__init__.py diff --git a/python_seed/template/pyseed/app.py b/python_seed/template/module/pyseed/app.py similarity index 100% rename from python_seed/template/pyseed/app.py rename to python_seed/template/module/pyseed/app.py diff --git a/python_seed/template/pyseed/scripts/__init__.py b/python_seed/template/module/pyseed/scripts/__init__.py similarity index 100% rename from python_seed/template/pyseed/scripts/__init__.py rename to python_seed/template/module/pyseed/scripts/__init__.py diff --git a/python_seed/template/pyseed/scripts/cli.py b/python_seed/template/module/pyseed/scripts/cli.py similarity index 100% rename from python_seed/template/pyseed/scripts/cli.py rename to python_seed/template/module/pyseed/scripts/cli.py diff --git a/python_seed/template/requirements-dev.txt b/python_seed/template/module/requirements-dev.txt similarity index 62% rename from python_seed/template/requirements-dev.txt rename to python_seed/template/module/requirements-dev.txt index 84bb552b..1f960b0b 100644 --- a/python_seed/template/requirements-dev.txt +++ b/python_seed/template/module/requirements-dev.txt @@ -1,3 +1,3 @@ pytest pytest-cov -pre-commit \ No newline at end of file +pre-commit diff --git a/python_seed/template/module/requirements.txt b/python_seed/template/module/requirements.txt new file mode 100644 index 00000000..dca9a909 --- /dev/null +++ b/python_seed/template/module/requirements.txt @@ -0,0 +1 @@ +click diff --git a/python_seed/template/setup.py b/python_seed/template/module/setup.py similarity index 100% rename from python_seed/template/setup.py rename to python_seed/template/module/setup.py diff --git a/python_seed/template/tests/__init__.py b/python_seed/template/module/tests/__init__.py similarity index 100% rename from python_seed/template/tests/__init__.py rename to python_seed/template/module/tests/__init__.py diff --git a/python_seed/template/tests/test_function.py b/python_seed/template/module/tests/test_function.py similarity index 100% rename from python_seed/template/tests/test_function.py rename to python_seed/template/module/tests/test_function.py diff --git a/python_seed/template/tests/test_mod.py b/python_seed/template/module/tests/test_mod.py similarity index 100% rename from python_seed/template/tests/test_mod.py rename to python_seed/template/module/tests/test_mod.py diff --git a/python_seed/template/tox.ini b/python_seed/template/module/tox.ini similarity index 100% rename from python_seed/template/tox.ini rename to python_seed/template/module/tox.ini diff --git a/python_seed/template/requirements.txt b/python_seed/template/requirements.txt deleted file mode 100644 index b98f6609..00000000 --- a/python_seed/template/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -click \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b98f6609..dca9a909 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -click \ No newline at end of file +click