Skip to content

Commit

Permalink
Added Python 3.7 support (#27)
Browse files Browse the repository at this point in the history
* separated documentation environment and modified github workflows accordingly
* added py37 to tox and github workflows
* added importlib-metadata dependency for python 3.7
* fixed unit tests
* added python version button to README
  • Loading branch information
Florian Maas authored Sep 5, 2022
1 parent bbdc7d2 commit 3fea461
Show file tree
Hide file tree
Showing 29 changed files with 926 additions and 1,958 deletions.
56 changes: 56 additions & 0 deletions .github/actions/check-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "check-docs"
description: "Composite action to verify the documentation."
inputs:
python-version:
required: false
description: "The python version to use"
default: 3.9.7
runs:
using: "composite"
steps:
#----------------------------------------------
# from: https://github.com/snok/install-poetry
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.python-version }}

#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: docs/.venv
key: docs-venv-${{ runner.os }}-${{ hashFiles('poetry.lock') }}

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
cd docs
poetry install --no-interaction --no-root
shell: bash

- name: Run checks
run: |
cd docs
poetry run mkdocs build -s
shell: bash
56 changes: 56 additions & 0 deletions .github/actions/deploy-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "deploy-docs"
description: "Composite action to verify the documentation."
inputs:
python-version:
required: false
description: "The python version to use"
default: 3.9.7
runs:
using: "composite"
steps:
#----------------------------------------------
# from: https://github.com/snok/install-poetry
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.python-version }}

#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: docs/.venv
key: docs-venv-${{ runner.os }}-${{ hashFiles('poetry.lock') }}

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
cd docs
poetry install --no-interaction --no-root
shell: bash

- name: Run checks
run: |
cd docs
poetry run mkdocs gh-deploy --force
shell: bash
5 changes: 2 additions & 3 deletions .github/actions/setup-poetry-env/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# checkout-and-yarn/action.yml

name: "setup-poetry-env"
description: "Composite action to setup the Python and poetry environment."
inputs:
Expand Down Expand Up @@ -38,7 +36,7 @@ runs:
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
key: venv-${{ runner.os }}-${{ hashFiles('poetry.lock') }}

#----------------------------------------------
# install dependencies if cache does not exist
Expand All @@ -53,6 +51,7 @@ runs:
- name: Install library
run: poetry install --no-interaction
shell: bash

- name: Activate environment
run: source .venv/bin/activate
shell: bash
20 changes: 13 additions & 7 deletions .github/workflows/on-merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ jobs:
- name: Run checks
uses: ./.github/actions/run-checks

- name: Documentation Test
run: |
source .venv/bin/activate
make docs-test
tox:
runs-on: ubuntu-latest
needs: quality
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Check out
uses: actions/checkout@v2
Expand All @@ -45,4 +40,15 @@ jobs:
run: |
source .venv/bin/activate
poetry add tox-gh-actions
tox
tox
check-docs:
runs-on: ubuntu-latest
needs: quality
steps:

- name: Check out
uses: actions/checkout@v2

- name: check documentation
uses: ./.github/actions/check-docs
21 changes: 15 additions & 6 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ jobs:
- name: Run checks
uses: ./.github/actions/run-checks

- name: Documentation Test
run: |
source .venv/bin/activate
make docs-test
tox:
runs-on: ubuntu-latest
needs: quality
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Check out
uses: actions/checkout@v2
Expand All @@ -43,3 +38,17 @@ jobs:
source .venv/bin/activate
poetry add tox-gh-actions
tox
check-docs:
runs-on: ubuntu-latest
needs: quality
steps:

- name: Check out
uses: actions/checkout@v2

- name: check documentation
uses: ./.github/actions/check-docs



36 changes: 20 additions & 16 deletions .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ jobs:
- name: Run checks
uses: ./.github/actions/run-checks

- name: Documentation Test
run: |
source .venv/bin/activate
make docs-test
tox:
needs: quality
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Check out
uses: actions/checkout@v2
Expand All @@ -46,6 +41,18 @@ jobs:
poetry add tox-gh-actions
tox
check-docs:
runs-on: ubuntu-latest
needs: quality
steps:

- name: Check out
uses: actions/checkout@v2

- name: check documentation
uses: ./.github/actions/check-docs

publish:
runs-on: ubuntu-latest
needs: tox
Expand All @@ -70,18 +77,15 @@ jobs:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

documentation:

deploy-docs:
runs-on: ubuntu-latest
needs: publish
needs: quality
steps:

- name: Check out
uses: actions/checkout@v2

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env

- name: Generate documentation
run: |
source .venv/bin/activate
mkdocs gh-deploy --force
- name: check documentation
uses: ./.github/actions/deploy-docs

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ publish: ## publish a release to pypi.
build-and-publish: build publish ## Build and publish.

docs-test: ## Test if documentation can be built without warnings or errors
@mkdocs build -s
@( cd docs ; poetry run mkdocs build -s)

docs: ## Build and serve the documentation
@mkdocs serve
@( cd docs ; poetry run mkdocs serve )

.PHONY: docs

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Release](https://img.shields.io/github/v/release/fpgmaas/deptry)](https://img.shields.io/github/v/release/fpgmaas/deptry)
[![Build status](https://img.shields.io/github/workflow/status/fpgmaas/deptry/merge-to-main)](https://img.shields.io/github/workflow/status/fpgmaas/deptry/merge-to-main)
[![Commit activity](https://img.shields.io/github/commit-activity/m/fpgmaas/deptry)](https://img.shields.io/github/commit-activity/m/fpgmaas/deptry)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/deptry)](https://pypi.org/project/deptry/)
[![Docs](https://img.shields.io/badge/docs-gh--pages-blue)](https://fpgmaas.github.io/deptry/)
[![Code style with black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports with isort](https://img.shields.io/badge/%20imports-isort-%231674b1)](https://pycqa.github.io/isort/)
Expand Down
2 changes: 2 additions & 0 deletions deptry/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def _override_config_with_pyproject_toml(self) -> None:
pyproject_toml_config = self._read_configuration_from_pyproject_toml()
if pyproject_toml_config:
self._override_with_toml_argument("ignore_dependencies", List[str], pyproject_toml_config)
self._override_with_toml_argument("ignore_directories", List[str], pyproject_toml_config)
self._override_with_toml_argument("ignore_notebooks", List[str], pyproject_toml_config)

def _read_configuration_from_pyproject_toml(self) -> Optional[Dict]:
try:
Expand Down
5 changes: 5 additions & 0 deletions deptry/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from pathlib import Path
from typing import List

Expand All @@ -12,6 +13,10 @@ def __init__(self, ignore_dependencies: List[str], ignore_directories: List[str]
self.ignore_dependencies = ignore_dependencies
self.ignore_directories = ignore_directories
self.ignore_notebooks = ignore_notebooks
logging.debug("Running with the following configuration:")
logging.debug(f"ignore_dependencies: {ignore_dependencies}")
logging.debug(f"ignore_directories: {ignore_directories}")
logging.debug(f"ignore_notebooks: {ignore_notebooks}")

def run(self) -> List[str]:
all_python_files = PythonFileFinder(
Expand Down
7 changes: 6 additions & 1 deletion deptry/imports_to_package_names.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import logging
import sys
from importlib.metadata import metadata
from typing import List, Set

from isort.stdlibs.py37 import stdlib as stdlib37
from isort.stdlibs.py38 import stdlib as stdlib38
from isort.stdlibs.py39 import stdlib as stdlib39
from isort.stdlibs.py310 import stdlib as stdlib310

# importlib.metadata is in the standard library since Python version 3.8
if sys.version_info[1] == 7:
from importlib_metadata import metadata
else:
from importlib.metadata import metadata

COMMON_PACKAGES_WITHOUT_METADATA = {"bs4": "beautifulsoup4", "dotenv": "python-dotenv"}


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3fea461

Please sign in to comment.