Skip to content

Commit

Permalink
Move development to poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Dec 9, 2024
1 parent 321408d commit f758223
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 116 deletions.
3 changes: 1 addition & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[flake8]
ignore = E501,W504,H601
include = lib,tests
exclude = setup.py
include = cohesion,tests
22 changes: 12 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ jobs:
- macos-latest
- windows-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14-dev"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: requirements-dev.txt
cache: "poetry"
- name: Run CI
run: |
python -m pip install -e .
python -m pip install -r requirements-dev.txt
python -m flake8
python -m pytest --cov
poetry env use ${{ matrix.python-version }}
poetry install --with dev
poetry run flake8
poetry run pytest --cov
33 changes: 4 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ $ python -m pip install cohesion
$ cohesion -h
```

OR

```
$ git clone https://github.com/mschwager/cohesion.git
$ cd cohesion
$ PYTHONPATH=lib/ python -m cohesion -h
```

# Using

Cohesion measures class and instance variable usage across the methods
Expand Down Expand Up @@ -116,45 +108,28 @@ $ flake8 example.py
example.py:1:1: H601 class has low cohesion
```

## Python Versions

If you would like to simultaneously run Cohesion on Python 2 and Python 3
code then you will have to install it for both versions. I.e.

```
$ python2 -m pip install cohesion
$ python3 -m pip install cohesion
```

Then use the corresponding version to run the module:

```
$ python2 -m cohesion --files python2_file.py
$ python3 -m cohesion --files python3_file.py
```

# Developing

First, install development packages:

```
$ python -m pip install -r requirements-dev.txt
$ python -m poetry install --with=dev
```

## Testing

```
$ pytest
$ python -m poetry run pytest
```

## Linting

```
$ flake8
$ python -m poetry run flake8
```

## Coverage

```
$ pytest --cov
$ python -m poetry run pytest --cov
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
296 changes: 296 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[tool.poetry]
name = "cohesion"
version = "1.1.0"
description = "A tool for measuring Python class cohesion."
authors = []
license = "GPLv3"
readme = "README.md"
repository = "https://github.com/mschwager/cohesion"
homepage = "https://github.com/mschwager/cohesion"
packages = [{include = "cohesion"}]
classifiers = [
'Environment :: Console',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Topic :: Security',
'Topic :: Software Development :: Quality Assurance',
]

[tool.poetry.dependencies]
python = "^3.8.1"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.0"
pytest-cov = "^5.0.0"
pyfakefs = "^5.0.0"
flake8 = ">=5.0.4"

[tool.poetry.group.dev]
optional = true

[tool.poetry.scripts]
cohesion = "cohesion.__main__:main"

[tool.poetry.plugins."flake8.extension"]
H60 = "cohesion.flake8_extension:CohesionChecker"

[tool.coverage.run]
source = ["cohesion"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 0 additions & 4 deletions requirements-dev.txt

This file was deleted.

2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

55 changes: 0 additions & 55 deletions setup.py

This file was deleted.

15 changes: 1 addition & 14 deletions tests/test_flake8_extension.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#!/usr/bin/env python

import textwrap
import sys
import os
import unittest

from cohesion import parser

# Since flake8_extension imports cohesion we cannot add it to the
# module, and thus must come up with some tricks to import it
sys.path.append(
os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"lib",
"cohesion"
)
)

import flake8_extension # noqa E402: see above
from cohesion import flake8_extension


class TestFlake8Extension(unittest.TestCase):
Expand Down

0 comments on commit f758223

Please sign in to comment.