Skip to content

Commit

Permalink
Local linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jash Parekh committed Dec 28, 2020
1 parent f60d6d7 commit be5bee6
Show file tree
Hide file tree
Showing 31 changed files with 185 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/
.git/
venv/
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-complexity = 10
builtins = unicode
tee = True
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ dmypy.json

# Pyre type checker
.pyre/

# PyCharm
.idea
*.iml
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile=black
atomic=true
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.4"
services:

# "devbox" to enable the developer to have a fully loaded development environment
devbox: &devbox
build:
dockerfile: "./docker/devbox.dockerfile"
context: "."
tty: true
volumes:
- "./:/app"

lint:
<<: *devbox
entrypoint: "docker/lint.sh"
11 changes: 11 additions & 0 deletions docker/devbox.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:latest

RUN apt-get update
#RUN apt-get upgrade -y
RUN apt-get install -y python3 python3-pip
RUN python3 -m pip install parse realpython-reader

COPY . /app
WORKDIR /app

RUN python3 -m pip install -r requirements-test.txt
11 changes: 11 additions & 0 deletions docker/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

echo "Running flake8..."
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

echo "Running bandit..."
bandit -r instagrapi

echo "Running isort..."
isort instagrapi
30 changes: 15 additions & 15 deletions instagrapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import logging
from urllib.parse import urlparse

from instagrapi.mixins.account import AccountMixin
from instagrapi.mixins.album import DownloadAlbumMixin, UploadAlbumMixin
from instagrapi.mixins.auth import LoginMixin
from instagrapi.mixins.challenge import ChallengeResolveMixin
from instagrapi.mixins.collection import CollectionMixin
from instagrapi.mixins.comment import CommentMixin
from instagrapi.mixins.direct import DirectMixin
from instagrapi.mixins.hashtag import HashtagMixin
from instagrapi.mixins.igtv import DownloadIGTVMixin, UploadIGTVMixin
from instagrapi.mixins.insights import InsightsMixin
from instagrapi.mixins.location import LocationMixin
from instagrapi.mixins.media import MediaMixin
from instagrapi.mixins.photo import DownloadPhotoMixin, UploadPhotoMixin
from instagrapi.mixins.private import PrivateRequestMixin
from instagrapi.mixins.public import (
ProfilePublicMixin,
PublicRequestMixin,
TopSearchesPublicMixin,
ProfilePublicMixin
)
from instagrapi.mixins.private import PrivateRequestMixin
from instagrapi.mixins.challenge import ChallengeResolveMixin
from instagrapi.mixins.photo import DownloadPhotoMixin, UploadPhotoMixin
from instagrapi.mixins.video import DownloadVideoMixin, UploadVideoMixin
from instagrapi.mixins.album import DownloadAlbumMixin, UploadAlbumMixin
from instagrapi.mixins.igtv import DownloadIGTVMixin, UploadIGTVMixin
from instagrapi.mixins.media import MediaMixin
from instagrapi.mixins.user import UserMixin
from instagrapi.mixins.insights import InsightsMixin
from instagrapi.mixins.collection import CollectionMixin
from instagrapi.mixins.account import AccountMixin
from instagrapi.mixins.direct import DirectMixin
from instagrapi.mixins.location import LocationMixin
from instagrapi.mixins.hashtag import HashtagMixin
from instagrapi.mixins.comment import CommentMixin
from instagrapi.mixins.video import DownloadVideoMixin, UploadVideoMixin


class Client(
Expand Down
20 changes: 14 additions & 6 deletions instagrapi/extractors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from copy import deepcopy

from .utils import json_value
from .types import (
Media, Resource, User, UserShort, Usertag,
Location, Collection, Comment, MediaOembed,
DirectThread, DirectMessage, Account,
Hashtag
Account,
Collection,
Comment,
DirectMessage,
DirectThread,
Hashtag,
Location,
Media,
MediaOembed,
Resource,
User,
UserShort,
Usertag,
)

from .utils import json_value

MEDIA_TYPES_GQL = {
"GraphImage": 1,
Expand Down
7 changes: 4 additions & 3 deletions instagrapi/mixins/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import requests
from pathlib import Path
from json.decoder import JSONDecodeError
from pathlib import Path

import requests

from instagrapi.exceptions import ClientLoginRequired, ClientError
from instagrapi.exceptions import ClientError, ClientLoginRequired
from instagrapi.extractors import extract_account, extract_user_short
from instagrapi.types import Account, UserShort
from instagrapi.utils import gen_csrftoken
Expand Down
9 changes: 5 additions & 4 deletions instagrapi/mixins/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from typing import List
from urllib.parse import urlparse

from instagrapi.extractors import extract_media_v1
from instagrapi.exceptions import (
AlbumNotDownload, AlbumUnknownFormat,
AlbumConfigureError
AlbumConfigureError,
AlbumNotDownload,
AlbumUnknownFormat,
)
from instagrapi.types import Usertag, Location, Media
from instagrapi.extractors import extract_media_v1
from instagrapi.types import Location, Media, Usertag
from instagrapi.utils import dumps


Expand Down
13 changes: 7 additions & 6 deletions instagrapi/mixins/auth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import re
import json
import base64
import time
import uuid
import hmac
import datetime
import hashlib
import hmac
import json
import random
import datetime
import re
import time
import uuid

import requests

from instagrapi import config
Expand Down
13 changes: 9 additions & 4 deletions instagrapi/mixins/challenge.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import hashlib
import json
import time
import hashlib
import requests
from datetime import datetime

import requests

from instagrapi.exceptions import (
ChallengeRequired, SelectContactPointRecoveryForm, RecaptchaChallengeForm,
ChallengeError, ChallengeRedirection, SubmitPhoneNumberForm
ChallengeError,
ChallengeRedirection,
ChallengeRequired,
RecaptchaChallengeForm,
SelectContactPointRecoveryForm,
SubmitPhoneNumberForm,
)

CHOICE_SMS = 0
Expand Down
2 changes: 1 addition & 1 deletion instagrapi/mixins/collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from instagrapi.exceptions import CollectionNotFound
from instagrapi.extractors import extract_media_v1, extract_collection
from instagrapi.extractors import extract_collection, extract_media_v1


class CollectionMixin:
Expand Down
6 changes: 1 addition & 5 deletions instagrapi/mixins/comment.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import random
from typing import List

from instagrapi.exceptions import (
ClientError,
ClientNotFoundError,
MediaNotFound,
)
from instagrapi.exceptions import ClientError, ClientNotFoundError, MediaNotFound
from instagrapi.extractors import extract_comment
from instagrapi.types import Comment

Expand Down
6 changes: 3 additions & 3 deletions instagrapi/mixins/direct.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
from typing import List

from instagrapi.utils import dumps
from instagrapi.types import DirectThread, DirectMessage
from instagrapi.exceptions import ClientNotFoundError, DirectThreadNotFound
from instagrapi.extractors import extract_direct_thread, extract_direct_message
from instagrapi.extractors import extract_direct_message, extract_direct_thread
from instagrapi.types import DirectMessage, DirectThread
from instagrapi.utils import dumps


class DirectMixin:
Expand Down
4 changes: 2 additions & 2 deletions instagrapi/mixins/hashtag.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List

from instagrapi.exceptions import ClientError, ClientLoginRequired
from instagrapi.extractors import (
extract_hashtag_gql,
extract_hashtag_v1,
extract_media_gql,
extract_media_v1
extract_media_v1,
)
from instagrapi.exceptions import ClientError, ClientLoginRequired
from instagrapi.types import Hashtag, Media
from instagrapi.utils import dumps

Expand Down
7 changes: 3 additions & 4 deletions instagrapi/mixins/igtv.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import json
import time
import random
import time
from pathlib import Path
from typing import List
from uuid import uuid4

from instagrapi import config
from instagrapi.exceptions import ClientError, IGTVConfigureError, IGTVNotUpload
from instagrapi.extractors import extract_media_v1
from instagrapi.exceptions import ClientError, IGTVNotUpload, IGTVConfigureError
from instagrapi.types import Usertag, Location, Media

from instagrapi.types import Location, Media, Usertag

try:
from PIL import Image
Expand Down
2 changes: 1 addition & 1 deletion instagrapi/mixins/insights.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

from instagrapi.exceptions import ClientError, MediaError, UserError
from instagrapi.utils import json_value
from instagrapi.exceptions import UserError, ClientError, MediaError


class InsightsMixin:
Expand Down
2 changes: 1 addition & 1 deletion instagrapi/mixins/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import time
from typing import List

from instagrapi.extractors import extract_location
from instagrapi.exceptions import ClientLoginRequired
from instagrapi.extractors import extract_location
from instagrapi.types import Location, Media


Expand Down
16 changes: 8 additions & 8 deletions instagrapi/mixins/media.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import json
import random
from typing import List
from copy import deepcopy
from typing import List
from urllib.parse import urlparse

from instagrapi.utils import InstagramIdCodec
from instagrapi.exceptions import (
ClientError,
ClientLoginRequired,
ClientNotFoundError,
MediaNotFound,
ClientLoginRequired
)
from instagrapi.extractors import (
extract_media_v1, extract_media_gql,
extract_media_oembed, extract_location
)
from instagrapi.types import (
Usertag, Location, UserShort, Media
extract_location,
extract_media_gql,
extract_media_oembed,
extract_media_v1,
)
from instagrapi.types import Location, Media, UserShort, Usertag
from instagrapi.utils import InstagramIdCodec


class MediaMixin:
Expand Down
17 changes: 10 additions & 7 deletions instagrapi/mixins/photo.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import shutil
import json
import time
import random
import requests
import shutil
import time
from pathlib import Path
from typing import List
from uuid import uuid4
from urllib.parse import urlparse
from uuid import uuid4

import requests

from instagrapi import config
from instagrapi.extractors import extract_media_v1
from instagrapi.exceptions import (
PhotoNotUpload, PhotoConfigureError, PhotoConfigureStoryError
PhotoConfigureError,
PhotoConfigureStoryError,
PhotoNotUpload,
)
from instagrapi.types import Usertag, Location, StoryMention, StoryLink, Media
from instagrapi.extractors import extract_media_v1
from instagrapi.types import Location, Media, StoryLink, StoryMention, Usertag
from instagrapi.utils import dumps

try:
Expand Down
Loading

0 comments on commit be5bee6

Please sign in to comment.