From 6805c4691f16b53f6a45e10349ebf329877f013d Mon Sep 17 00:00:00 2001 From: "Budnick, Leon" Date: Sat, 23 Dec 2023 11:14:44 +0100 Subject: [PATCH] new project structure --- .github/workflows/build.yml | 37 +++--- .github/workflows/lint.yml | 25 ++-- .github/workflows/publish.yml | 62 +++++++-- factorialhr/__init__.py | 11 -- pyproject.toml | 123 +++++++++++++++--- src/factorialhr/__init__.py | 1 + {factorialhr => src/factorialhr}/endpoints.py | 0 {factorialhr => src/factorialhr}/models.py | 0 {factorialhr => src/factorialhr}/py.typed | 0 9 files changed, 189 insertions(+), 70 deletions(-) delete mode 100644 factorialhr/__init__.py create mode 100644 src/factorialhr/__init__.py rename {factorialhr => src/factorialhr}/endpoints.py (100%) rename {factorialhr => src/factorialhr}/models.py (100%) rename {factorialhr => src/factorialhr}/py.typed (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5b26a1..e5ac585 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,20 +3,17 @@ name: Build package on: workflow_call: pull_request: - branches: - - main - - "v[0-9]+.[0-9]+.x" + types: [ opened, synchronize, reopened, ready_for_review ] jobs: linters: uses: ./.github/workflows/lint.yml build: - name: Build runs-on: ubuntu-latest - needs: linters - permissions: - contents: write + outputs: + WHL: ${{ steps.filenames.outputs.WHL }} + TARGZ: ${{ steps.filenames.outputs.TARGZ }} steps: - name: Check out Git repository @@ -27,20 +24,24 @@ jobs: with: python-version: "3.11" - - name: Detect release version + - name: Setup hatch + run: python -m pip install hatch + + - name: Set new version if: startsWith(github.ref, 'refs/tags/v') run: | - echo FACTORIALHR_VERSION=${GITHUB_REF/refs\/tags\//} >> $GITHUB_ENV - - - name: Install build - run: pip install build - + python -m hatch version ${GITHUB_REF/refs\/tags\/v/} - name: Build package - run: python -m build + run: python -m hatch build - - name: Archive wheel + - name: Set filenames in output + id: filenames + run: | + echo WHL=$(echo dist/*.whl) >> $GITHUB_OUTPUT + echo TARGZ=$(echo dist/*.tar.gz) >> $GITHUB_OUTPUT + - name: Archive package uses: actions/upload-artifact@v3 with: - name: dist - path: dist/*.whl - retention-days: 1 \ No newline at end of file + name: distributions + path: dist + retention-days: 5 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3b2f9d8..ea9d674 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,9 +1,12 @@ name: Lint package -on: workflow_call +on: + workflow_call: + pull_request: + types: [ opened, synchronize, reopened, ready_for_review ] jobs: - linters: + lint: name: Run linters runs-on: ubuntu-latest @@ -20,17 +23,11 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Python dependencies - run: pip install ".[lint]" - - - name: Run Black - run: black --check factorialhr - - - name: Run isort - run: isort factorialhr -c - - - name: Run flake8 - run: flake8 factorialhr + - uses: chartboost/ruff-action@v1 - name: Run mypy - run: mypy factorialhr + uses: sasanquaneuf/mypy-github-action@releases/v1 + with: + checkName: 'lint' # NOTE: this needs to be the same as the job name + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8881984..240b403 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,32 +1,72 @@ -name: Publish package to pypi +name: Publish package on: - workflow_call: push: tags: - - "v[0-9]+.[0-9]+.[0-9]+[ab][0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+" # normal release + - "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+" # release candidate + - "v[0-9]+.[0-9]+.[0-9]+[ab][0-9]+" # alpha or beta release jobs: build: - permissions: - contents: write uses: ./.github/workflows/build.yml - publish: - name: Publish + upload: + name: Upload runs-on: ubuntu-latest needs: build - permissions: - contents: write + outputs: + DO_GITHUB_RELEASE: ${{ steps.detect-release.outputs.DO_GITHUB_RELEASE }} steps: - name: Download Artifact uses: actions/download-artifact@v3 with: - name: dist + name: distributions path: dist/ - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_API_TOKEN }} + + - name: Detect release version + id: detect-release + run: | + do_github_release=$((echo "${GITHUB_REF}" | grep -Eq "^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$") && echo 1 || echo 0) + echo DO_GITHUB_RELEASE=$do_github_release >> $GITHUB_OUTPUT + echo DO_GITHUB_RELEASE=$do_github_release + + release: + name: Release + runs-on: ubuntu-latest + needs: upload + if: needs.upload.outputs.DO_GITHUB_RELEASE == '1' + permissions: + contents: write + + steps: + - name: Check out Git repository + uses: actions/checkout@v3 + + - name: Download Build + uses: actions/download-artifact@v3 + with: + name: distributions + path: dist + + - name: Detect prerelease + id: detect-prerelease + run: | + do_prerelease=$((echo "${GITHUB_REF}" | grep -Eq "^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+rc[0-9]+$") && echo 1 || echo 0) + echo DO_PRERELEASE=$do_prerelease >> $GITHUB_ENV + echo DO_PRERELEASE=$do_prerelease + + - name: Attach artifacts to github release + uses: softprops/action-gh-release@v1 + with: + files: | + CHANGELOG.md + dist/* + prerelease: ${{ env.DO_PRERELEASE == '1' }} + body_path: CHANGELOG.md \ No newline at end of file diff --git a/factorialhr/__init__.py b/factorialhr/__init__.py deleted file mode 100644 index 3445b9f..0000000 --- a/factorialhr/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -try: - __version__ = os.environ["FACTORIALHR_VERSION"] -except KeyError: - from importlib import metadata - - try: - __version__ = metadata.version("factorialhr") - except metadata.PackageNotFoundError: - __version__ = "0.0.0" diff --git a/pyproject.toml b/pyproject.toml index 0904b8e..41d8d67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["flit_core >=3.2"] -build-backend = "flit_core.buildapi" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "factorialhr" @@ -8,7 +8,7 @@ dynamic = ["version"] authors = [ { name = "Leon Budnick", email = "y6q6ea9w@mail-proxy.org" }, ] -description = "Python package for the api of FactorialHR " +description = "Python package for the api of FactorialHR" readme = "README.md" requires-python = ">=3.11" classifiers = [ @@ -34,23 +34,114 @@ dependencies = [ [project.urls] "Homepage" = "https://github.com/leon1995/factorialhr" "Bug Tracker" = "https://github.com/leon1995/factorialhr/issues" + [project.optional-dependencies] lint = [ - 'black', - 'flake8', + "ruff", 'mypy', - 'isort' ] -[tool.pytest.ini_options] -testpaths = "tests/" -#addopts = "--cov=fwtv --cov-report term-missing --cov-fail-under=95" +[tool.hatch.build.targets.sdist] +include = [ + "src/factorialhr/**/*", + "LICENSE", + "README.md", + "pyproject.toml", + "CHANGELOG.md" +] +support-legacy = false + +[tool.hatch.build.targets.wheel] +packages = ["src/factorialhr"] + +[tool.hatch.version] +path = "src/factorialhr/__init__.py" + +[tool.ruff] +extend-select = [# https://beta.ruff.rs/docs/settings/#extend-select + "A", # https://beta.ruff.rs/docs/rules/#flake8-builtins-a + "ANN", # https://beta.ruff.rs/docs/rules/#flake8-annotations-ann + "ARG", # https://beta.ruff.rs/docs/rules/#flake8-unused-arguments-arg + "B", # https://beta.ruff.rs/docs/rules/#flake8-bugbear-b + "BLE", # https://beta.ruff.rs/docs/rules/#flake8-blind-except-ble + "C4", # https://beta.ruff.rs/docs/rules/#flake8-comprehensions-c4 + "C90", # https://beta.ruff.rs/docs/rules/#mccabe-c90 + "COM", # https://beta.ruff.rs/docs/rules/#flake8-commas-com + "D", # https://beta.ruff.rs/docs/rules/#pydocstyle-d + "ERA", # https://beta.ruff.rs/docs/rules/#eradicate-era + "G", # https://beta.ruff.rs/docs/rules/#flake8-logging-format-g + "I", # https://beta.ruff.rs/docs/rules/#isort-i + "ICN", # https://beta.ruff.rs/docs/rules/#flake8-import-conventions-icn + "INP", # https://beta.ruff.rs/docs/rules/#flake8-no-pep420-inp + "ISC", # https://beta.ruff.rs/docs/rules/#flake8-implicit-str-concat-isc + "ICN", # https://beta.ruff.rs/docs/rules/#flake8-import-conventions-icn + "N", # https://beta.ruff.rs/docs/rules/#pep8-naming-n + "PGH", # https://beta.ruff.rs/docs/rules/#pygrep-hooks-pgh + "PIE", # https://beta.ruff.rs/docs/rules/#flake8-pie-pie + "PL", # https://beta.ruff.rs/docs/rules/#pylint-pl + # "PT", # https://beta.ruff.rs/docs/rules/#flake8-pytest-style-pt + "PTH", # https://beta.ruff.rs/docs/rules/#flake8-use-pathlib-pth + "PYI", # https://beta.ruff.rs/docs/rules/#flake8-pyi-pyi + "Q", # https://beta.ruff.rs/docs/rules/#flake8-quotes-q + "RET", # https://beta.ruff.rs/docs/rules/#flake8-return-ret + "RSE", # https://beta.ruff.rs/docs/rules/#flake8-raise-rse + "RUF", # https://beta.ruff.rs/docs/rules/#ruff-specific-rules-ruf + "S", # https://beta.ruff.rs/docs/rules/#flake8-bandit-s + "SIM", # https://beta.ruff.rs/docs/rules/#flake8-simplify-sim + "SLF", # https://beta.ruff.rs/docs/rules/#flake8-self-slf + "T20", # https://beta.ruff.rs/docs/rules/#flake8-print-t20 + "TCH", # https://beta.ruff.rs/docs/rules/#flake8-type-checking-tch + "TID", # https://beta.ruff.rs/docs/rules/#flake8-tidy-imports-tid + "UP", # https://beta.ruff.rs/docs/rules/#pyupgrade-up + "YTT" # https://beta.ruff.rs/docs/rules/#flake8-2020-ytt +] +extend-ignore = [# https://beta.ruff.rs/docs/settings/#extend-ignore + "ANN101", # https://beta.ruff.rs/docs/rules/missing-type-self/ + "ANN102", # https://beta.ruff.rs/docs/rules/missing-type-cls/ + "ANN204", # https://beta.ruff.rs/docs/rules/missing-return-type-special-method/ + "ANN401", # https://beta.ruff.rs/docs/rules/any-type/ + "C408", # https://beta.ruff.rs/docs/rules/unnecessary-collection-call/ + "C409", # https://beta.ruff.rs/docs/rules/unnecessary-literal-within-tuple-call/ + "D105", # undocumented-magic-method + "D107", # undocumented-public-init + "D203", # one-blank-line-before-class + "D213", # multi-line-summary-second-line + "Q000", # https://beta.ruff.rs/docs/rules/bad-quotes-inline-string/ + "S101", # https://beta.ruff.rs/docs/rules/assert/ + "S311", # https://beta.ruff.rs/docs/rules/suspicious-non-cryptographic-random-usage/ + "SIM102", # collapsible-if + "T201", # https://beta.ruff.rs/docs/rules/print/ + +] +line-length = 120 # https://beta.ruff.rs/docs/settings/#line-length +target-version = "py311" # https://beta.ruff.rs/docs/settings/#target-version +# Allow imports relative to the "src" and "test" directories. +src = ["src", "test"] # https://beta.ruff.rs/docs/settings/#src +# In addition to the standard set of exclusions, omit all tutorials and examples +extend-exclude = ["examples", "tools", "tutorial"] # https://beta.ruff.rs/docs/settings/#extend-exclude + +[tool.ruff.flake8-annotations] +allow-star-arg-any = true # https://beta.ruff.rs/docs/settings/#allow-star-arg-any +suppress-none-returning = true # https://beta.ruff.rs/docs/settings/#suppress-none-returning + +[tool.ruff.flake8-comprehensions] +allow-dict-calls-with-keyword-arguments = true # https://beta.ruff.rs/docs/settings/#allow-dict-calls-with-keyword-arguments + +[tool.ruff.pycodestyle] +max-doc-length = 120 # https://beta.ruff.rs/docs/settings/#max-doc-length -[tool.black] -line-length = 120 +[tool.ruff.per-file-ignores] +"__init__.py" = ["D104"] -[isort] -force_single_line = 1 -known_localfolder = "factorialhr" -force_alphabetical_sort_within_sections = 1 -profile = "black" \ No newline at end of file +[tool.mypy] +python_version = "3.9" # https://mypy.readthedocs.io/en/stable/config_file.html#confval-python_version +strict = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-strict +disallow_untyped_calls = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_untyped_calls +disallow_untyped_defs = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_untyped_defs +disallow_any_generics = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_any_generics +disallow_any_unimported = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_any_unimported +warn_redundant_casts = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-warn_redundant_casts +check_untyped_defs = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-check_untyped_defs +warn_return_any = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-warn_return_any +warn_unused_configs = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-warn_unused_configs +warn_unused_ignores = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-warn_unused_ignores diff --git a/src/factorialhr/__init__.py b/src/factorialhr/__init__.py new file mode 100644 index 0000000..6c8e6b9 --- /dev/null +++ b/src/factorialhr/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.0" diff --git a/factorialhr/endpoints.py b/src/factorialhr/endpoints.py similarity index 100% rename from factorialhr/endpoints.py rename to src/factorialhr/endpoints.py diff --git a/factorialhr/models.py b/src/factorialhr/models.py similarity index 100% rename from factorialhr/models.py rename to src/factorialhr/models.py diff --git a/factorialhr/py.typed b/src/factorialhr/py.typed similarity index 100% rename from factorialhr/py.typed rename to src/factorialhr/py.typed