Skip to content

Commit

Permalink
Adding virtualenv to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Anavelyz committed Aug 15, 2023
1 parent dc42597 commit a06ce04
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 53 deletions.
5 changes: 5 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ community.
is a good option. It is included in all versions of Anaconda and
Miniconda.

If you select this option, a conda folder will appear in the project
directory, containing a dev.yaml file that you can use to manage the
development project's dependencies. If you do not select this option, a
requirements.txt will be added for you to manage with virtualenv.

### Code formatter

A code formatter is a tool that automatically reformats code to conform to a set
Expand Down
91 changes: 48 additions & 43 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
PROJECT_DIRECTORY = Path(os.path.abspath(os.path.curdir)).resolve()

UNUSED_DOCS_DIRS = [
PROJECT_DIRECTORY / 'docs-mkdocs',
PROJECT_DIRECTORY / 'docs-sphinx',
PROJECT_DIRECTORY / 'docs-jupyter-book'
PROJECT_DIRECTORY / "docs-mkdocs",
PROJECT_DIRECTORY / "docs-sphinx",
PROJECT_DIRECTORY / "docs-jupyter-book"
]

DOCUMENTATION_ENGINE = "{{ cookiecutter.documentation_engine }}"
DOCS_SPEC_DIR = UNUSED_DOCS_DIRS.pop(
UNUSED_DOCS_DIRS.index(
PROJECT_DIRECTORY / f'docs-{DOCUMENTATION_ENGINE}'
PROJECT_DIRECTORY / f"docs-{DOCUMENTATION_ENGINE}"
)
)

Expand All @@ -30,26 +30,26 @@
USE_BLACK = {{ cookiecutter.use_black == "yes" }}
USE_BLUE = {{ cookiecutter.use_blue == "yes" }}
USE_BANDIT = {{ cookiecutter.use_bandit == "yes" }}
USE_CONTAINERS = {{ cookiecutter.use_containers in ['Docker', 'Podman'] }}
USE_CONTAINERS = {{ cookiecutter.use_containers in ["Docker", "Podman"] }}
USE_CLI = {{ cookiecutter.command_line_interface != "No command-line interface" }}
USE_CONDA = {{ cookiecutter.use_conda == "yes" }}
USE_MYPY = {{ cookiecutter.use_mypy == "yes" }}
{% if cookiecutter.code_of_conduct == "contributor-covenant" -%}
COC_PATH = PROJECT_DIRECTORY / 'coc' / 'CONTRIBUTOR_COVENANT.md'
COC_PATH = PROJECT_DIRECTORY / "coc" / "CONTRIBUTOR_COVENANT.md"
{%- elif cookiecutter.code_of_conduct == "citizen-code-of-conduct" -%}
COC_PATH = PROJECT_DIRECTORY / 'coc' / 'CITIZEN.md'
COC_PATH = PROJECT_DIRECTORY / "coc" / "CITIZEN.md"
{% else %}
COC_PATH = None
{%- endif %}
{% if cookiecutter.governance_document == "numpy-governance" -%}
GOVERNANCE_PATH = PROJECT_DIRECTORY / 'governance' / 'numpy_governance.md'
GOVERNANCE_PATH = PROJECT_DIRECTORY / "governance" / "numpy_governance.md"
{% elif cookiecutter.code_of_conduct == "sciml-governance" -%}
GOVERNANCE_PATH = PROJECT_DIRECTORY / 'governance' / 'sciml_governance.md'
GOVERNANCE_PATH = PROJECT_DIRECTORY / "governance" / "sciml_governance.md"
{% else -%}
GOVERNANCE_PATH = None
{%- endif %}
{% if cookiecutter.roadmap_document == "pytorch-ignite-roadmap" -%}
ROADMAP_PATH = PROJECT_DIRECTORY / 'roadmap' / 'ignite_roadmap.md'
ROADMAP_PATH = PROJECT_DIRECTORY / "roadmap" / "ignite_roadmap.md"
{%- else %}
ROADMAP_PATH = None
{%- endif %}
Expand All @@ -74,7 +74,7 @@
{%- else %}
BUILD_SYSTEM = None
{%- endif %}

WORKFLOW_PATH = PROJECT_DIRECTORY / ".github" / "workflows"

def remove_dirs(dirs: list):
for dirs in dirs:
Expand Down Expand Up @@ -115,28 +115,46 @@ def clean_up_project_layout():
if USE_SRC_LAYOUT:
if not os.path.exists("src"):
os.mkdir("src")
shutil.move('{{cookiecutter.package_slug}}', 'src')
shutil.move("{{cookiecutter.package_slug}}", "src")


def clean_up_code_of_conduct():
if COC_PATH:
shutil.move(
COC_PATH,
PROJECT_DIRECTORY / 'CODE_OF_CONDUCT.md'
PROJECT_DIRECTORY / "CODE_OF_CONDUCT.md"
)
remove_dir("coc")


def clean_up_conda():
if not USE_CONDA:
remove_dir("conda")
remove_dir( WORKFLOW_PATH /"conda-workflows" )
shutil.move(WORKFLOW_PATH / "virtualenv-workflows" / "main.yaml",
WORKFLOW_PATH )
shutil.move(WORKFLOW_PATH / "virtualenv-workflows" / "release.yaml",
WORKFLOW_PATH )
remove_dir(WORKFLOW_PATH / "virtualenv-workflows")
shutil.move(PROJECT_DIRECTORY/ "virtualenv"/ "requirements.txt",
PROJECT_DIRECTORY)
remove_dir(PROJECT_DIRECTORY/ "virtualenv")
else:
remove_dir("virtualenv")
remove_dir( WORKFLOW_PATH /"virtualenv-workflows" )
shutil.move(WORKFLOW_PATH / "conda-workflows" / "main.yaml",
WORKFLOW_PATH )
shutil.move(WORKFLOW_PATH / "conda-workflows" / "release.yaml",
WORKFLOW_PATH )
remove_dir(WORKFLOW_PATH / "conda-workflows")



def clean_up_governance():
if GOVERNANCE_PATH:
shutil.move(
GOVERNANCE_PATH,
PROJECT_DIRECTORY / 'governance.md'
PROJECT_DIRECTORY / "governance.md"
)
remove_dir("governance")

Expand All @@ -145,7 +163,7 @@ def clean_up_roadmap():
if ROADMAP_PATH:
shutil.move(
ROADMAP_PATH,
PROJECT_DIRECTORY / 'roadmap.md'
PROJECT_DIRECTORY / "roadmap.md"
)
remove_dir("roadmap")

Expand All @@ -166,76 +184,63 @@ def clean_up_build_system():
if BUILD_SYSTEM == "poetry":
shutil.move(
build_system_dir / "poetry-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
elif BUILD_SYSTEM == "flit":
shutil.move(
build_system_dir / "flit-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
elif BUILD_SYSTEM == "mesonpy":
shutil.move(
build_system_dir / "mesonpy-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
shutil.move(
build_system_dir / "meson.build",
PROJECT_DIRECTORY / 'meson.build'
PROJECT_DIRECTORY / "meson.build"
)
elif BUILD_SYSTEM == "setuptools":
shutil.move(
build_system_dir / "setuptools-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
elif BUILD_SYSTEM == "pdm":
shutil.move(
build_system_dir / "pdm-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
elif BUILD_SYSTEM == "hatch":
shutil.move(
build_system_dir / "hatch-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
elif BUILD_SYSTEM == "maturin":
shutil.move(
build_system_dir / "maturin-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
shutil.move(
build_system_dir / "Cargo.toml",
PROJECT_DIRECTORY / 'Cargo.toml'
)
PROJECT_DIRECTORY / "Cargo.toml"
)
elif BUILD_SYSTEM == "scikit-build-core":
shutil.move(
build_system_dir / "scikit-build-core-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
shutil.move(
build_system_dir / "CMakeLists.txt",
PROJECT_DIRECTORY / 'CMakeLists.txt'
PROJECT_DIRECTORY / "CMakeLists.txt"
)
shutil.move(
build_system_dir / "skcdemo.cpp",
PROJECT_DIRECTORY / 'skcdemo.cpp'
)
elif BUILD_SYSTEM == "pybind11":
shutil.move(
build_system_dir / "pybind11-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "CMakeLists.txt",
PROJECT_DIRECTORY / 'CMakeLists.txt'
)
shutil.move(
build_system_dir / "setup.py",
PROJECT_DIRECTORY / 'setup.py'
)
PROJECT_DIRECTORY / "skcdemo.cpp"
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
PROJECT_DIRECTORY / "pyproject.toml"
)
remove_dir("build-system")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Release

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 'pypy3.9'

- name: Create virtualenv
run: python -m venv {{ cookiecutter.project_slug }}

- name: Activate virtualenv
run: source {{ cookiecutter.project_slug }}/bin/activate

- name: Install dependencies
{%- if cookiecutter.build_system == "poetry" %}
run: poetry install
{%- elif cookiecutter.build_system == "flit" %}
run: flit install
{%- elif cookiecutter.build_system in ["maturin", "mesonpy", "scikit_build_core", "setuptools"] %}
run: pip install -e .
{%- elif cookiecutter.build_system == "pdm" %}
run: pdm install
{%- elif cookiecutter.build_system == "hatch" %}
run: hatch run
{%- endif %}

- name: Run semantic release (for tests)
if: ${{ "{{ github.event_name != 'workflow_dispatch' }}" }}
env:
GITHUB_TOKEN: ${{ "{{ secrets.GITHUB_TOKEN }}" }}
run: make release-dry

- name: Release command
if: ${{ "{{ github.event_name == 'workflow_dispatch' }}" }}
env:
GITHUB_TOKEN: ${{ "{{ secrets.GITHUB_TOKEN }}" }}
PYPI_TOKEN: ${{ "{{ secrets.PYPI_TOKEN }}" }}
run: |
poetry config pypi-token.pypi ${PYPI_TOKEN}
make release-ci
- name: Generate documentation with changes from semantic-release
if: ${{ "{{ github.event_name == 'workflow_dispatch' }}" }}
run: make docs-build

- name: GitHub Pages action
if: ${{ "{{ github.event_name == 'workflow_dispatch' }}" }}
uses: peaceiris/actions-gh-pages@v3.5.9
with:
github_token: ${{ "{{ secrets.GITHUB_TOKEN }}" }}
publish_dir: ./docs/_build/html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
concurrency:
group: ci-${{ "{{ github.ref }}" }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 'pypy3.9'

- name: Create virtualenv
run: python -m venv {{ cookiecutter.project_slug }}

- name: Activate virtualenv
run: source {{ cookiecutter.project_slug }}/bin/activate

- name: Install build-system
run: pip install -r requirements.txt

- name: Install dependencies
{%- if cookiecutter.build_system == "poetry" %}
run: poetry install
{%- elif cookiecutter.build_system == "flit" %}
run: flit install
{%- elif cookiecutter.build_system in ["maturin", "mesonpy", "scikit_build_core", "setuptools"] %}
run: pip install -e .
{%- elif cookiecutter.build_system == "pdm" %}
run: pdm install
{%- elif cookiecutter.build_system == "hatch" %}
run: hatch run
{%- endif %}

- name: Run tests
run: make test

- name: Run style checks
run: |
pre-commit install
make lint
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: conda-incubator/setup-miniconda@v2
- uses: actions/setup-python@v4
with:
miniconda-version: "latest"
mamba-version: "1.*"
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
channel-priority: true
activate-environment: {{ cookiecutter.project_slug }}
use-mamba: true
miniforge-variant: Mambaforge
python-version: 'pypy3.9'

- name: Create virtualenv
run: python -m venv {{ cookiecutter.project_slug }}

- name: Activate virtualenv
run: source {{ cookiecutter.project_slug }}/bin/activate

- name: Install build-system
run: pip install -r requirements.txt

- name: Install dependencies
{%- if cookiecutter.build_system == "poetry" %}
Expand Down
Loading

0 comments on commit a06ce04

Please sign in to comment.