Skip to content

Commit

Permalink
Merge pull request #1 from rzuckerm/reproducible-builds
Browse files Browse the repository at this point in the history
feat: Add reproducible builds
  • Loading branch information
rzuckerm authored Oct 11, 2021
2 parents 433641e + 4a4df1c commit 7325472
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
24 changes: 24 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Developing

## Installing

You will need to install `tox` like this:

```
python3 -m pip install --user tox
```

## Testing

```
tox -e pre-commit
tox -e py36
tox -e py37
tox -e py38
```

## Update requirements in setup.cfg

```
tox -e py36-update-requirements
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Some out-of-the-box hooks for pre-commit.

See also: https://github.com/pre-commit/pre-commit

This is a fork of https://github.com/pre-commit/pre-commit-hooks modified for build reproducibility.

### Using pre-commit-hooks with pre-commit

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruamel.yaml>=0.15
toml
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pre_commit_hooks
version = 4.0.1
version = 4.0.1a0
description = Some out-of-the-box hooks for pre-commit.
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -24,8 +24,9 @@ classifiers =
[options]
packages = find:
install_requires =
ruamel.yaml>=0.15
toml
ruamel.yaml==0.17.16
ruamel.yaml.clib==0.2.6
toml==0.10.2
python_requires = >=3.6.1

[options.packages.find]
Expand Down
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py36,py37,py38,pypy3,pre-commit
envlist = py36,py37,py38,pypy3,pre-commit,py36-update-requirements

[testenv]
deps = -rrequirements-dev.txt
Expand All @@ -10,14 +10,19 @@ setenv =
GIT_COMMITTER_EMAIL = "[email protected]"
commands =
coverage erase
coverage run -m pytest {posargs:tests}
coverage run --source pre_commit_hooks -m pytest {posargs:tests}
coverage report --fail-under 100

[testenv:pre-commit]
skip_install = true
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure

[testenv:py36-update-requirements]
skip_install = true
deps = -rrequirements.txt
commands = python update_requirements.py

[pep8]
ignore=E265,E501,W504

Expand Down
37 changes: 37 additions & 0 deletions update_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import subprocess
from configparser import ConfigParser

print('*** Generate requirements.lock ***')
subprocess.run('pip freeze >requirements.lock', shell=True, check=True)
with open('requirements.lock') as f:
requirements = [
line for line in f.read().strip().splitlines()
if not line.startswith('pre-commit')
]
print('\n'.join(requirements))

os.remove('requirements.lock')
print()

# Read setup.cfg, replace install_requires value with requirements.lock, and
# write setup.cfg
parser = ConfigParser()
parser.read('setup.cfg')
requirements_str = ''.join(f'\n{requirement}' for requirement in requirements)
parser.set('options', 'install_requires', requirements_str)
with open('setup.cfg', 'w') as f:
parser.write(f)

# Clean up setup.cfg
with open('setup.cfg') as f:
setup_cfg = [
line.replace('\t', ' ').rstrip()
for line in f.read().splitlines()
]


with open('setup.cfg', 'w') as f:
f.write('\n'.join(setup_cfg))

print('setup.cfg has been updated. Please commit this change')

0 comments on commit 7325472

Please sign in to comment.