Skip to content

Commit

Permalink
Apply black and isort formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Sep 11, 2024
1 parent 01b1664 commit 5283ef7
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 606 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ dev:

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

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

doc8:
@echo "-> Run doc8 validation"
Expand All @@ -33,11 +33,11 @@ valid: isort black

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

clean:
@echo "-> Clean the Python env"
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ docs =
sphinx-rtd-dark-mode>=1.3.0
sphinx-copybutton

[pycodestyle]
max-line-length = 88
ignore = E203,E701
31 changes: 15 additions & 16 deletions src/fetchcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from ftplib import FTP
from mimetypes import MimeTypes
import os
import tempfile
from ftplib import FTP
from mimetypes import MimeTypes
from urllib.parse import urlparse

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

def fetch_http(url, location):
"""
Return a `Response` object built from fetching the content at a HTTP/HTTPS based `url` URL string
saving the content in a file at `location`
Return a `Response` object built from fetching the content at a HTTP/HTTPS based
`url` URL string saving the content in a file at `location`
"""
r = requests.get(url)
with open(location, 'wb') as f:
with open(location, "wb") as f:
f.write(r.content)

content_type = r.headers.get('content-type')
size = r.headers.get('content-length')
content_type = r.headers.get("content-type")
size = r.headers.get("content-length")
size = int(size) if size else None

resp = Response(location=location,
content_type=content_type, size=size, url=url)
resp = Response(location=location, content_type=content_type, size=size, url=url)

return resp

Expand Down Expand Up @@ -80,19 +79,19 @@ def fetch_ftp(url, location):
content_type = None

ftp.cwd(dir)
file = 'RETR {}'.format(file)
with open(location, 'wb') as f:
file = "RETR {}".format(file)
with open(location, "wb") as f:
ftp.retrbinary(file, f.write)
ftp.close()

resp = Response(location=location,
content_type=content_type, size=size, url=url)
resp = Response(location=location, content_type=content_type, size=size, url=url)
return resp


def fetch(url):
"""
Return a `Response` object built from fetching the content at the `url` URL string and store content at a temporary file.
Return a `Response` object built from fetching the content at the `url` URL string and
store content at a temporary file.
"""

temp = tempfile.NamedTemporaryFile(delete=False)
Expand All @@ -101,9 +100,9 @@ def fetch(url):
url_parts = urlparse(url)
scheme = url_parts.scheme

fetchers = {'ftp': fetch_ftp, 'http': fetch_http, 'https': fetch_http}
fetchers = {"ftp": fetch_ftp, "http": fetch_http, "https": fetch_http}

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

raise Exception('Not a supported/known scheme.')
raise Exception("Not a supported/known scheme.")
Loading

0 comments on commit 5283ef7

Please sign in to comment.