Skip to content

Commit

Permalink
create poetry-export hook
Browse files Browse the repository at this point in the history
  • Loading branch information
avlm committed Oct 1, 2020
1 parent 59cb877 commit bcc67e9
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 1 deletion.
Empty file added .gitignore
Empty file.
5 changes: 5 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- id: poetry-export
name: poetry export
description: pre-commit hook to keep requirements.txt updated
entry: poetry-export
language: python
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# pre-commit-poetry-export
Pre-commit hook to keep requirements.txt updated
pre-commit hook to keep requirements.txt updated

- [] write readme
- [] test
Binary file added dist/pre-commit-poetry-export-0.1.1.tar.gz
Binary file not shown.
Binary file not shown.
220 changes: 220 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pre_commit_poetry_export/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
30 changes: 30 additions & 0 deletions pre_commit_poetry_export/poetry_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import hashlib
import os


def main(argv=None):
os.system('cp requirements.txt old.requirements.txt')
os.system('poetry export -f requirements.txt > requirements.txt')

with open('requirements.txt', 'r') as new,\
open('old.requirements.txt', 'r') as old:
new_content = new.read()
new.close()
new_md5 = hashlib.md5()
new_md5.update(new_content.encode('utf-8'))

old_content = old.read()
old.close()
old_md5 = hashlib.md5()
old_md5.update(old_content.encode('utf-8'))

if new_md5.hexdigest() == old_md5.hexdigest():
os.system('rm old.requirements.txt')
return 0

print('requirements.txt updated!')
return 1


if __name__ == '__name__':
exit(main())
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "pre-commit-poetry-export"
version = "0.1.1"
description = "pre-commit hook to keep requirements.txt updated"
authors = ["Antonio Luckwu <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/avlm/pre-commit-poetry-export"
repository = "https://github.com/avlm/pre-commit-poetry-export"
keywords = ["pre-commit", "hook", "poetry", "export", "pip", "requirements", "requirements.txt"]
classifiers = [
"Environment :: Console",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
]
include = [
"LICENSE",
]

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

[tool.poetry.dev-dependencies]
pytest = "^5.2"
flake8 = "^3.8.3"

[tool.poetry.scripts]
poetry-export = 'pre_commit_poetry_export.poetry_export:main'

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Empty file added tests/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions tests/test_pre_commit_poetry_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pre_commit_poetry_export import __version__


def test_version():
assert __version__ == '0.1.0'

0 comments on commit bcc67e9

Please sign in to comment.