Skip to content

Commit 1bed547

Browse files
authored
Optimize installation process (#46)
* 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
1 parent 53c5a28 commit 1bed547

File tree

184 files changed

+41697
-2585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+41697
-2585
lines changed

.github/workflows/cd.yml

+72-50
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,94 @@
1-
name: Build and Release
2-
on:
3-
push:
4-
tags:
5-
- 'v*'
6-
workflow_dispatch:
7-
inputs:
8-
branch:
9-
description: 'Name of the branch to build and release'
10-
required: true
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+
on: push
114

125
jobs:
136
build:
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
os: [windows-latest, ubuntu-latest, macos-latest]
18-
python-version: ['3.9', '3.10.8', '3.11']
7+
name: Build distribution 📦
8+
runs-on: ubuntu-latest
199

2010
steps:
21-
- uses: actions/checkout@v2
22-
11+
- uses: actions/checkout@v4
2312
- name: Set up Python
24-
uses: actions/setup-python@v2
13+
uses: actions/setup-python@v4
2514
with:
26-
python-version: ${{ matrix.python-version }}
27-
28-
- name: Install dependencies
15+
python-version: "3.x"
16+
- name: Install pypa/build
2917
run: |
3018
python -m pip install --upgrade pip
31-
pip install setuptools wheel twine cython numpy
32-
19+
pip install setuptools wheel twine
3320
- name: Build a binary wheel and a source tarball
34-
run: |
35-
python setup.py bdist_wheel sdist
21+
run: python3 setup.py build sdist
22+
- name: Store the distribution packages
23+
uses: actions/upload-artifact@v3
24+
with:
25+
name: python-package-distributions
26+
path: dist/
3627

37-
- name: Rename wheel for manylinux compatibility (Ubuntu only)
38-
if: runner.os == 'Linux'
39-
run: |
40-
for file in *.whl; do
41-
if [[ $file == *linux* ]]; then
42-
mv "$file" "${file/-linux/-manylinux1}"
43-
fi
44-
done
28+
publish-to-testpypi:
29+
name: Publish Python 🐍 distribution 📦 to TestPyPI
30+
if: startsWith(github.ref, 'refs/tags/')
31+
needs:
32+
- build
33+
runs-on: ubuntu-latest
34+
35+
environment:
36+
name: release
37+
url: https://test.pypi.org/p/time-series-anomaly-detector
4538

46-
- name: Publish artifacts
47-
uses: actions/upload-artifact@v2
39+
permissions:
40+
id-token: write # IMPORTANT: mandatory for trusted publishing
41+
42+
steps:
43+
- name: Download all the dists
44+
uses: actions/download-artifact@v3
4845
with:
49-
name: dist
46+
name: python-package-distributions
5047
path: dist/
48+
- name: Publish distribution 📦 to TestPyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
5152

52-
release:
53-
needs: build
53+
github-release:
54+
name: >-
55+
Sign the Python 🐍 distribution 📦 with Sigstore
56+
and upload them to GitHub Release
57+
needs:
58+
- publish-to-testpypi
5459
runs-on: ubuntu-latest
60+
5561
permissions:
56-
contents: write
62+
contents: write # IMPORTANT: mandatory for making GitHub Releases
63+
id-token: write # IMPORTANT: mandatory for sigstore
64+
5765
steps:
58-
- name: Download artifacts
59-
uses: actions/download-artifact@v2
66+
- name: Download all the dists
67+
uses: actions/download-artifact@v3
6068
with:
61-
name: dist
69+
name: python-package-distributions
6270
path: dist/
63-
64-
- name: Publish to GitHub Releases
71+
- name: Sign the dists with Sigstore
72+
uses: sigstore/[email protected]
73+
with:
74+
inputs: >-
75+
./dist/*.tar.gz
76+
./dist/*.whl
77+
- name: Create GitHub Release
78+
env:
79+
GITHUB_TOKEN: ${{ github.token }}
80+
run: >-
81+
gh release create
82+
'${{ github.ref_name }}'
83+
--repo '${{ github.repository }}'
84+
--notes ""
85+
- name: Upload artifact signatures to GitHub Release
6586
env:
66-
GITHUB_TOKEN: ${{ secrets.RELEASE_KEY }}
87+
GITHUB_TOKEN: ${{ github.token }}
88+
# Upload to GitHub Release using the `gh` CLI.
89+
# `dist/` contains the built packages, and the
90+
# sigstore-produced signatures and certificates.
6791
run: >-
68-
pwd && ls -lh && ls -lh dist/ &&
69-
gh release create ${{ github.ref_name }} ./dist/*
70-
"release binary and source artifacts"
71-
--generate-notes
72-
--title "Version ${{ github.ref_name }}"
92+
gh release upload
93+
'${{ github.ref_name }}' dist/**
94+
--repo '${{ github.repository }}'

.github/workflows/ci.yml

+8-67
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,34 @@ jobs:
1818
# This workflow contains a single job called "build"
1919
test:
2020
# The type of runner that the job will run on
21-
runs-on: ubuntu-latest
21+
runs-on: ${{matrix.os}}
2222
strategy:
2323
matrix:
24+
os: ["ubuntu-latest", "windows", "macos"]
2425
python-version: ["3.9", "3.10.8", "3.11"]
2526

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

31-
- name: Install poetry
32-
run: pipx install poetry
33-
3432
- name: setup python ${{matrix.python-version}}
3533
uses: actions/setup-python@v4
3634
with:
3735
python-version: ${{matrix.python-version}}
38-
cache: "poetry"
39-
40-
- name: install dependence
41-
working-directory: anomaly-detector
42-
run: |
43-
poetry env use ${{matrix.python-version}}
44-
poetry lock --no-update
45-
poetry install
4636

47-
- name: compile .pyx file
37+
- name: install package
4838
run: |
49-
pip install Cython
50-
pip install numpy
51-
python setup.py build_ext --inplace
39+
python -m pip install -e .
5240
5341
- name: run the test script
54-
working-directory: anomaly-detector/tests
42+
working-directory: tests
5543
run: |
5644
pip install pytest
57-
poetry run pytest test_demo.py
58-
poetry run python uvad_test.py
45+
pytest test_demo.py
46+
python uvad_test.py
5947
6048
- name: Analyze code with pylint
6149
run: |
6250
pip install pylint
63-
pylint --exit-zero $(git ls-files '*.py')
64-
65-
test_on_setup_whl:
66-
runs-on: ubuntu-latest
67-
strategy:
68-
matrix:
69-
python-version: ["3.9", "3.10.8", "3.11"]
70-
steps:
71-
- uses: actions/checkout@v4
72-
73-
- name: setup python ${{matrix.python-version}}
74-
uses: actions/setup-python@v4
75-
with:
76-
python-version: ${{matrix.python-version}}
77-
cache: "pip"
78-
79-
- name: gen .whl file by setup
80-
run: |
81-
pip install Cython numpy setuptools wheel
82-
python setup.py sdist bdist_wheel
83-
84-
- name: install .whl file
85-
run: pip install ./dist/*.whl
86-
87-
- name: run the test script
88-
working-directory: anomaly-detector/tests
89-
run: |
90-
pip install pytest
91-
python test_demo.py
92-
python uvad_test.py
93-
94-
test_on_setup:
95-
runs-on: ubuntu-latest
96-
steps:
97-
- uses: actions/checkout@v4
98-
99-
- name: install package by setup.py
100-
run: |
101-
pip install Cython
102-
pip install numpy
103-
pip install .
104-
105-
- name: run the test script
106-
working-directory: anomaly-detector/tests
107-
run: |
108-
pip install pytest
109-
python test_demo.py
110-
python uvad_test.py
51+
pylint --exit-zero $(git ls-files '*.py')

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,12 @@ FodyWeavers.xsd
399399

400400
mlruns/
401401
mlartifacts/
402-
model/
403402
venv/
404403
dist/
405404
temp/
406405
build/
407406
time_series_anomaly_detector.egg-info/
408-
anomaly-detector/anomaly_detector/univariate/_anomaly_kernel_cython.c
407+
#anomaly-detector/anomaly_detector/univariate/_anomaly_kernel_cython.c
409408
.idea/
410409
*.so
411410
*.pyd

MANIFEST.in

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
recursive-include ./anomaly-detector/*.pyx
2-
recursive-include ./anomaly-detector/*.c
3-
recursive-include ./anomaly-detector/*.h
4-
recursive-include ./anomaly-detector/*.py
5-
recursive-include ./anomaly-detector/*.txt
6-
recursive-include ./anomaly-detector/anomaly_detector/univariate *
7-
include ./README.md
8-
include ./LICENSE
9-
include ./requirements.txt
10-
include ./setup.py
1+
recursive-include ./src/anomaly_detector/univariate *

README.md

+3-15
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@ Tested on
1111
## Installing from pip
1212

1313
```bash
14-
# install dependencies
15-
pip install numpy>=1.23.5 Cython
16-
17-
# then install time-series-anomaly-detector
18-
pip install time-series-anomaly-detector
14+
# install time-series-anomaly-detector
15+
pip install time-series-anomaly-detector==0.2.3
1916
```
2017

2118
## Installing from Source
2219
<!-- ## Clone the Repository -->
2320

2421
```bash
2522
git clone https://github.com/microsoft/anomaly-detector.git
26-
cd anomaly-detector
23+
pip install -e .
2724
```
2825

29-
<!-- ## Install -->
30-
31-
32-
```bash
33-
pip install -r requirements.txt
34-
python setup.py sdist bdist_wheel
35-
pip install ./dist/*.whl
36-
```
37-
3826
## Test
3927

4028
```bash

anomaly-detector/README.md

Whitespace-only changes.

anomaly-detector/anomaly_detector/univariate/util/critical_table.txt

-1
This file was deleted.

anomaly-detector/build.py

-63
This file was deleted.

0 commit comments

Comments
 (0)