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

Change project structure for Poetry and Jupyter-Book ocmpatibility #10

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
33 changes: 0 additions & 33 deletions .gitlab-ci.yml

This file was deleted.

31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@

This repository contains a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template
that can be used for library development. The template contains several well-known "best-practices" for libraries
(tox, sphinx, nbsphinx, coverage, pylint etc) and also some tools
(mypy, ruff, sphinx, nbsphinx, coverage, pylint etc) and also some tools
MischaPanch marked this conversation as resolved.
Show resolved Hide resolved
inspired by projects of ours that we consider generally useful - build and release scripts,
auto-generation of documentation files, links for jumping directly to the correct place in the source code and others.
Earlier versions of this template were used in several industry projects as well as for open source libraries.

Build, install and tests of the library are run by tox, the documentation is built with sphinx and a
helper script (both also invoked by tox). The template includes ci/cd pipelines for gitlab CI, github actions and
a rudimentary pipeline for azure devops. The pipeline will run the test suite and publish docu, badges and reports. On
gitlab, [gitlab pages](https://docs.gitlab.com/ee/user/project/pages/) are used and on github,
we make use of [github pages](https://pages.github.com/) through the
[github-pages-deploy-action](https://github.com/JamesIves/github-pages-deploy-action). You will need to enable pages
for gitlab, for github you should configure the pages source to be the root directory of the branch gh-pages.
Build, install and tests of the library are run by default poetry tasks, the documentation is built with Jupyter-Books.
The template includes ci/cd pipelines for github actions and a rudimentary pipeline for azure devops.
The pipeline will run the test suite and publish docu, badges and reports.
We make use of [github pages](https://pages.github.com/) through the [github-pages-deploy-action](https://github.com/JamesIves/github-pages-deploy-action).
You should configure the pages source to be the root directory of the branch gh-pages.

In the documentation links to source code will be created, therefore you will be prompted to give the project's url.

See the resulting repository's [developer's readme]({{cookiecutter.project_name}}/README-dev.md) for further details. An example of the current output of this template is in [pymetrius_output](https://github.com/appliedAI-Initiative/pymetrius_output)
See the resulting repository's [developer's readme]({{cookiecutter.project_name}}/docs/04_contributing/04_contributing.rst)
for further details. An example of the current output of this template is in [pymetrius_output](https://github.com/appliedAI-Initiative/pymetrius_output)

# Usage

## Prerequisites

The template supports python 3.8 and higher. For a smooth project generation you need to have
The template supports python 3.11 and higher. For a smooth project generation you need to have

1) Python of the correct version installed on your system.
2) The venv module for that python version. If not installed yet, you can install it with
```shell script
sudo apt-get update && apt-get install python<VERSION>-venv
```
3) Cookiecutter. Install it e.g. with `pip install cookiecutter`
2) Cookiecutter. Install it e.g. with `pip install cookiecutter`


## Creating a new project
Expand All @@ -44,9 +39,9 @@ cookiecutter https://github.com/appliedAI-Initiative/python_library_template -o
and walk through the questions. You can also clone this repository, adjust the template and call cookiecutter on
the local file.

You will get a repo in `<path/to/directory>/<project_name>` with a venv inside it; the venv will contain your new
library installed in "editable mode" (i.e. with `pip install -e` ).
If you prefer to use a different virtual environment (like conda), feel free to delete the venv.
You will get a repo in `<path/to/directory>/<project_name>`, which will contain your new library installed in
"editable mode" (i.e. with `pip install -e`, we reccomend installing in poetry with `poetry install --with dev` ).
The virtual environment is created by poetry. Documentation is built with jupyter-book and is published on github pages.


# Contributing
Expand Down
9 changes: 5 additions & 4 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"project_name": null,
"author": null,
"project_name": "test",
"author": "carlo",
"author_email": "[email protected]",
"package_name": "{{cookiecutter.project_name}}",
"python_version": ["3.8", "3.9"],
"python_version": ["3.11", "3.12"],
"project_url": "https://github.com/{{cookiecutter.author}}/{{cookiecutter.project_name}}",
"include_configuration_utils": ["Y", "n"],
"include_accsr_configuration_utils": ["N", "y"],
"include_readthedocs_yaml": ["N", "y"],
"initial_version": "0.1.0",
"_copy_without_render": [
Expand Down
42 changes: 6 additions & 36 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,18 @@ def delete_line_in_file(filepath: str, line_starts_with: str):
if "{{cookiecutter.include_readthedocs_yaml}}".lower() != "y":
remove(".readthedocs.yaml")

if "{{cookiecutter.include_configuration_utils}}".lower() != "y":
if "{{cookiecutter.include_accsr_configuration_utils}}".lower() != "y":
remove("config.py")
remove("config.json")
remove("notebooks/config_example.ipynb")
delete_line_in_file("requirements-dev.txt", "accsr")
delete_line_in_file("requirements-test.txt", "accsr")
remove("docs/02_notebooks/config_example.ipynb")
remove("data")
delete_line_in_file("pyproject.toml", "accsr")
delete_line_in_file(".gitignore", "config_local.json")

return_code = os.system(
"""
echo "Initializing your new project in $(pwd). This might take a while"

# THIS IS A NAIVE HACK TO PREVENT COOKIECUTTER FROM RENDERING IN GITHUB WORKFLOWS
cat .github/workflows/tox-addition.yaml >> .github/workflows/tox.yaml
rm .github/workflows/tox-addition.yaml
return_code = os.system("""
echo "Initializing your new project in $(pwd)."

git init
echo "Creating and activating venv"
python{{cookiecutter.python_version}} -m venv ./.venv
. .venv/bin/activate
echo "Installing dev requirements"
pip install -q -r requirements-dev.txt
echo "Performing Initial formatting"
black . && isort . && nbstripout notebooks/*
echo "Setting git hooks"
pre-commit install
pre-commit autoupdate
echo "Initial commit"
git checkout -b develop
git add . && git add -f data/raw/hello.txt
git commit -q -m "Initial commit by pymetrius"
echo "Installing {{cookiecutter.project_name}} in editable mode into .venv"
pip install -q -e .
echo "A virtual environment for your project has been created in $(pwd)/.venv, \
the library was installed there in editable mode."
echo "Running the sample script"
python scripts/run_sample.py
echo "All done, you can start by running tox (will take a while the first time) and looking at the docu in \
docs/_build/html. \n \
You can also just quickly run tests and build the docu using \n \
./build_scripts/run-all-tests-with-coverage.sh \n
./build_scripts/build-docs.sh \n \"
"""
)
if return_code:
Expand Down
2 changes: 1 addition & 1 deletion tests/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_context:
project_name: pymetrius_output
author: automated_user
python_version: 3.8
python_version: 3.11
project_url: https://github.com/appliedAI-Initiative/pymetrius_output
22 changes: 0 additions & 22 deletions {{cookiecutter.project_name}}/.bumpversion.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions {{cookiecutter.project_name}}/.coveragerc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_REPO_PASS }}
{%- endraw %}
run: |
# TODO: build dist with poetry
python setup.py sdist bdist_wheel
twine upload dist/*
27 changes: 0 additions & 27 deletions {{cookiecutter.project_name}}/.github/workflows/tox-addition.yaml

This file was deleted.

42 changes: 0 additions & 42 deletions {{cookiecutter.project_name}}/.github/workflows/tox.yaml

This file was deleted.

Loading
Loading