Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn into a cookiecutter template #2

Merged
merged 54 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
59dc4af
Add project template
jorgepiloto Feb 22, 2022
dba358d
Setup CI pipelines
jorgepiloto Feb 22, 2022
a7ae0e6
Add LICENSE
jorgepiloto Feb 22, 2022
4528431
Collect extra deps in requirements
jorgepiloto Feb 23, 2022
030a082
New tox_poetry.ini and tox_flit.ini
jorgepiloto Feb 23, 2022
c3be512
New pyproject_poetry.toml and pyproject_flit.toml
jorgepiloto Feb 23, 2022
0851dac
Allow selection of build system
jorgepiloto Feb 23, 2022
ac2da44
Setup pre-commit
jorgepiloto Feb 24, 2022
28f3061
DBG: py310
jorgepiloto Feb 25, 2022
a5cec5d
Add dependabot
jorgepiloto Feb 25, 2022
3917e4a
Test baked project GH actions
jorgepiloto Feb 25, 2022
50a5b0d
DBG: actions
jorgepiloto Feb 25, 2022
56c48c8
Update cookiecutter.json
akaszynski Feb 28, 2022
89dc738
DBG: actions
jorgepiloto Mar 1, 2022
fa75273
DBG: windows actions
jorgepiloto Mar 1, 2022
ad0bd34
Test baked project in linux flavors
jorgepiloto Mar 1, 2022
a133ce8
Use act desired platform
jorgepiloto Mar 1, 2022
d7ef1cd
Run act on all jobs
jorgepiloto Mar 1, 2022
3ee8d5b
Force project path
jorgepiloto Mar 1, 2022
b99bde6
Force git clone
jorgepiloto Mar 1, 2022
8e159e2
Remove act cache
jorgepiloto Mar 1, 2022
d1e69ba
Execute as dry run
jorgepiloto Mar 1, 2022
7535ab1
Check var/run
jorgepiloto Mar 1, 2022
47572ca
Dryrun and tox envs
jorgepiloto Mar 1, 2022
31f0fb6
Remove requirements_style.txt
jorgepiloto Mar 1, 2022
138e6df
Test requirements files
jorgepiloto Mar 1, 2022
4fa03f4
Allow setuptools support
jorgepiloto Mar 1, 2022
880cfc5
Fix CI scope and setuptools based project
jorgepiloto Mar 1, 2022
87d7f4a
Working setuptools
jorgepiloto Mar 2, 2022
cbb7fc6
Hooks warning
jorgepiloto Mar 2, 2022
639123b
Run desired tox envs
jorgepiloto Mar 2, 2022
c9b3368
Fix tox_setuptools
jorgepiloto Mar 2, 2022
4c1acab
Remove tox build
jorgepiloto Mar 2, 2022
a8a4208
Fix isolated build env tox
jorgepiloto Mar 2, 2022
0125a13
Clean CI
jorgepiloto Mar 2, 2022
a4bd164
Migrate docs -> doc
jorgepiloto Mar 2, 2022
89ea390
Apply baked project style
jorgepiloto Mar 2, 2022
13b8b3e
Update docs related
jorgepiloto Mar 2, 2022
cf88eaa
Apply docstyle
jorgepiloto Mar 2, 2022
9254b0e
Update authors/maintainers metadata
jorgepiloto Mar 2, 2022
15723f8
Apply black & isort instead of checking
jorgepiloto Mar 2, 2022
b6c7642
Update authors/maintainers metadata
jorgepiloto Mar 2, 2022
6f8551d
Ignore poetry
jorgepiloto Mar 2, 2022
5e0dd5a
Fix pre-commit
jorgepiloto Mar 2, 2022
d0a3894
Add build in requirements_build.txt
jorgepiloto Mar 2, 2022
251b9c1
Line-length pre-commit
jorgepiloto Mar 2, 2022
419c99c
Fix tox
jorgepiloto Mar 2, 2022
c92ea1c
Fix style
jorgepiloto Mar 2, 2022
f5c5312
Fix default version
jorgepiloto Mar 2, 2022
3d67855
Fix tox pre-commit
jorgepiloto Mar 2, 2022
7502ec7
Use pre-hook
jorgepiloto Mar 2, 2022
21ad2a5
Add usage guidelines
jorgepiloto Mar 2, 2022
2a555e2
Fix dependabot.yml location
jorgepiloto Mar 2, 2022
1fcbbe6
Enhance baked README.rst and actions
jorgepiloto Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/requirements"
schedule:
interval: "daily"
113 changes: 113 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: GitHub CI
on:
pull_request:
push:
tags:
- "*"
branches:
- main

jobs:

style:
name: Code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
- name: Test with tox
run: tox -e style


tests:
name: Test baked project
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
build-system: ["flit", "setuptools"]
fail-fast: false

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 ${{ matrix.build-system }} tox tox-gh-actions

# Runs only the tox environment specified in tox.ini [gh-actions]
- name: Test with tox-gh-actions
run: tox

# Baked project actions are tested only for Linux-base OS
- name: Install and configure act for Linux-based OS
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install build-essential gcc
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)"
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile
brew install act
echo "-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest" >> ~/.actrc

- name: Test flit baked project
if: matrix.os == 'ubuntu-latest' && matrix.build-system == 'flit'
run: |
# Change to baked project directory
cd output/test_bake_project_with_build_s0/cookies/bake00/pyproduct-library
# Initialize it as git repository (pre-commit needs it)
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git init && git add . && git commit -m "Init Python package"
# TODO: Only filter out errors from tox command
# act -j tests docs > act_output.log || true > act_output.log; grep -c ERROR act_output.log && cat act_output.log
tox
# Check package builds properly
python -m pip install -r requirements/requirements_build.txt
flit build
python -m twine check dist/*

- name: Test poetry baked project
if: matrix.os == 'ubuntu-latest' && matrix.build-system == 'poetry'
run: |
# Change to baked project directory
cd output/test_bake_project_with_build_s1/cookies/bake00/pyproduct-library
# Initialize it as git repository (pre-commit needs it)
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git init && git add . && git commit -m "Init Python package"
# TODO: Only filter out errors from tox command
# act -j tests docs > act_output.log || true > act_output.log; grep -c ERROR act_output.log && cat act_output.log
tox
# Check package builds properly
poetry run python -m pip install -r requirements/requirements_build.txt
poetry build
poetry run python -m twine check dist/*

- name: Test setuptools baked project
if: matrix.os == 'ubuntu-latest' && matrix.build-system == 'setuptools'
run: |
# Change to baked project directory
cd output/test_bake_project_with_build_s2/cookies/bake00/pyproduct-library
# Initialize it as git repository (pre-commit needs it)
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git init && git add . && git commit -m "Init Python package"
# TODO: Only filter out errors from tox command
# act -j tests docs > act_output.log || true > act_output.log; grep -c ERROR act_output.log && cat act_output.log
tox
# Check package builds properly
python -m pip install -r requirements/requirements_build.txt
python -m build
python -m twine check dist/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ cython_debug/
#.idea/

# End of https://www.toptal.com/developers/gitignore/api/python

# Ignore baked output cookies from debugging
output/
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:

- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
exclude: "^({{cookiecutter.project_name_slug}}/)"
args: ["tests", "hooks"]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [
"--profile", "black",
"--force-sort-within-sections",
"--line-length", "100",
"--section-default", "THIRDPARTY", "hooks", "tests"
]

- repo: https://gitlab.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: ["tests", "hooks"]
exclude: "^({{cookiecutter.project_name_slug}}/)"

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell

- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
additional_dependencies: [toml]
args: ["--match-dir='^(hooks)'"]
exclude: "^({{cookiecutter.project_name_slug}}/)|(tests/)"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 ANSYS, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion README.md

This file was deleted.

68 changes: 68 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
PyAnsys library as cookiecutter template
========================================

This repository holds a `cookiecutter`_ template for
creating a Python library. The process is fully interactive and the rendered
project is compliant with the `PyAnsys Developer's guide`_.


Requirements
------------

Before creating your library, you will need to install `cookiecutter`_ via:

.. code:: bash

python -m pip install cookiecutter


How to use
----------

Once you have installed `cookiecutter`_, you can create a new Python library by
calling this template using:

.. code:: bash

cookiecutter gh:pyansys/pyansys-template

Previous command will ask you to introduce different data regarding your new
Python project. Some of these are already pre-defined but you can always change
their value:

- **product_name**: the name of Ansys product (i.e. Product).
- **product_name_slug**: product sanitized name (i.e. product).
- **library_name**: the name of the product library (i.e. Library).
- **library_name_slug**: library named sanitized (i.e. library).
- **project_name_slug**: the project's directory name (i.e. pyproduct-library).
- **pkg_name**: the name of the Python package/library (i.e. ansys-product-library).
- **version**: the version of the package/library (i.e. 0.1.dev0).
- **short_description**: a short description of the purpose/goal of the project.
- **repository_url**: link to the repository where the source code will be hosted.
- **requires_python**: choose the minimum required Python version among 3.7, 3.8, 3.9 or 3.10.
- **build_system**: choose the build system among flit, poetry or setuptools.
- **max_linelength**: maximum number of characters per line in the source code (i.e. 100).


How to contribute
-----------------

For developers, the requirements can be installed via:

.. code:: bash

python -m pip install -r requirements/requirements_dev.txt

The coding style checks and unit tests are executed via `tox`_. Simply execute:

.. code:: bash

tox

and all the environments (style and tests) will be checked.


.. LINKS AND REFERENCES
.. _cookiecutter: https://cookiecutter.readthedocs.io/en/latest/
.. _PyAnsys Developer's guide: https://dev.docs.pyansys.com/
.. _tox: https://tox.wiki/
14 changes: 14 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"product_name": "product",
"product_name_slug": "{{ cookiecutter.product_name | lower | slugify }}",
"library_name": "library",
"library_name_slug": "{{ cookiecutter.library_name | lower | slugify }}",
"project_name_slug": "py{{ cookiecutter.product_name_slug }}-{{ cookiecutter.library_name_slug }}",
"pkg_name": "ansys-{{ cookiecutter.product_name_slug }}-{{ cookiecutter.library_name_slug }}",
"version": "0.1.dev0",
"short_description": "A Python wrapper for Ansys {{ cookiecutter.product_name }} {{ cookiecutter.library_name }}",
"repository_url": "https://github.com/pyansys/{{ cookiecutter.project_name_slug }}",
"requires_python": ["3.7", "3.8", "3.9", "3.10"],
"build_system": ["flit", "poetry", "setuptools"],
"max_linelength": "100"
}
75 changes: 75 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Post-processing script for cleaning the raw rendered project."""
import os
from pathlib import Path

import isort

ALLOWED_BUILD_SYSTEMS = ["flit", "poetry", "setuptools"]
"""A list of all allowed build systems by the template."""


def remove_tool_files(tool_name, basedir):
"""
Remove files matching given glob expression within desired base directory.

Parameters
----------
tool_name: str
Name of the tool used as build system.
basedir: Path
Base directory path.

"""
for filepath in basedir.glob(f"**/*_{tool_name}*"):
filepath.unlink()


def rename_tool_files(tool_name, basedir):
"""Rename tool filenames within desired base directory.

Parameters
----------
tool_name: str
Name of the tool used as build system.
basedir: Path
Base directory path.

"""
for original_filepath in basedir.glob(f"**/*_{tool_name}*"):
new_filename = original_filepath.name.replace(f"_{tool_name}", "")
original_filepath.rename(Path(original_filepath.parent, new_filename))


def main():
"""Entry point of the script."""
# Get baked project location path
project_path = Path(os.getcwd())

# Get the desired build system
build_system = "{{ cookiecutter.build_system }}"
# TODO: warn user if using setup.py
# if build_system == "setuptools":
# raise Warning("Please, consider to update to pyproject.toml.")

# Remove non-desired build system files
for tool in ALLOWED_BUILD_SYSTEMS:
if tool != build_system:
remove_tool_files(tool, project_path)

# Rename any files including tool name suffix
rename_tool_files(build_system, project_path)

# Apply isort with desired config
isort_config = isort.settings.Config(
line_length=100,
profile="black",
)
filepaths_list = [
project_path / "doc/source/conf.py",
]
for filepath in filepaths_list:
isort.api.sort_file(filepath, isort_config)


if __name__ == "__main__":
main()
29 changes: 29 additions & 0 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Pre-processing script for cleaning the raw rendered project."""
import subprocess
import sys


def install_package(package):
"""
Installs desired package in current Python environment.

Parameters
----------
package: str
Name of the package.

"""
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--ignore-installed", package]
)


def main():
"""Entry point of the script."""
packages_list = ["isort"]
for package in packages_list:
install_package(package)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cookiecutter==1.7.3
tox==3.24.5
2 changes: 2 additions & 0 deletions requirements/requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-cookies
Loading