From f188724d4b207d301df8e2c88c654b10ae51fefb Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 5 Jul 2022 10:45:51 +0200 Subject: [PATCH] Add Flit and change namer --- .github/workflows/docker.yaml | 2 +- .github/workflows/publish.yaml | 17 ++++----- .github/workflows/test.yml | 5 +-- .vscode/tasks.json | 4 +- Dockerfile | 2 +- README.md | 18 +++++---- dev-requirements.txt | 13 ------- great_ai/__init__.py | 4 ++ mkdocs.yml | 14 +++++++ pyproject.toml | 68 +++++++++++++++++++++++++++++++--- scripts/check-python.sh | 27 ++++++++------ scripts/format-python.sh | 34 +++++++++-------- setup.cfg | 49 ------------------------ 13 files changed, 138 insertions(+), 119 deletions(-) delete mode 100644 dev-requirements.txt create mode 100644 mkdocs.yml delete mode 100644 setup.cfg diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 8ac9d06..f54641d 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -28,7 +28,7 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: schmelczera/great-ai + images: schmelczera/great_ai - name: Build and push uses: docker/build-push-action@v3 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 85e9d52..c2e4050 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -16,14 +16,11 @@ jobs: with: python-version: 3.9 - - name: Install pypa/build - run: python -m pip install build --user + - name: Install Flit + run: pip install --upgrade flit --user - - name: Build a binary wheel and a source tarball - run: python -m build --sdist --wheel --outdir dist/ - - - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + - name: Build and publish + run: flit publish --setup-py + env: + FLIT_USERNAME: __token__ + FLIT_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07c8cd3..496b074 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,11 +30,10 @@ jobs: - name: Install dependencies run: | python3 -m pip install --upgrade pip - pip install --upgrade --requirement dev-requirements.txt - pip install --upgrade . + pip install --upgrade './[dev]' - name: Check code and formatting - run: scripts/check-python.sh . + run: scripts/check-python.sh . tests - name: Run tests run: python3 -m pytest --doctest-modules --cov=. --cov-report=xml --junit-xml pytest.xml --asyncio-mode=strict || true diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9abc7ab..9d3230f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,9 +4,9 @@ { "label": "Format and lint", "type": "shell", - "command": "source .env/bin/activate && scripts/format-python.sh .", + "command": "source .env/bin/activate && scripts/format-python.sh . tests", "windows": { - "command": ".env\\bin\\activate.bat; scripts\\format-python.sh ." + "command": ".env\\bin\\activate.bat; scripts\\format-python.sh . tests" }, "group": "test", "presentation": { diff --git a/Dockerfile b/Dockerfile index e99b071..c8d5730 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3.10.4-slim-bullseye LABEL org.opencontainers.image.title="GreatAI package wrapper container" LABEL org.opencontainers.image.vendor="ScoutinScience B.V." LABEL org.opencontainers.image.authors="andras@schmelczer.dev" -LABEL org.opencontainers.image.source="https://github.com/ScoutinScience/great-ai" +LABEL org.opencontainers.image.source="https://github.com/ScoutinScience/great_ai" ENV ENVIRONMENT=production EXPOSE 6060 diff --git a/README.md b/README.md index 241c6d5..827d826 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,26 @@ **work in progress, do not use!** -[![Test](https://github.com/ScoutinScience/great_ai/actions/workflows/test.yml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/check.yml) [![Quality Gate Status](https://sonar.scoutinscience.com/api/project_badges/measure?project=great-ai&metric=alert_status)](https://sonar.scoutinscience.com/dashboard?id=great-ai) [![Publish on PyPI](https://github.com/ScoutinScience/great_ai/actions/workflows/publish.yaml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/publish.yaml) [![Publish on DockerHub](https://github.com/ScoutinScience/great_ai/actions/workflows/docker.yaml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/docker.yaml) +[![Test](https://github.com/ScoutinScience/great_ai/actions/workflows/test.yml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/check.yml) +[![Quality Gate Status](https://sonar.scoutinscience.com/api/project_badges/measure?project=great-ai&metric=alert_status)](https://sonar.scoutinscience.com/dashboard?id=great_ai) +[![Publish on PyPI](https://github.com/ScoutinScience/great_ai/actions/workflows/publish.yaml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/publish.yaml) +[![Publish on DockerHub](https://github.com/ScoutinScience/great_ai/actions/workflows/docker.yaml/badge.svg)](https://github.com/ScoutinScience/great_ai/actions/workflows/docker.yaml) +[![Downloads](https://pepy.tech/badge/great_ai/month)](https://pepy.tech/project/great_ai) -## Find `great-ai` on [DockerHub](https://hub.docker.com/repository/docker/schmelczera/great-ai) +## Find `great_ai` on [DockerHub](https://hub.docker.com/repository/docker/schmelczera/great_ai) ```sh -docker run -p6060:6060 schmelczera/great-ai +docker run -p6060:6060 schmelczera/great_ai ``` Find the dashboard at [http://localhost:6060](http://localhost:6060/dashboard/). -## Find `great-ai` on [PyPI](https://pypi.org/project/great-ai/) +## Find `great_ai` on [PyPI](https://pypi.org/project/great_ai/) ```sh -pip install great-ai +pip install great_ai ``` ```python @@ -29,13 +33,13 @@ def hello_world(name: str) -> str: ``` > Create a new file called `main.py` -Deploy by executing `python3 -m great-ai main.py` +Deploy by executing `python3 -m great_ai main.py` Find the dashboard at [http://localhost:6060](http://localhost:6060/dashboard/). ### Contribute ```sh -pip install --upgrade --requirement dev-requirements.txt +pip install 'great_ai[dev]' ``` diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 4424810..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -build -mkdocs -mkdocstrings[python] -mkdocs-material -autoflake -isort -black[jupyter] -mypy -flake8 -pytest -pytest-cov -pytest-subtests -pytest-asyncio diff --git a/great_ai/__init__.py b/great_ai/__init__.py index 04e3e65..211373a 100644 --- a/great_ai/__init__.py +++ b/great_ai/__init__.py @@ -1,3 +1,7 @@ +"""GreatAI""" +__version__ = "0.0.12" + + from .context import configure from .deploy import GreatAI from .exceptions import ( diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..3dd976f --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,14 @@ +site_name: GreatAI documentation + +theme: + name: "material" + +plugins: + - mkdocstrings + +nav: + - Home: index.md + - tutorials.md + - How-To Guides: how-to-guides.md + - reference.md + - explanation.md diff --git a/pyproject.toml b/pyproject.toml index 4faf030..ba4faa5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,65 @@ [build-system] -requires = [ - "setuptools>=42", - "setuptools-git", - "wheel" +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "great_ai" +dynamic = ["version", "description"] +readme = "README.md" +authors = [{ name = "András Schmelczer", email = "andras@schmelczer.dev" }] +license = { file = "LICENSE" } +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)" ] -build-backend = "setuptools.build_meta" +keywords = ["SE4ML", "MLOps", "AI engineering", "general", "robust", "end-to-end", "automated", "trustworthy", "ai", "deployment"] +requires-python = ">= 3.8" +dependencies = [ + "scikit-learn", + "matplotlib", + "numpy", + "nbconvert", + "ipython", + "unidecode >= 1.3.0", + "syntok >= 1.4.0", + "langcodes[data] >= 3.3.0", + "langdetect >= 1.0.9", + "tinydb >= 4.7.0", + "boto3 >= 1.23.0", + "plotly >= 5.8.0", + "pandas", + "dash >= 2.4.0", + "fastapi >= 0.70.0", + "uvicorn[standard] >= 0.18.0", + "watchdog >= 2.1.0", + "typeguard >= 2.10.0", + "pymongo >= 3.0.0", + "dill >= 0.3.5.0", + "aiohttp[speedups] >= 3.8.0", +] + +[project.optional-dependencies] +dev = [ + "flit", + "mkdocs", + "mkdocstrings[python]", + "mkdocs-material", + "autoflake", + "isort", + "black[jupyter]", + "mypy", + "flake8", + "pytest", + "pytest-cov", + "pytest-subtests", + "pytest-asyncio" +] + +[project.urls] +Homepage = "https://github.com/ScoutinScience/great_ai" +DockerHub = "https://hub.docker.com/repository/docker/schmelczera/great_ai" + +[project.scripts] +great_ai = "great_ai:main" +large_file = "great_ai.large_file:main" diff --git a/scripts/check-python.sh b/scripts/check-python.sh index b6cbcfb..668308c 100755 --- a/scripts/check-python.sh +++ b/scripts/check-python.sh @@ -2,21 +2,24 @@ set -e -echo "Checking $1" +echo "Installing dependencies if necessary" +python3 -m pip install --upgrade autoflake isort black[jupyter] mypy flake8 -cd $1 +for dir in "$@"; do + echo "Checking $dir" -python3 -m autoflake --expand-star-imports --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables --in-place -r . --check -python3 -m isort --profile black --skip .env . --check -python3 -m black . --exclude .env --check + cd "$dir" -if ls *.py 1> /dev/null 2>&1; then - yes | python3 -m mypy . --install-types > /dev/null || true - python3 -m mypy --namespace-packages --ignore-missing-imports --install-types --non-interactive --disallow-untyped-defs --disallow-incomplete-defs --follow-imports=silent --exclude=external/ --exclude=/build/ --pretty . -fi + python3 -m autoflake --expand-star-imports --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables --in-place -r . --check + python3 -m isort --profile black --skip .env . --check + python3 -m black . --exclude .env --check -python3 -m flake8 . --count --show-source --statistics --exclude=__init__.py,.env,external --ignore=E501,E722,E402,W503,E203 + if find . -name "*.py" 2>/dev/null | grep -q .; then + yes | python3 -m mypy . --install-types > /dev/null || true + python3 -m mypy --namespace-packages --ignore-missing-imports --install-types --non-interactive --disallow-untyped-defs --disallow-incomplete-defs --follow-imports=silent --exclude=external/ --exclude=/build/ --pretty . + fi -cd - + python3 -m flake8 . --count --show-source --statistics --exclude=__init__.py,.env,external --ignore=E501,E402,F821,W503,E722,E203 -echo "Finished checking" + cd - +done diff --git a/scripts/format-python.sh b/scripts/format-python.sh index 4ed6730..8cbf26d 100755 --- a/scripts/format-python.sh +++ b/scripts/format-python.sh @@ -2,27 +2,29 @@ set -e -echo "Formatting and checking $1" +for dir in "$@"; do + echo "Formatting and checking $dir" -cd $1 + cd "$dir" -echo Running autoflake -python3 -m autoflake --expand-star-imports --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables --in-place -r . + echo Running autoflake + python3 -m autoflake --expand-star-imports --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables --in-place -r . -echo Running isort -python3 -m isort --profile black --skip .env . + echo Running isort + python3 -m isort --profile black --skip .env . -echo Running black -python3 -m black . --exclude .env + echo Running black + python3 -m black . --exclude .env -if ls *.py 1> /dev/null 2>&1; then - echo Running mypy - python3 -m mypy --namespace-packages --ignore-missing-imports --install-types --non-interactive --disallow-untyped-defs --disallow-incomplete-defs --pretty --follow-imports=silent --exclude=external/ --exclude=/build/ . -fi + if find . -name "*.py" 2>/dev/null | grep -q .; then + echo Running mypy -echo Running Flake8 -python3 -m flake8 . --count --show-source --statistics --exclude=__init__.py,.env,external --ignore=E501,E722,E402,W503,E203 + if [ ! -d .mypy_cache ]; then + python3 -m mypy --namespace-packages --ignore-missing-imports --disallow-untyped-defs --disallow-incomplete-defs --follow-imports=silent --exclude=external/ --exclude=/build/ --pretty . || true + fi -cd - + python3 -m mypy --namespace-packages --ignore-missing-imports --install-types --non-interactive --disallow-untyped-defs --disallow-incomplete-defs --follow-imports=silent --exclude=external/ --exclude=/build/ --pretty . || true + fi -echo "Finished formatting" + cd - +done diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c8994b9..0000000 --- a/setup.cfg +++ /dev/null @@ -1,49 +0,0 @@ -[metadata] -name = great-ai -version = 0.0.11 -author = András Schmelczer -author_email = andras@scoutinscience.com -description = -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/ScoutinScience/great-ai -project_urls = - Bug Tracker = https://github.com/ScoutinScience/great-ai/issues -classifiers = - Programming Language :: Python :: 3 - Operating System :: OS Independent - -[options] -package_dir = - great_ai = great_ai - -include_package_data = True -python_requires = >= 3.8 -install_requires = - scikit-learn - matplotlib - numpy - nbconvert - ipython - unidecode >= 1.3.0 - syntok >= 1.4.0 - langcodes[data] >= 3.3.0 - langdetect >= 1.0.9 - tinydb >= 4.7.0 - boto3 >= 1.23.0 - plotly >= 5.8.0 - pandas - dash >= 2.4.0 - fastapi >= 0.70.0 - uvicorn[standard] >= 0.18.0 - watchdog >= 2.1.0 - typeguard >= 2.10.0 - pymongo >= 3.0.0 - dill >= 0.3.5.0 - aiohttp[speedups] >= 3.8.0 - -[options.package_data] -* = *.conf, *.css, *.png - -[options.packages.find] -where = .