Skip to content

Commit

Permalink
Merge pull request #17 from UCSD-E4E/poetry
Browse files Browse the repository at this point in the history
switches to poetry, upgrades tools and versions
  • Loading branch information
ccrutchf authored Dec 4, 2024
2 parents 8361c47 + ae6b8aa commit acdc4af
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 46 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
python -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
24 changes: 10 additions & 14 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@ on: [push, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest coverage
pip install .
python -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install
- name: Test
run: |
coverage run -m pytest tests/
coverage run -m pytest tests
- name: Generate Report
run: |
coverage html
- name: Upload report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
htmlcov/*
path: htmlcov/*
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Semantic Release

on:
push:
workflow_run:
workflows:
- Pylint
- PyTest
branches:
- main
types:
- completed

jobs:
release:
Expand All @@ -21,4 +26,5 @@ jobs:
- name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@master
with:
# This might need to be changed to the E4E Releaser PAT
github_token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"ms-toolsai.jupyter",
"njpwerner.autodocstring",
"ms-python.isort",
"ms-python.autopep8"
]
}
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.linting.pylintEnabled": true,
"editor.rulers": [
100
]
],
"python.testing.pytestEnabled": true,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications",
"editor.formatOnType": true
}
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@ Example Python Package Repository. This repository serves as an example of how
## .vscode
This folder should contain at least a `launch.json` file that provides entry points into the package. This could be entry points to example programs, typical debug entry points, etc. Ideally, this will also contain a `settings.json` with folder specific VS Code settings.

All standard invocations that developers should be using MUST be saved into a `launch.json` entry.

## Python Packages
Almost all code should be organized into packages. This facilitates easy code reuse. See https://packaging.python.org/en/latest/ for more information on how to use packages in Python.

## tests
Tests should ideally be kept in an isolated folder. This example uses `pytest`, see https://docs.pytest.org/en/7.0.x/ for information on how to use `pytest`.
Tests should ideally be kept in an isolated folder. This example uses `pytest`, see https://docs.pytest.org/en/8.3.x/ for information on how to use `pytest`.

## .gitignore
This is an important file to put into your `git` repositories. This helps prevent `git` from including unnecessary files into the version control system, such as generated files, environment files, or log files.
This is an important file to put into your `git` repositories. This helps prevent `git` from including unnecessary files into the version control system, such as generated files, environment files, or log files. Please upgrade this using https://gitignore.io

## Jupyter Notebooks
Jupyter Notebooks are a great way to add interactive reports or documentation. There is an example here.

## *.code-workspace
This is created by going to `File`->`Save Workspace As` in VS Code. This allows us to easily open the same development environment across computers and operating systems. Use this as the root of your development environment.

You'll also notice here that there are some recommended extensions. This allows everyone on your team to have a consistent toolchain for how to interact with your code. See https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions for instructions for how to configure these.

## README.md
This is a critical file to include. This should be an introduction to your repository. It should be a birds-eye view of what your repo is and how to use it, with links to the appropriate lower-level documentation.

## setup.py
This is the original way to package Python projects, which we probably still prefer. However, in general, if you can, you should probably start using the newer packaging tools (`pyproject.toml`)
## pyproject.toml
This is the standard way to package Python projects. This is now structured using Poetry, see https://python-poetry.org/ for tool documentation.

See https://packaging.python.org/en/latest/tutorials/packaging-projects/ and https://docs.python.org/3/distutils/setupscript.html for more information about each tool.

Expand All @@ -41,5 +38,20 @@ python -m venv .venv
source .venv/bin/activate # for bash
# Install in developer mode
python -m pip install -e .[dev]
poetry install
```

## Installing for end users
End users should do the following:
```
# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
.venv/Scripts/activate.ps1 # for Windows PowerShell
.venv/Scripts/activate.bat # for Windows Command Prompt
source .venv/bin/activate # for bash
# Install
pip install .
```
38 changes: 24 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
[build-system]
requires = ['setuptools']
build-backend = 'setuptools.build_meta'
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[project]
name = 'example_package'
[tool.poetry]
name = "example_package"
version = "0.1.0"
description = ""
authors = [
{name = 'UCSD Engineers for Exploration', email = '[email protected]'},
"UCSD Engineers for Exploration <[email protected]>"
]
description = ''
readme = 'REAME.md'
requires-python = '>=3.8'
keywords = []
license = {file = 'LICENSE'}
dependencies = [
]
dynamic = ['version']
license = "UCSD"
readme = "README.md"
repository = 'https://github.com/UCSD-E4E/python-repo-example'

[tool.poetry.dependencies]
python = "^3.12"

[project.scripts]
[tool.poetry.group.dev.dependencies]
pylint = "^3.2.7"
pytest = "^8.3.2"
jupyter = "^1.1.1"
autopep8 = "^2.3.1"
coverage = "^7.6.1"

[tool.poetry.scripts]
ExamplePythonConsoleScript = 'example_package.example_module:exampleEntryPoint'

[tool.semantic_release]
version_variables = ["example_package/__init__.py:__version__"]
version_toml = [
"pyproject.toml:tool.poetry.version",
]
assets = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
Expand Down

0 comments on commit acdc4af

Please sign in to comment.