Skip to content

Commit

Permalink
Optimize installation process (#46)
Browse files Browse the repository at this point in the history
* resolve cython issue

* update ci

* refactor

* update repo structure

* refactor build process

* refine build and release pipeline

* update pipeline

* lazily import numpy

* fix error

* fix setup.py

* add setup requires

* fix env

* change project name

* update critical table

* update version

* update github-release rule

* update to v0.2.3

* update release pipeline

* update ci/cd yml

* add more os and set workding dir for testing

* fix circular import

* fix gitignore
  • Loading branch information
juaduan authored Mar 29, 2024
1 parent 53c5a28 commit 1bed547
Show file tree
Hide file tree
Showing 184 changed files with 41,697 additions and 2,585 deletions.
122 changes: 72 additions & 50 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,94 @@
name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
branch:
description: 'Name of the branch to build and release'
required: true
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: ['3.9', '3.10.8', '3.11']
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
python-version: "3.x"
- name: Install pypa/build
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine cython numpy
pip install setuptools wheel twine
- name: Build a binary wheel and a source tarball
run: |
python setup.py bdist_wheel sdist
run: python3 setup.py build sdist
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Rename wheel for manylinux compatibility (Ubuntu only)
if: runner.os == 'Linux'
run: |
for file in *.whl; do
if [[ $file == *linux* ]]; then
mv "$file" "${file/-linux/-manylinux1}"
fi
done
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest

environment:
name: release
url: https://test.pypi.org/p/time-series-anomaly-detector

- name: Publish artifacts
uses: actions/upload-artifact@v2
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: dist
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

release:
needs: build
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-testpypi
runs-on: ubuntu-latest

permissions:
contents: write
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download artifacts
uses: actions/download-artifact@v2
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: dist
name: python-package-distributions
path: dist/

- name: Publish to GitHub Releases
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
pwd && ls -lh && ls -lh dist/ &&
gh release create ${{ github.ref_name }} ./dist/*
"release binary and source artifacts"
--generate-notes
--title "Version ${{ github.ref_name }}"
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
75 changes: 8 additions & 67 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,34 @@ jobs:
# This workflow contains a single job called "build"
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ${{matrix.os}}
strategy:
matrix:
os: ["ubuntu-latest", "windows", "macos"]
python-version: ["3.9", "3.10.8", "3.11"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: setup python ${{matrix.python-version}}
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
cache: "poetry"

- name: install dependence
working-directory: anomaly-detector
run: |
poetry env use ${{matrix.python-version}}
poetry lock --no-update
poetry install

- name: compile .pyx file
- name: install package
run: |
pip install Cython
pip install numpy
python setup.py build_ext --inplace
python -m pip install -e .
- name: run the test script
working-directory: anomaly-detector/tests
working-directory: tests
run: |
pip install pytest
poetry run pytest test_demo.py
poetry run python uvad_test.py
pytest test_demo.py
python uvad_test.py
- name: Analyze code with pylint
run: |
pip install pylint
pylint --exit-zero $(git ls-files '*.py')
test_on_setup_whl:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10.8", "3.11"]
steps:
- uses: actions/checkout@v4

- name: setup python ${{matrix.python-version}}
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
cache: "pip"

- name: gen .whl file by setup
run: |
pip install Cython numpy setuptools wheel
python setup.py sdist bdist_wheel
- name: install .whl file
run: pip install ./dist/*.whl

- name: run the test script
working-directory: anomaly-detector/tests
run: |
pip install pytest
python test_demo.py
python uvad_test.py
test_on_setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: install package by setup.py
run: |
pip install Cython
pip install numpy
pip install .
- name: run the test script
working-directory: anomaly-detector/tests
run: |
pip install pytest
python test_demo.py
python uvad_test.py
pylint --exit-zero $(git ls-files '*.py')
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,12 @@ FodyWeavers.xsd

mlruns/
mlartifacts/
model/
venv/
dist/
temp/
build/
time_series_anomaly_detector.egg-info/
anomaly-detector/anomaly_detector/univariate/_anomaly_kernel_cython.c
#anomaly-detector/anomaly_detector/univariate/_anomaly_kernel_cython.c
.idea/
*.so
*.pyd
Expand Down
11 changes: 1 addition & 10 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
recursive-include ./anomaly-detector/*.pyx
recursive-include ./anomaly-detector/*.c
recursive-include ./anomaly-detector/*.h
recursive-include ./anomaly-detector/*.py
recursive-include ./anomaly-detector/*.txt
recursive-include ./anomaly-detector/anomaly_detector/univariate *
include ./README.md
include ./LICENSE
include ./requirements.txt
include ./setup.py
recursive-include ./src/anomaly_detector/univariate *
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,18 @@ Tested on
## Installing from pip

```bash
# install dependencies
pip install numpy>=1.23.5 Cython

# then install time-series-anomaly-detector
pip install time-series-anomaly-detector
# install time-series-anomaly-detector
pip install time-series-anomaly-detector==0.2.3
```

## Installing from Source
<!-- ## Clone the Repository -->

```bash
git clone https://github.com/microsoft/anomaly-detector.git
cd anomaly-detector
pip install -e .
```

<!-- ## Install -->


```bash
pip install -r requirements.txt
python setup.py sdist bdist_wheel
pip install ./dist/*.whl
```

## Test

```bash
Expand Down
Empty file removed anomaly-detector/README.md
Empty file.

This file was deleted.

63 changes: 0 additions & 63 deletions anomaly-detector/build.py

This file was deleted.

Loading

0 comments on commit 1bed547

Please sign in to comment.