Skip to content

Commit 5283ef7

Browse files
committed
Apply black and isort formatting
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 01b1664 commit 5283ef7

19 files changed

+538
-606
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ dev:
1919

2020
isort:
2121
@echo "-> Apply isort changes to ensure proper imports ordering"
22-
${VENV}/bin/isort --sl -l 100 src tests setup.py
22+
${VENV}/bin/isort --sl -l 100 --skip=src/fetchcode/vcs/pip setup.py src tests
2323

2424
black:
2525
@echo "-> Apply black code formatter"
26-
${VENV}/bin/black -l 100 src tests setup.py
26+
${VENV}/bin/black -l 100 --exclude=src/fetchcode/vcs/pip src tests setup.py
2727

2828
doc8:
2929
@echo "-> Run doc8 validation"
@@ -33,11 +33,11 @@ valid: isort black
3333

3434
check:
3535
@echo "-> Run pycodestyle (PEP8) validation"
36-
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache .
36+
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache,etc,src/fetchcode/vcs/pip,tests/data/ .
3737
@echo "-> Run isort imports ordering validation"
38-
@${ACTIVATE} isort --sl --check-only -l 100 setup.py src tests .
38+
@${ACTIVATE} isort --sl --check-only -l 100 --skip=src/fetchcode/vcs/pip setup.py src tests
3939
@echo "-> Run black validation"
40-
@${ACTIVATE} black --check --check -l 100 src tests setup.py
40+
@${ACTIVATE} black --check --check -l 100 --exclude=src/fetchcode/vcs/pip src tests setup.py
4141

4242
clean:
4343
@echo "-> Clean the Python env"

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ docs =
8484
sphinx-rtd-dark-mode>=1.3.0
8585
sphinx-copybutton
8686

87+
[pycodestyle]
88+
max-line-length = 88
89+
ignore = E203,E701

src/fetchcode/__init__.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations under the License.
1616

17-
from ftplib import FTP
18-
from mimetypes import MimeTypes
1917
import os
2018
import tempfile
19+
from ftplib import FTP
20+
from mimetypes import MimeTypes
2121
from urllib.parse import urlparse
2222

2323
import requests
@@ -40,19 +40,18 @@ def __init__(self, location, content_type, size, url):
4040

4141
def fetch_http(url, location):
4242
"""
43-
Return a `Response` object built from fetching the content at a HTTP/HTTPS based `url` URL string
44-
saving the content in a file at `location`
43+
Return a `Response` object built from fetching the content at a HTTP/HTTPS based
44+
`url` URL string saving the content in a file at `location`
4545
"""
4646
r = requests.get(url)
47-
with open(location, 'wb') as f:
47+
with open(location, "wb") as f:
4848
f.write(r.content)
4949

50-
content_type = r.headers.get('content-type')
51-
size = r.headers.get('content-length')
50+
content_type = r.headers.get("content-type")
51+
size = r.headers.get("content-length")
5252
size = int(size) if size else None
5353

54-
resp = Response(location=location,
55-
content_type=content_type, size=size, url=url)
54+
resp = Response(location=location, content_type=content_type, size=size, url=url)
5655

5756
return resp
5857

@@ -80,19 +79,19 @@ def fetch_ftp(url, location):
8079
content_type = None
8180

8281
ftp.cwd(dir)
83-
file = 'RETR {}'.format(file)
84-
with open(location, 'wb') as f:
82+
file = "RETR {}".format(file)
83+
with open(location, "wb") as f:
8584
ftp.retrbinary(file, f.write)
8685
ftp.close()
8786

88-
resp = Response(location=location,
89-
content_type=content_type, size=size, url=url)
87+
resp = Response(location=location, content_type=content_type, size=size, url=url)
9088
return resp
9189

9290

9391
def fetch(url):
9492
"""
95-
Return a `Response` object built from fetching the content at the `url` URL string and store content at a temporary file.
93+
Return a `Response` object built from fetching the content at the `url` URL string and
94+
store content at a temporary file.
9695
"""
9796

9897
temp = tempfile.NamedTemporaryFile(delete=False)
@@ -101,9 +100,9 @@ def fetch(url):
101100
url_parts = urlparse(url)
102101
scheme = url_parts.scheme
103102

104-
fetchers = {'ftp': fetch_ftp, 'http': fetch_http, 'https': fetch_http}
103+
fetchers = {"ftp": fetch_ftp, "http": fetch_http, "https": fetch_http}
105104

106105
if scheme in fetchers:
107106
return fetchers.get(scheme)(url, location)
108107

109-
raise Exception('Not a supported/known scheme.')
108+
raise Exception("Not a supported/known scheme.")

0 commit comments

Comments
 (0)