Skip to content

Commit

Permalink
Merge pull request #5 from mwbrulhardt/main
Browse files Browse the repository at this point in the history
Added poetry for setup and workflow
  • Loading branch information
gmgeorg committed Apr 15, 2024
2 parents 7f3d779 + 3b993d5 commit f64eac4
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 68 deletions.
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "pylambertw",
"postCreateCommand": "bash .devcontainer/post-create.sh",
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cache",
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"installJupyterlab": true,
"version": "3.12"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [],
// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
},
"python.defaultInterpreterPath": "./.venv/bin/python"
},
"extensions": [
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"vscode-icons-team.vscode-icons",
"wayou.vscode-todo-highlight",
"timonwong.shellcheck",
"charliermarsh.ruff",
"ms-python.python"
]
}
},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode"
}
11 changes: 11 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

# Setup poetry and install
poetry config virtualenvs.in-project true
poetry install --with dev

# Setup and install pre-commit
cd /workspace
source .venv/bin/activate
pre-commit install
20 changes: 13 additions & 7 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.8.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
run: poetry install --with dev

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 pylambertw --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=C901
poetry run flake8 pylambertw --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=C901
- name: Test with pytest
run: |
pytest
poetry run pytest
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Ruff
.ruff_cache/
2 changes: 1 addition & 1 deletion pylambertw/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version."""

__version__ = "0.0.3"
__version__ = "0.0.4"
12 changes: 7 additions & 5 deletions pylambertw/igmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ def fit(self, data: np.ndarray):
self._initialize_params(data)

tau_trace = np.zeros(shape=(self.max_iter + 1, 3))
tau_trace[0,] = np.array([
self.tau_init.loc,
self.tau_init.scale,
self.tau_init.lambertw_params.delta,
]).reshape(1, -1)
tau_trace[0,] = np.array(
[
self.tau_init.loc,
self.tau_init.scale,
self.tau_init.lambertw_params.delta,
]
).reshape(1, -1)

for kk in range(self.max_iter):
current = tau_trace[kk, :]
Expand Down
34 changes: 31 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
[tool.poetry]
name = "pylambertw"
version = "0.0.4"
description = "Python implementation of the Lambert W x F framework for analyzing skewed, heavy-tailed distribution with an sklearn interface and torch based maximum likelihood estimation (MLE)."
authors = ["Georg M. Goerg <im@gmge.org>"]
homepage = "https://github.com/gmgeorg/pylambertw.git"

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

dataclasses = ">=0.6"
matplotlib = ">=3.3.0"
numpy = ">=1.0.1"
pandas = ">=1.0.0"
scikit-learn = ">=1.0.1"
scipy = ">=1.7.0"
seaborn = ">=0.11.1"
statsmodels = ">=0.12.0"
torch = ">=2.0.1"
torchlambertw = { git = "https://github.com/gmgeorg/torchlambertw.git", rev = "v0.0.3" }
tqdm = ">=4.62.3"

[tool.poetry.group.dev.dependencies]
flake8 = "^7.0.0"
pre-commit = "^3.7.0"
pytest = ">=6.1.1"
ruff = "^0.3.7"

[tool.ruff]
line-length = 100

fix = true


[tool.ruff.per-file-ignores]
"setup.py" = ['E501'] # line length violations
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

39 changes: 0 additions & 39 deletions setup.py

This file was deleted.

0 comments on commit f64eac4

Please sign in to comment.