Skip to content

Commit c0f3665

Browse files
authored
Merge pull request #120 from cisagov/bugfix/fix_run_script
Resolve Issue with run Script
2 parents 830cc7a + b0d6c3c commit c0f3665

File tree

11 files changed

+608
-365
lines changed

11 files changed

+608
-365
lines changed

.flake8

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[flake8]
2+
max-line-length = 80
3+
# Select (turn on)
4+
# * Complexity violations reported by mccabe (C) -
5+
# http://flake8.pycqa.org/en/latest/user/error-codes.html#error-violation-codes
6+
# * Documentation conventions compliance reported by pydocstyle (D) -
7+
# http://www.pydocstyle.org/en/stable/error_codes.html
8+
# * Default errors and warnings reported by pycodestyle (E and W) -
9+
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
10+
# * Default errors reported by pyflakes (F) -
11+
# http://flake8.pycqa.org/en/latest/glossary.html#term-pyflakes
12+
# * Default warnings reported by flake8-bugbear (B) -
13+
# https://github.com/PyCQA/flake8-bugbear#list-of-warnings
14+
# * The B950 flake8-bugbear opinionated warning -
15+
# https://github.com/PyCQA/flake8-bugbear#opinionated-warnings
16+
select = C,D,E,F,W,B,B950
17+
# Ignore flake8's default warning about maximum line length, which has
18+
# a hard stop at the configured value. Instead we use
19+
# flake8-bugbear's B950, which allows up to 10% overage.
20+
#
21+
# Also ignore flake8's warning about line breaks before binary
22+
# operators. It no longer agrees with PEP8. See, for example, here:
23+
# https://github.com/ambv/black/issues/21. Guido agrees here:
24+
# https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b.
25+
ignore = E501,W503

.travis.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
language: python
22

3+
dist: xenial
4+
35
services:
46
- docker
57

@@ -9,22 +11,17 @@ env:
911
- DOCKER_USER=jsf9k
1012
- secure: "IAbtmubLq2hL71aollQEfoV+t9Zbqn4rNVqi5YNerqxvXr6WiDzwmYUujOCnQiHli8xkIU0J8OSPX0aA4cOTxPGiZeNguGuVWmR2ZCB8SMyjbKJOEIpLZv/jG1Be6dVXiJwKwQM3yX4pqPfLIuYkE6S1GAodudPzcJ8xM/h1qzJijknJEqsCJQw43zSHZ/epYulgWcmnCAmaoehZTCjVcW4l8iyVHSNfgO7gu5iWC9y4AIIX96E9TZkSDeud1yqUcORMwfdOl2pHhDh3KnF8HZSOCetTHP7JacLUMJiiCpKN34Xn9RQgjbVKOrF/rcC8WEDrWKn14SFfgUP0dl6lCr6P9HE4aHKvrH/nCyflFOANbEKMywE8DzNA3zd7MC0HQkyb40LAiBSbTD58myUsc+WlmaZyvpJ7akukbmVjVPQWNvs1laz/bqyLdPh4WMqgOTbP7BrgDeIrCVedwdvhqq9KEaoak8RBs/Wb8LisI6j+vAY/HKlVnuIXRL0RNGTko96kBluEpAsWDjls39Hmu5hl1glbqCWDW9+dE0/Zx4MuSt4OVAywMW+lzxA16SdqDLCZqGv00vnPpxuBAvEEQbVtsmQ6lR+fwTYKFEDZM7axRwBlLzIDEzSoz4K0fSq3EuU4mkoVZKcHGnuHuRqaNhce0zzZx3lHdNTm7oa7b0U="
1113

12-
# Matrix approach here due to: https://github.com/travis-ci/travis-ci/issues/9815
13-
matrix:
14-
include:
15-
- python: 3.6
16-
dist: xenial
17-
sudo: true
18-
- python: 3.7
19-
dist: xenial
20-
sudo: true
14+
python:
15+
- 3.6
16+
- 3.7
17+
- 3.8
2118

2219
before_install:
2320
- sudo apt-get install -y shellcheck
2421

2522
install:
2623
- pip install flake8 pytest-cov pytest coveralls
27-
- pip install -e .
24+
- pip install --editable .
2825

2926
script:
3027
- shellcheck bump_version.sh tag.sh travis_scripts/*.sh
@@ -43,7 +40,7 @@ deploy:
4340
distributions: sdist bdist_wheel
4441
on:
4542
tags: true
46-
python: '3.7'
43+
python: '3.8'
4744
# - provider: script
4845
# script: bash travis_scripts/deploy_to_docker_hub.sh
4946
# on:

Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ FROM python:3
22

33
WORKDIR /app
44

5-
COPY requirements.txt requirements.txt
5+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
66

7-
RUN pip install --no-cache-dir -r requirements.txt
7+
COPY requirements.txt .
88

9-
COPY . .
9+
RUN pip install --no-cache-dir --requirement requirements.txt
10+
11+
COPY scripts/ scripts/
12+
13+
COPY trustymail/ trustymail/
14+
15+
COPY README.md .
16+
17+
COPY requirements-dev.txt .
18+
19+
COPY setup.py .
1020

1121
RUN pip install --editable .
1222

bump_version.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ VERSION_FILE=trustymail/__init__.py
1010

1111
HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"
1212

13-
old_version=$(sed -n "s/^__version__ = '\(.*\)'$/\1/p" $VERSION_FILE)
13+
old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)
1414

1515
if [ $# -ne 1 ]
1616
then
@@ -20,17 +20,25 @@ else
2020
major|minor|patch|prerelease|build)
2121
new_version=$(python -c "import semver; print(semver.bump_$1('$old_version'))")
2222
echo Changing version from "$old_version" to "$new_version"
23-
sed -i "s/$old_version/$new_version/" $VERSION_FILE
23+
# A temp file is used to provide compatability with macOS development
24+
# as a result of macOS using the BSD version of sed
25+
tmp_file=/tmp/version.$$
26+
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
27+
mv $tmp_file $VERSION_FILE
2428
git add $VERSION_FILE
2529
git commit -m"Bump version from $old_version to $new_version"
2630
git push
2731
;;
2832
finalize)
2933
new_version=$(python -c "import semver; print(semver.finalize_version('$old_version'))")
3034
echo Changing version from "$old_version" to "$new_version"
31-
sed -i "s/$old_version/$new_version/" $VERSION_FILE
35+
# A temp file is used to provide compatability with macOS development
36+
# as a result of macOS using the BSD version of sed
37+
tmp_file=/tmp/version.$$
38+
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
39+
mv $tmp_file $VERSION_FILE
3240
git add $VERSION_FILE
33-
git commit -m"Finalize version from $old_version to $new_version"
41+
git commit -m"Bump version from $old_version to $new_version"
3442
git push
3543
;;
3644
show)

run

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ docker build -t trustymail/cli .
77

88
docker run --rm -it \
99
--name trustymail \
10-
-v $(pwd):/app \
11-
trustymail/cli $@
10+
--volume "$(pwd)":/workspace \
11+
--workdir="/workspace" \
12+
--user "$(id -u)" \
13+
trustymail/cli "$@"

scripts/trustymail

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,97 +68,105 @@ def main():
6868
args = docopt.docopt(__doc__, version=trustymail.__version__)
6969

7070
# Monkey patching trustymail to make it cache the PSL where we want
71-
if args['--psl-filename'] is not None:
72-
trustymail.PublicSuffixListFilename = args['--psl-filename']
71+
if args["--psl-filename"] is not None:
72+
trustymail.PublicSuffixListFilename = args["--psl-filename"]
7373
# Monkey patching trustymail to make the PSL cache read-only
74-
if args['--psl-read-only']:
74+
if args["--psl-read-only"]:
7575
trustymail.PublicSuffixListReadOnly = True
7676
import trustymail.trustymail as tmail
7777

7878
log_level = logging.WARN
79-
if args['--debug']:
79+
if args["--debug"]:
8080
log_level = logging.DEBUG
81-
logging.basicConfig(format='%(asctime)-15s %(message)s', level=log_level)
81+
logging.basicConfig(format="%(asctime)-15s %(message)s", level=log_level)
8282

8383
# Allow for user to input a csv for many domain names.
84-
if args['INPUT'][0].endswith('.csv'):
85-
domains = tmail.domain_list_from_csv(open(args['INPUT'][0]))
84+
if args["INPUT"][0].endswith(".csv"):
85+
domains = tmail.domain_list_from_csv(open(args["INPUT"][0]))
8686
else:
87-
domains = args['INPUT']
87+
domains = args["INPUT"]
8888

89-
if args['--timeout'] is not None:
90-
timeout = int(args['--timeout'])
89+
if args["--timeout"] is not None:
90+
timeout = int(args["--timeout"])
9191
else:
9292
timeout = 5
9393

94-
if args['--smtp-timeout'] is not None:
95-
smtp_timeout = int(args['--smtp-timeout'])
94+
if args["--smtp-timeout"] is not None:
95+
smtp_timeout = int(args["--smtp-timeout"])
9696
else:
9797
smtp_timeout = 5
9898

99-
if args['--smtp-localhost'] is not None:
100-
smtp_localhost = args['--smtp-localhost']
99+
if args["--smtp-localhost"] is not None:
100+
smtp_localhost = args["--smtp-localhost"]
101101
else:
102102
smtp_localhost = None
103103

104-
if args['--smtp-ports'] is not None:
105-
smtp_ports = {int(port) for port in args['--smtp-ports'].split(',')}
104+
if args["--smtp-ports"] is not None:
105+
smtp_ports = {int(port) for port in args["--smtp-ports"].split(",")}
106106
else:
107107
smtp_ports = _DEFAULT_SMTP_PORTS
108108

109-
if args['--dns'] is not None:
110-
dns_hostnames = args['--dns'].split(',')
109+
if args["--dns"] is not None:
110+
dns_hostnames = args["--dns"].split(",")
111111
else:
112112
dns_hostnames = None
113113

114114
# --starttls implies --mx
115-
if args['--starttls']:
116-
args['--mx'] = True
115+
if args["--starttls"]:
116+
args["--mx"] = True
117117

118118
# User might not want every scan performed.
119119
scan_types = {
120-
'mx': args['--mx'],
121-
'starttls': args['--starttls'],
122-
'spf': args['--spf'],
123-
'dmarc': args['--dmarc']
120+
"mx": args["--mx"],
121+
"starttls": args["--starttls"],
122+
"spf": args["--spf"],
123+
"dmarc": args["--dmarc"],
124124
}
125125

126126
domain_scans = []
127127
for domain_name in domains:
128-
domain_scans.append(tmail.scan(domain_name, timeout,
129-
smtp_timeout, smtp_localhost,
130-
smtp_ports, not args['--no-smtp-cache'],
131-
scan_types, dns_hostnames))
128+
domain_scans.append(
129+
tmail.scan(
130+
domain_name,
131+
timeout,
132+
smtp_timeout,
133+
smtp_localhost,
134+
smtp_ports,
135+
not args["--no-smtp-cache"],
136+
scan_types,
137+
dns_hostnames,
138+
)
139+
)
132140

133141
# Default output file name is results.
134-
if args['--output'] is None:
135-
output_file_name = 'results'
142+
if args["--output"] is None:
143+
output_file_name = "results"
136144
else:
137-
output_file_name = args['--output']
145+
output_file_name = args["--output"]
138146

139147
# Ensure file extension is present in filename.
140-
if args['--json'] and '.json' not in output_file_name:
141-
output_file_name += '.json'
142-
elif '.csv' not in output_file_name:
143-
output_file_name += '.csv'
148+
if args["--json"] and ".json" not in output_file_name:
149+
output_file_name += ".json"
150+
elif ".csv" not in output_file_name:
151+
output_file_name += ".csv"
144152

145-
if args['--json']:
153+
if args["--json"]:
146154
json_out = tmail.generate_json(domain_scans)
147-
if args['--output'] is None:
155+
if args["--output"] is None:
148156
print(json_out)
149157
else:
150158
write(json_out, output_file_name)
151-
logging.warn('Wrote results to %s.' % output_file_name)
159+
logging.warn("Wrote results to %s." % output_file_name)
152160
else:
153161
tmail.generate_csv(domain_scans, output_file_name)
154162

155163

156164
def write(content, out_file):
157165
parent = os.path.dirname(out_file)
158-
if parent is not '':
166+
if parent != "":
159167
mkdir_p(parent)
160168

161-
f = open(out_file, 'w') # no utf-8 in python 2
169+
f = open(out_file, "w") # no utf-8 in python 2
162170
f.write(content)
163171
f.close()
164172

@@ -175,5 +183,5 @@ def mkdir_p(path):
175183
raise
176184

177185

178-
if __name__ == '__main__':
186+
if __name__ == "__main__":
179187
main()

setup.py

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,55 @@
1111

1212

1313
def readme():
14-
with open('README.md') as f:
14+
with open("README.md") as f:
1515
return f.read()
1616

1717

18-
with open('requirements.txt') as fp:
18+
with open("requirements.txt") as fp:
1919
reqs = [line.strip() for line in fp.readlines() if line]
2020

21-
with open('requirements-dev.txt') as fp:
21+
with open("requirements-dev.txt") as fp:
2222
lines = [line.strip() for line in fp.readlines() if line]
23-
dev_reqs = [line for line in lines if line and '-r requirements.txt' not in line]
23+
dev_reqs = [line for line in lines if line and "-r requirements.txt" not in line]
2424

2525

2626
setup(
27-
name='trustymail',
27+
name="trustymail",
2828
version=__version__,
29-
description='Scan domains and return data based on trustworthy email best practices',
29+
description="Scan domains and return data based on trustworthy email best practices",
3030
long_description=readme(),
31-
long_description_content_type='text/markdown',
32-
31+
long_description_content_type="text/markdown",
3332
# NCATS "homepage"
3433
url="https://www.us-cert.gov/resources/ncats",
3534
# The project's main homepage
36-
download_url='https://github.com/cisagov/trustymail',
37-
35+
download_url="https://github.com/cisagov/trustymail",
3836
# Author details
39-
author='Cyber and Infrastructure Security Agency',
40-
author_email='[email protected]',
41-
42-
license='License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
43-
37+
author="Cyber and Infrastructure Security Agency",
38+
author_email="[email protected]",
39+
license="License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
4440
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
4541
classifiers=[
4642
# How mature is this project? Common values are
4743
# 3 - Alpha
4844
# 4 - Beta
4945
# 5 - Production/Stable
50-
'Development Status :: 4 - Beta',
51-
46+
"Development Status :: 4 - Beta",
5247
# Indicate who your project is intended for
53-
'Intended Audience :: Developers',
54-
48+
"Intended Audience :: Developers",
5549
# Pick your license as you wish (should match "license" above)
56-
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
57-
50+
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
5851
# Specify the Python versions you support here. In particular, ensure
5952
# that you indicate whether you support Python 2, Python 3 or both.
60-
'Programming Language :: Python :: 3',
61-
'Programming Language :: Python :: 3.6',
62-
'Programming Language :: Python :: 3.7',
53+
"Programming Language :: Python :: 3",
54+
"Programming Language :: Python :: 3.6",
55+
"Programming Language :: Python :: 3.7",
56+
"Programming Language :: Python :: 3.8",
6357
],
64-
58+
python_requires=">=3.6",
6559
# What does your project relate to?
66-
keywords='email authentication, STARTTLS',
67-
68-
packages=['trustymail'],
69-
60+
keywords="email authentication, STARTTLS",
61+
packages=["trustymail"],
7062
install_requires=reqs,
71-
72-
extras_require={
73-
'dev': dev_reqs,
74-
},
75-
76-
scripts=['scripts/trustymail']
63+
extras_require={"dev": dev_reqs},
64+
scripts=["scripts/trustymail"],
7765
)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py34,py35,py36,py37,flake8
2+
envlist = py36,py37,py38,flake8
33
skip_missing_interpreters = true
44
; usedevelop = true
55

0 commit comments

Comments
 (0)