afshin-dini commited on
Commit
062a131
·
0 Parent(s):

Initialize the project

Browse files
.bumpversion.cfg ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [bumpversion]
2
+ current_version = 0.1.0
3
+ commit = False
4
+ tag = False
5
+
6
+ [bumpversion:file:pyproject.toml]
7
+ search = version = "{current_version}"
8
+ replace = version = "{new_version}"
9
+
10
+ [bumpversion:file:src/deep_package_detection/__init__.py]
11
+ search = __version__ = "{current_version}"
12
+ replace = __version__ = "{new_version}"
13
+
14
+ [bumpversion:file:tests/test_deep_package_detection.py]
15
+ search = __version__ == "{current_version}"
16
+ replace = __version__ == "{new_version}"
.gitignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pycharm files
2
+ .idea/
3
+
4
+ # poetry
5
+ poetry.lock
6
+
7
+ # Unit test files
8
+ .coverage
9
+ .coverage.*
10
+ .cache
11
+ .pytest_cache/
12
+
13
+ # mypy files
14
+ .mypy_cache/
15
+
16
+ # Probable environments files
17
+ .env
18
+ .venv
19
+ env/
20
+ venv/
21
+
22
+
23
+
24
+
.pre-commit-config.yaml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ default_language_version:
4
+ python: python3
5
+ repos:
6
+ - repo: https://github.com/pre-commit/pre-commit-hooks
7
+ rev: v4.5.0 # the release, git tag, or commit you want to use
8
+ hooks:
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: check-json
12
+ - id: end-of-file-fixer
13
+ - id: trailing-whitespace
14
+ - id: no-commit-to-branch
15
+ - id: check-executables-have-shebangs
16
+ - id: check-added-large-files
17
+ - id: check-case-conflict
18
+ - id: check-merge-conflict
19
+ - id: pretty-format-json
20
+ args:
21
+ - --autofix
22
+ - id: check-symlinks
23
+ - id: check-ast
24
+ - id: detect-private-key
25
+ - repo: https://github.com/psf/black
26
+ rev: 24.1.1
27
+ hooks:
28
+ - id: black
29
+ language: python
30
+ - repo: https://github.com/pre-commit/mirrors-mypy
31
+ rev: v1.8.0
32
+ hooks:
33
+ - id: mypy
34
+ language: system
35
+ args: [--strict, --ignore-missing-imports]
36
+ - repo: https://github.com/pycqa/pylint
37
+ rev: v3.0.3
38
+ hooks:
39
+ - id: pylint
40
+ language: system
41
+ - repo: https://github.com/Lucas-C/pre-commit-hooks
42
+ rev: v1.5.4
43
+ hooks:
44
+ - id: forbid-crlf
45
+ - id: remove-crlf
46
+ - id: forbid-tabs
47
+ - id: remove-tabs
48
+ - repo: https://github.com/PyCQA/bandit
49
+ rev: 1.7.7
50
+ hooks:
51
+ - id: bandit
52
+ args: ["--skip=B101"]
53
+ - repo: https://github.com/Lucas-C/pre-commit-hooks-markup
54
+ rev: v1.0.1
55
+ hooks:
56
+ - id: rst-linter
57
+ - repo: https://github.com/Yelp/detect-secrets
58
+ rev: v1.4.0
59
+ hooks:
60
+ - id: detect-secrets
61
+ language: python
62
+ exclude: "poetry.lock"
63
+ # args: ['--baseline', '.secrets.baseline']
64
+ - repo: https://github.com/shellcheck-py/shellcheck-py
65
+ rev: v0.9.0.6
66
+ hooks:
67
+ - id: shellcheck
68
+ args: ["--external-sources"]
69
+ - repo: https://github.com/python-poetry/poetry
70
+ rev: '1.7.1'
71
+ hooks:
72
+ - id: poetry-check
73
+ - id: poetry-lock
74
+ args: ["--no-update"]
Dockerfile ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## syntax=docker/dockerfile:1.1.7-experimental
2
+
3
+ ################
4
+ # Base builder #
5
+ ################
6
+ FROM python:3.10-bookworm as base_build
7
+
8
+ ENV \
9
+ # locale environment variables
10
+ LC_ALL=C.UTF-8 \
11
+ # python environemnt variables
12
+ PYTHONFAULTHANDLER=1 \
13
+ PYTHONUNBUFFERED=1 \
14
+ PYTHONHASHSEED=random \
15
+ # pip environmental variables
16
+ PIP_NO_CACHE_DIR=off \
17
+ PIP_DISABLE_PIP_VERSION_CHECK=on \
18
+ PIP_DEFAULT_TIMEOUT=100 \
19
+ # poetry version
20
+ POETRY_VERSION=1.5.0
21
+
22
+ # Install requirements
23
+ RUN apt-get update && apt-get install -y \
24
+ curl \
25
+ git \
26
+ bash \
27
+ build-essential \
28
+ libffi-dev \
29
+ libssl-dev \
30
+ tini \
31
+ openssh-client \
32
+ cargo \
33
+ musl-dev \
34
+ && apt-get autoremove -y \
35
+ && rm -rf /var/lib/apt/lists/* \
36
+ # github ssh key setting
37
+ && mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com | sort > ~/.ssh/known_hosts \
38
+ # Installing poetry and set the PATH
39
+ && curl -sSL https://install.python-poetry.org | python3 - \
40
+ && echo 'export PATH="/root/.local/bin:$PATH"' >>/root/.profile \
41
+ && export PATH="/root/.local/bin:$PATH" \
42
+ && true
43
+ SHELL ["/bin/bash", "-lc"]
44
+
45
+ # Copy poetry lock and pyproject config files to the container
46
+ WORKDIR /pysetup
47
+ COPY ./poetry.lock ./pyproject.toml /pysetup/
48
+ # Install pip/wheel/virtualenv and build the wheels based on the poetry lock
49
+ RUN --mount=type=ssh pip3 install wheel virtualenv poetry-plugin-export \
50
+ && poetry export -f requirements.txt --without-hashes -o /tmp/requirements.txt \
51
+ && pip3 wheel --wheel-dir=/tmp/wheelhouse --trusted-host 172.17.0.1 --find-links=http://172.17.0.1:3141/debian/ -r /tmp/requirements.txt \
52
+ && virtualenv /.venv && source /.venv/bin/activate && echo 'source /.venv/bin/activate' >>/root/.profile \
53
+ && pip3 install --no-deps --trusted-host 172.17.0.1 --find-links=http://172.17.0.1:3141/debian/ --find-links=/tmp/wheelhouse/ /tmp/wheelhouse/*.whl \
54
+ && true
55
+
56
+
57
+ ###########################
58
+ # Production base builder #
59
+ ###########################
60
+ FROM base_build as production_build
61
+ # Copy entrypoint script to the container and src files to the app directory
62
+ COPY ./docker/entrypoint.sh /docker-entrypoint.sh
63
+ COPY . /app/
64
+ WORKDIR /app
65
+ # Build the wheel packages with poetry and add them to the wheelhouse
66
+ RUN --mount=type=ssh source /.venv/bin/activate \
67
+ && poetry build -f wheel --no-interaction --no-ansi \
68
+ && cp dist/*.whl /tmp/wheelhouse \
69
+ && chmod a+x /docker-entrypoint.sh \
70
+ && true
71
+
72
+
73
+
74
+ ########################
75
+ # Production Container #
76
+ ########################
77
+ FROM python:3.10-bookworm as production
78
+ COPY --from=production_build /tmp/wheelhouse /tmp/wheelhouse
79
+ COPY --from=production_build /docker-entrypoint.sh /docker-entrypoint.sh
80
+ WORKDIR /app
81
+ # Install system level deps for running the package and install the wheels we built in the previous step.
82
+ RUN --mount=type=ssh apt-get update && apt-get install -y \
83
+ bash \
84
+ libffi8 \
85
+ libgl1 \
86
+ tini \
87
+ && apt-get autoremove -y \
88
+ && rm -rf /var/lib/apt/lists/* \
89
+ && chmod a+x /docker-entrypoint.sh \
90
+ && WHEELFILE=`echo /tmp/wheelhouse/deep_package_detection-*.whl` \
91
+ && pip3 install --trusted-host 172.17.0.1 --find-links=http://172.17.0.1:3141/debian/ --find-links=/tmp/wheelhouse/ "$WHEELFILE"[all] \
92
+ && rm -rf /tmp/wheelhouse/ \
93
+ && true
94
+ ENTRYPOINT ["/usr/bin/tini", "--", "/docker-entrypoint.sh"]
95
+
96
+
97
+
98
+ ############################
99
+ # Development base builder #
100
+ ############################
101
+ FROM base_build as development_build
102
+ # Copy src to app directory
103
+ COPY . /app
104
+ WORKDIR /app
105
+ # Install dependencies from poetry lock
106
+ RUN --mount=type=ssh source /.venv/bin/activate \
107
+ && apt-get update && apt-get install -y libgl1 \
108
+ && export PIP_FIND_LINKS=http://172.17.0.1:3141/debian/ \
109
+ && export PIP_TRUSTED_HOST=172.17.0.1 \
110
+ && pip3 install nvidia-cublas-cu12 nvidia-cusparse-cu12 triton nvidia-nccl-cu12 nvidia-cudnn-cu12 nvidia-cufft-cu12 nvidia-cusolver-cu12 \
111
+ && poetry install --no-interaction --no-ansi \
112
+ && true
113
+
114
+
115
+
116
+ ###################
117
+ # Tests Container #
118
+ ###################
119
+ FROM development_build as test
120
+ RUN --mount=type=ssh source /.venv/bin/activate \
121
+ && chmod a+x docker/*.sh \
122
+ && docker/pre_commit_init.sh \
123
+ && true
124
+ ENTRYPOINT ["/usr/bin/tini", "--", "docker/entrypoint-test.sh"]
125
+
126
+
127
+ #########################
128
+ # Development Container #
129
+ #########################
130
+ FROM development_build as development
131
+ RUN apt-get update && apt-get install -y zsh \
132
+ && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
133
+ && echo "if [ \"\$NO_WHEELHOUSE\" = \"1\" ]" >>/root/.profile \
134
+ && echo "then" >>/root/.profile \
135
+ && echo " echo \"Wheelhouse disabled\"" >>/root/.profile \
136
+ && echo "else">>/root/.profile \
137
+ && echo " export PIP_TRUSTED_HOST=172.17.0.1" >>/root/.profile \
138
+ && echo " export PIP_FIND_LINKS=http://172.17.0.1:3141/debian/" >>/root/.profile \
139
+ && echo "fi" >>/root/.profile \
140
+ && echo "source /root/.profile" >>/root/.zshrc \
141
+ && pip3 install git-up \
142
+ && true
143
+ ENTRYPOINT ["/bin/zsh", "-l"]
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deep-Package-Detection
2
+ This is a deep model for detecting different types of packages.
3
+
4
+ ## How to Develop
5
+ Do the following only once after creating your project:
6
+ - Init the git repo with `git init`.
7
+ - Add files with `git add .`.
8
+ - Then `git commit -m 'initialize the project'`.
9
+ - Add remote url with `git remote add origin REPO_URL`.
10
+ - Then `git branch -M master`.
11
+ - `git push origin main`.
12
+ Then create a branch with `git checkout -b BRANCH_NAME` for further developments.
13
+ - Install poetry if you do not have it in your system from [here](https://python-poetry.org/docs/#installing-with-pipx).
14
+ - Create a virtual env preferably with virtualenv wrapper and `mkvirtualenv -p $(which python3.10) ENVNAME`.
15
+ - Then `git add poetry.lock`.
16
+ - Then `pre-commit install`.
17
+ - For applying changes use `pre-commit run --all-files`.
18
+
19
+ ## Docker Container
20
+ Under development.
docker/entrypoint-test.sh ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -l
2
+ set -e
3
+ if [ "$#" -eq 0 ]; then
4
+ # Kill cache, pytest complains about it if running local and docker tests in mapped volume
5
+ find tests -type d -name '__pycache__' -print0 | xargs -0 rm -rf {}
6
+ # Make sure the service itself is installed
7
+ poetry install
8
+ # Make sure pre-commit checks were not missed and run tests
9
+ git config --global --add safe.directory /app
10
+ poetry run pre-commit install
11
+ pre-commit run --all-files
12
+ pytest -v --junitxml=pytest.xml tests/
13
+ else
14
+ exec "$@"
15
+ fi
docker/entrypoint.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -l
2
+ set -e
3
+ if [ "$#" -eq 0 ]; then
4
+ exec deep_package_detection --help
5
+ else
6
+ exec "$@"
7
+ fi
docker/pre_commit_init.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -l
2
+ if [ ! -d .git ]
3
+ then
4
+ git init
5
+ git checkout -b precommit_init
6
+ git add .
7
+ fi
8
+ set -e
9
+ poetry run pre-commit install
10
+ SKIP="poetry-lock" poetry run pre-commit run --all-files
pyproject.toml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "deep_package_detection"
3
+ version = "0.1.0"
4
+ description = "This is a deep model for detecting different types of packages."
5
+ authors = ["Afshin Dini <Afshin Dini>"]
6
+ readme = "README.md"
7
+ packages = [{include = "deep_package_detection", from = "src"}]
8
+
9
+ [tool.poetry.scripts]
10
+ deep_package_detection = "deep_package_detection.main:deep_package_detection_cli"
11
+
12
+ [tool.pylint.format]
13
+ max-line-length=150 # This defines the maximum number of characters on a single line in pylint
14
+
15
+ [tool.pylint.design]
16
+ max-attributes=10
17
+ max-positional-arguments=6
18
+ max-args=6
19
+
20
+ [tool.pylint.messages_control]
21
+ disable=["fixme"]
22
+
23
+ [tool.pylint.similarities]
24
+ min-similarity-lines = 8 # Minimum lines number of a similarity.
25
+ ignore-imports = true # Ignore imports when computing similarities.
26
+
27
+ [tool.pytest.ini_options]
28
+ junit_family="xunit2"
29
+ addopts="--cov=deep_package_detection --cov-fail-under=65 --cov-branch"
30
+ asyncio_mode="strict"
31
+
32
+
33
+ [tool.coverage.run]
34
+ omit = ["tests/*"]
35
+ branch = true
36
+
37
+
38
+ [tool.poetry.dependencies]
39
+ python = "^3.10"
40
+ click = "^8.1.7"
41
+
42
+
43
+ [tool.poetry.group.dev.dependencies]
44
+ pytest = "^8.3.3"
45
+ coverage = "^7.6"
46
+ pytest-cov = "^6.0"
47
+ pylint = "^3.3.1"
48
+ black = "^24.10.0"
49
+ mypy = "^1.13.0"
50
+ bump2version = "^1.0.1"
51
+ bandit = "^1.7.10"
52
+ pre-commit = "^4.0.1"
53
+ detect-secrets = "^1.5"
54
+
55
+ [build-system]
56
+ requires = ["poetry-core>=1.5.0"]
57
+ build-backend = "poetry.core.masonry.api"
src/deep_package_detection/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ """ his is a deep model for detecting different types of packages. """
2
+
3
+ __version__ = "0.1.0"
src/deep_package_detection/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (309 Bytes). View file
 
src/deep_package_detection/__pycache__/loggings.cpython-312.pyc ADDED
Binary file (1.29 kB). View file
 
src/deep_package_detection/__pycache__/main.cpython-312.pyc ADDED
Binary file (1.52 kB). View file
 
src/deep_package_detection/loggings.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Logger initialization"""
2
+
3
+ import logging
4
+ import logging.config
5
+ from typing import Any, Optional
6
+
7
+
8
+ def config_logger(loglevel: int, log_file: Optional[str] = None) -> Any:
9
+ """Initialize a custom logger"""
10
+ handlers = {
11
+ "console": {
12
+ "class": "logging.StreamHandler",
13
+ "formatter": "standard",
14
+ },
15
+ }
16
+ if log_file:
17
+ handlers["file"] = {
18
+ "class": "logging.FileHandler",
19
+ "formatter": "standard",
20
+ "filename": log_file,
21
+ "mode": "a",
22
+ }
23
+ default_logging_config = {
24
+ "version": 1,
25
+ "disable_existing_loggers": False,
26
+ "formatters": {
27
+ "standard": {
28
+ "format": "%(asctime)s - [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)d (%(process)d)] | %(message)s",
29
+ "datefmt": "%Y-%m-%d %H:%M:%S",
30
+ },
31
+ },
32
+ "handlers": handlers,
33
+ "root": {
34
+ "handlers": list(handlers.keys()),
35
+ "level": loglevel,
36
+ },
37
+ }
38
+ logging.config.dictConfig(default_logging_config)
src/deep_package_detection/main.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run the main code for Deep-Package-Detection"""
2
+
3
+ import logging
4
+
5
+ import click
6
+
7
+ from deep_package_detection import __version__
8
+ from deep_package_detection.loggings import config_logger
9
+
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ @click.command()
15
+ @click.version_option(version=__version__)
16
+ @click.option("-l", "--log_path", type=str, help="Path to save log file")
17
+ @click.option("-v", "--verbose", count=True, help="Shorthand for info/debug/warning/error loglevel (-v/-vv/-vvv/-vvvv)")
18
+ def deep_package_detection_cli(log_path: str, verbose: int) -> None:
19
+ """This is a deep model for detecting different types of packages. """
20
+ if verbose == 1:
21
+ log_level = 10
22
+ elif verbose == 2:
23
+ log_level = 20
24
+ elif verbose == 3:
25
+ log_level = 30
26
+ else:
27
+ log_level = 40
28
+ config_logger(log_level, log_path)
29
+
30
+ click.echo("Run the main code.")
tests/__init__.py ADDED
File without changes
tests/test_deep_package_detection.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ """Package level tests"""
2
+
3
+ from deep_package_detection import __version__
4
+
5
+
6
+ def test_version() -> None:
7
+ """Unit test for checking the version of the code"""
8
+ assert __version__ == "0.1.0"