From 25f686bae5ea08872c3444393c8b949177a35814 Mon Sep 17 00:00:00 2001 From: varisd Date: Thu, 20 Jun 2024 16:31:15 +0200 Subject: [PATCH] initial github project setup --- .github/workflows/release.yaml | 83 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 44 ++++++++++++++++++ pyproject.toml | 78 ++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 pyproject.toml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..5e4e97c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,83 @@ +name: Build and upload to PyPI + +on: + push: + release: + types: + - published + +jobs: + run_tests: + name: Run tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v3 + + - name: Install + run: python3 -m pip install . + + - name: Run runtime pytest + run: pytest tests + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v3 + + - name: Set version number + if: startsWith(github.ref, 'refs/tags/v') + run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v3 + with: + name: sdist + path: dist/opuscleaner-*.tar.gz + + build_wheels: + name: Build wheels + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v3 + + - name: Set version number + if: startsWith(github.ref, 'refs/tags/v') + run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py + + - name: Build wheels + run: python -m pip wheel -w wheelhouse . + + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: ./wheelhouse/opuscleaner-*.whl + + upload_pypi: + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: actions/download-artifact@v3 + with: + name: wheels + path: dist + + - uses: actions/download-artifact@v3 + with: + name: sdist + path: dist + + - uses: pypa/gh-action-pypi-publish@v1.5.0 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..60ff9ce --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,44 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python +name: Testing (CI/CD) + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + + 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: Display Python version + run: python -c "import sys; print(sys.version)" + + - name: Install requirements + run: | + python -m pip install --upgrade pip setuptools + pip install pre-commit ruff pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Lint with pre-commit + run: pre-commit run --all-files + + - name: Test with pytest + run: pytest tests/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..81b267f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,78 @@ +[build-system] +requires = ["hatchling", "hatch-requirements-txt"] +build-backend = "hatchling.build" + +[project] +name = "opuspocus" +description = "Modular NLP pipeline manager." +readme = "README.md" +requires-python = ">=3.7" +license = "MIT" +keywords = ["OPUS", "HPLT", "pipeline manager"] +authors = [ + { name = "Dušan Variš", email = "varis@ufal.mff.cuni.cz" }, +] +classifiers = [ + "Development Status :: 3 - Alpha", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dynamic = [ + "version", + "dependencies", + "optional-dependencies" +] + +[project.scripts] +opuspocus = "go:main_cli" + +[project.urls] +Documentation = "https://github.com/hplt-project/opuspocus#readme" +Issues = "https://github.com/hplt-project/opuspocus/issues" +Repository = "https://github.com/hplt-project/OpusPocus.git" + +[tool.hatch.version] +path = "opuspocus/__about__.py" + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "pytest-cov", +] +[tool.hatch.envs.default.scripts] +cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=opuspocus --cov=tests {args}" +no-cov = "cov --no-cov {args}" + +[[tool.hatch.envs.test.matrix]] +python = ["37", "38", "39", "310", "311"] + +[tool.hatch.build] +include = [ + "/opuspocus", +] + +[tool.hatch.metadata.hooks.requirements_txt] +files = ["requirements.txt"] + +[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies] +all = ["requirements-all.txt"] + +[tool.coverage.run] +branch = true +parallel = true +omit = [ + "opuspocus/__about__.py", +] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +]