Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 48272358 authored by Dorian Turba's avatar Dorian Turba
Browse files

first commit

parents
No related branches found
No related tags found
No related merge requests found
[flake8]
exclude = .git,__pycache__,venv,dist
max-complexity = 10
max-line-length = 100
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
stages:
- code_quality
- test
include:
- remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/black@latest.yaml'
- remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/ruff@latest.yaml'
- remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/pytest@latest.yaml'
- remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/flake8@latest.yaml'
- remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/mypy@latest.yaml'
variables:
PACKAGE_NAME: "requirement_compare"
black:
variables:
PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
ruff:
variables:
PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
flake8:
variables:
PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
mypy:
variables:
PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
pytest:
variables:
PYTHON_SETUP: "pip install ${PROJECT_PATH}[TEST]"
pytest_310:
extends: pytest
variables:
IMAGE_TAG: "3.10"
pytest_39:
extends: pytest
variables:
IMAGE_TAG: "3.9"
pytest_38:
extends: pytest
variables:
IMAGE_TAG: "3.8"
pytest_37:
extends: pytest
variables:
IMAGE_TAG: "3.7"
repos:
- repo: https://github.com/psf/black
rev: 23.9.0
hooks:
- id: black
args: [ --check, --diff, --quiet ]
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [ --check-only ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
exclude: ^tests/
- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.13.3
hooks:
- id: pymarkdown
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks/
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-case-conflict
- id: check-docstring-first
\ No newline at end of file
=======
Credits
=======
Development Lead
----------------
* Dorian Turba <contact.r9qrp@8shield.net>
Contributors
------------
None yet. Why not be the first?
# Who is concerned by this file
[//]: # (For a guide to create CONTRIBUTING.md, see http://mozillascience.github.io/working-open-workshop/contributing/)
This file is for:
- Project owners - creators and maintainers of the project
- Project contributors - users of the project who want to know items they're welcome to
tackle, and tact they need in navigating the project/respecting those involved with
the project
- Project consumers - users who want to build off the project to create their own
project
## Testing
### Installation
```bash
pip install --upgrade pip
pip install -e .[ALL]
pre-commit install
```
Run pre-commit hooks on all files:
```bash
pre-commit autoupdate
pre-commit run --all-files
```
This will run the following hooks:
- `black`
- `flake8`
- `isort`
- `mypy`
### Running tests
```bash
pytest
```
## Generating distribution archives
```bash
pip install --upgrade build
python -m build
```
## Pypi share
```bash
pip install --upgrade twine
python -m twine upload --repository pypi dist/*
```
You will be prompted for a username and password. For the username, use __token__. For
the password, use the token value, including the pypi- prefix.
LICENCE 0 → 100644
MIT License
Copyright (c) 2023 Dorian Turba
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Requirement Compare
A CLI that generate a version changelog based on git history and local requirement file.
build>=0.9.0
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "requirement_compare"
version = "0.1.0"
authors = [
{ name = "Dorian Turba", email = "contact.r9qrp@8shield.net" },
]
description = "A CLI that generate a version changelog based on git history and local requirement file."
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Typing :: Typed",
]
dependencies = [
"typer[all]",
]
[project.urls]
"Homepage" = "https://lab.frogg.it/swepy/requirement-compare"
"Bug Tracker" = "https://lab.frogg.it/swepy/requirement-compare"
[project.optional-dependencies]
ALL = ["requirement_compare[QUALITY]", "requirement_compare[TEST]"]
QUALITY = [
"black",
"flake8",
"mypy",
"isort",
"ruff",
"pre-commit",
]
TEST = [
"pytest",
"coverage",
]
[project.scripts]
requirement_compare = "requirement_compare:app"
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-rA -q"
testpaths = [
"tests",
"integration",
]
[tool.black]
line-length = 88
[tool.mypy]
packages = "requirement_compare"
python_version = 3.11
disallow_untyped_defs = true
[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
env_list =
py{38,39,310,311,312}
black
flake8
mypy
isolated_build = true
[testenv]
deps = pytest
commands = pytest
[testenv:black]
deps = black
commands = black --check .
[testenv:flake8]
deps = flake8
commands = flake8
[testenv:mypy]
deps = mypy
commands = mypy src
"""
[tool.pymarkdown]
strict-config = true
plugins.line-length.line_length = 88
from requirement_compare.main import app, main
__all__ = ["app", "main"]
import argparse
import io
import pathlib
import subprocess
import typing
import packaging.requirements
import packaging.specifiers
import typer
app = typer.Typer(pretty_exceptions_enable=False)
class OldNewRequirements(typing.NamedTuple):
old: packaging.requirements.Requirement
new: packaging.requirements.Requirement
def clean_lines(f: io.TextIOWrapper) -> typing.Generator[str, None, None]:
for line in f:
# remove comments and hashes
# because packaging.requirements.Requirement can't read hashes
# and comments are useless here
if not line.lstrip().startswith(("#", "--hash")):
yield line.rstrip("\n").rstrip("\\")
def retrieve_equal_version(
specifier: packaging.specifiers.SpecifierSet,
) -> packaging.specifiers.Specifier:
"""
:raises ValueError: if no equal version is found
"""
for s in specifier:
if s.operator == "==":
return s
raise ValueError("No equal version found")
def retrieve_requirements(file: pathlib.Path) -> io.StringIO:
p = subprocess.run(
["git", "show", f"HEAD:{file.name}"],
stdout=subprocess.PIPE,
)
content = io.StringIO(p.stdout.decode())
return content
def compare_requirements(
requirements: pathlib.Path,
) -> tuple[
set[packaging.requirements.Requirement],
set[
OldNewRequirements[
packaging.requirements.Requirement, packaging.requirements.Requirement
]
],
set[packaging.requirements.Requirement],
]:
try:
with requirements.open() as file:
set_after = {
packaging.requirements.Requirement(line) for line in clean_lines(file)
}
except FileNotFoundError:
raise FileNotFoundError(f"default requirement file {requirements} not found")
set_before = {
packaging.requirements.Requirement(line)
for line in clean_lines(retrieve_requirements(requirements))
}
new_requirements = {
requirement.name: requirement
for requirement in set_after.difference(set_before)
}
old_requirements = {
requirement.name: requirement
for requirement in set_before.difference(set_after)
}
added_requirements = {
requirement
for package_name, requirement in new_requirements.items()
if package_name not in old_requirements
}
updated_requirements = {
OldNewRequirements(old_requirements[package_name], requirement)
for package_name, requirement in new_requirements.items()
if package_name in old_requirements
}
removed_requirements = {
requirement
for package_name, requirement in old_requirements.items()
if package_name not in new_requirements
}
return added_requirements, updated_requirements, removed_requirements
def parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
"requirements_file",
nargs="?",
default=pathlib.Path("requirements.txt"),
type=pathlib.Path,
)
parser.add_argument(
"-o",
nargs="?",
default=pathlib.Path("description.md"),
type=pathlib.Path,
required=False,
)
return parser
def generate_changes(
added_requirements: set[packaging.requirements.Requirement],
updated: set[
OldNewRequirements[
packaging.requirements.Requirement,
packaging.requirements.Requirement,
]
],
removed: set[packaging.requirements.Requirement],
) -> str:
description = (
[
f"- Added `{requirement.name}` version "
f"`{retrieve_equal_version(requirement.specifier).version}`"
for requirement in added_requirements
]
+ [
f"- Bump `{requirements.old.name}` from "
f"`{retrieve_equal_version(requirements.old.specifier).version}` to "
f"`{retrieve_equal_version(requirements.new.specifier).version}`"
for requirements in updated
]
+ [
f"- Removed `{requirement.name}` version "
f"`{retrieve_equal_version(requirement.specifier).version}`"
for requirement in removed
]
)
return "\r\n".join(description)
@app.command()
def main(
requirements_file: pathlib.Path = pathlib.Path("requirements.txt"),
output_file: pathlib.Path = pathlib.Path("description.md"),
) -> None:
added, updated, removed = compare_requirements(requirements_file)
with output_file.open("w") as file:
typer.echo(generate_changes(added, updated, removed), file=file)
if __name__ == "__main__":
app()
"""Sample test module."""
from requirement_compare import main
def test_main():
"""Test main function."""
assert main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment