diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..6a6724e --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,17 @@ +version = 1 + +test_patterns = [ + 'tests/**' +] + +exclude_patterns = [ + +] + +[[analyzers]] +name = 'python' +enabled = true +runtime_version = '3.x.x' + + [analyzers.meta] + max_line_length = 119 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6ccd91f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: ternaus +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b36d9f9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python package + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8, 3.9] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1.1.1 + with: + python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v1 + with: + path: ~/.cache/pip # This path is specific to Ubuntu + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + # You can test your matrix by printing the current Python version + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install black flake8 mypy + - name: Run black + run: + black --check . + - name: Run flake8 + run: flake8 + - name: Run Mypy + run: mypy cloths_segmentation +# - name: tests +# run: | +# pip install .[tests] +# pytest diff --git a/.gitignore b/.gitignore index b6e4761..b97131e 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ + +.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aa5f7dc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,46 @@ +exclude: _pb2\.py$ +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black +- repo: https://github.com/asottile/yesqa + rev: v1.2.2 + hooks: + - id: yesqa + additional_dependencies: + - flake8-bugbear==20.1.4 + - flake8-builtins==1.5.2 + - flake8-comprehensions==3.2.2 + - flake8-tidy-imports==4.1.0 + - flake8==3.7.9 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: check-docstring-first + - id: check-json + - id: check-merge-conflict + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace + - id: requirements-txt-fixer +- repo: https://gitlab.com/pycqa/flake8 + rev: a4aeb2e209c64efcfadb43cb96809c1f5b80912b + hooks: + - id: flake8 +- repo: https://github.com/asottile/pyupgrade + rev: v2.7.3 + hooks: + - id: pyupgrade + args: ['--py36-plus'] +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.7.0 + hooks: + - id: python-check-mock-methods + - id: python-use-type-annotations +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 9feadeb + hooks: + - id: mypy + args: [--ignore-missing-imports, --warn-no-return, --warn-redundant-casts, --disallow-incomplete-defs] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..038ed30 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Vladimir Iglovikov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..06d00f2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +# Example configuration for Black. + +# NOTE: you have to use single-quoted strings in TOML for regular expressions. +# It's the equivalent of r-strings in Python. Multiline strings are treated as +# verbose regular expressions by Black. Use [ ] to denote a significant space +# character. + +[tool.black] +line-length = 119 +target-version = ['py36', 'py37', 'py38'] +include = '\.pyi?$' +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e0b7433 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +albumentations +iglovikov_helper_functions +pytorch_lightning +pytorch_toolbelt +segmentation-models-pytorch +torch +tqdm diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..1776e6d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,7 @@ +[flake8] +max-line-length = 119 +exclude =.git,__pycache__,docs/source/conf.py,build,dist +ignore = I101,I201,F401,F403,S001,D100,D101,D102,D103,D104,D105,D106,D107,D200,D205,D400,W504,E203,D202,D401 + +[mypy] +ignore_missing_imports = True diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1e8bc29 --- /dev/null +++ b/setup.py @@ -0,0 +1,112 @@ +import io +import os +import re +import sys +from shutil import rmtree + +from setuptools import Command, find_packages, setup + +# Package meta-data. +name = "cloths_segmentation" +description = "High quality model for cloths segmentation." +url = "https://github.com/ternaus/cloths_segmentation" +email = "iglovikov@gmail.com" +author = "Vladimir Iglovikov" +requires_python = ">=3.0.0" +current_dir = os.path.abspath(os.path.dirname(__file__)) + + +def get_version(): + version_file = os.path.join(current_dir, name, "__init__.py") + with open(version_file, encoding="utf-8") as f: + return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', f.read(), re.M).group(1) + + +# What packages are required for this module to be executed? +try: + with open(os.path.join(current_dir, "requirements.txt"), encoding="utf-8") as f: + required = f.read().split("\n") +except FileNotFoundError: + required = [] + +# What packages are optional? +extras = {"test": ["pytest"]} + +version = get_version() + +about = {"__version__": version} + + +def get_test_requirements(): + requirements = ["pytest"] + if sys.version_info < (3, 3): + requirements.append("mock") + return requirements + + +def get_long_description(): + base_dir = os.path.abspath(os.path.dirname(__file__)) + with open(os.path.join(base_dir, "README.md"), encoding="utf-8") as f: + return f.read() + + +class UploadCommand(Command): + """Support setup.py upload.""" + + description = "Build and publish the package." + + @staticmethod + def status(s): + """Print things in bold.""" + print(s) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + try: + self.status("Removing previous builds...") + rmtree(os.path.join(current_dir, "dist")) + except OSError: + pass + + self.status("Building Source and Wheel (universal) distribution...") + os.system(f"{sys.executable} setup.py sdist bdist_wheel --universal") + + self.status("Uploading the package to PyPI via Twine...") + os.system("twine upload dist/*") + + self.status("Pushing git tags...") + os.system("git tag v{}".format(about["__version__"])) + os.system("git push --tags") + + sys.exit() + + +setup( + name=name, + version=version, + description=description, + long_description=get_long_description(), + long_description_content_type="text/markdown", + author="Vladimir Iglovikov", + license="MIT", + url=url, + packages=find_packages(exclude=["tests", "docs", "images"]), + install_requires=required, + extras_require=extras, + classifiers=[ + "License :: OSI Approved :: MIT License", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + cmdclass={"upload": UploadCommand}, +)