Skip to content

Commit 1ca7ed5

Browse files
committed
Initial commit
0 parents  commit 1ca7ed5

20 files changed

+736
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
indent_size = 4
7+
insert_final_newline = true
8+
end_of_line = lf
9+
10+
[*.{yml,yaml}]
11+
indent_style = space
12+
indent_size = 2

.github/.templateMarker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KOLANICH/python_project_boilerplate.py

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
allow:
8+
- dependency-type: "all"

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: typical python workflow
13+
uses: KOLANICH-GHActions/typical-python-workflow@master
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
__pycache__
2+
*.pyc
3+
*.pyo
4+
/*.egg-info
5+
/build
6+
/dist
7+
/.eggs
8+
*.sqlite3
9+
*.sqlite
10+
/.mypy_cache
11+
*.py,cover
12+
/.coverage
13+
/rspec.xml
14+
/monkeytype.sqlite3
15+
/*.srctrldb
16+
/*.srctrlbm
17+
/*.srctrlprj

.gitlab-ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#image: pypy:latest
2+
image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest
3+
stages:
4+
- dependencies
5+
- build
6+
- test
7+
- trigger
8+
9+
variables:
10+
DOCKER_DRIVER: overlay2
11+
SAST_ANALYZER_IMAGE_TAG: latest
12+
SAST_DISABLE_DIND: "true"
13+
14+
include:
15+
- template: SAST.gitlab-ci.yml
16+
#- template: DAST.gitlab-ci.yml
17+
#- template: License-Management.gitlab-ci.yml
18+
#- template: Container-Scanning.gitlab-ci.yml
19+
#- template: Dependency-Scanning.gitlab-ci.yml
20+
- template: Code-Quality.gitlab-ci.yml
21+
22+
23+
build:
24+
tags:
25+
- shared
26+
- linux
27+
stage: build
28+
variables:
29+
GIT_DEPTH: "1"
30+
PYTHONUSERBASE: ${CI_PROJECT_DIR}/python_user_packages
31+
32+
before_script:
33+
- export PYTHON_MODULES_DIR=${PYTHONUSERBASE}/lib/python3.7
34+
- export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin
35+
- export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered
36+
- mkdir ./wheels
37+
- pip install --upgrade --pre --user git+https://gitlab.com/KOLANICH/pantarei.py.git git+https://gitlab.com/KOLANICH/MempipedPath.py.git
38+
39+
script:
40+
- python3 ./setup.py bdist_wheel
41+
- mv ./dist/*.whl ./wheels/File2Package-0.CI_python-py3-none-any.whl
42+
- pip3 install --upgrade --pre --user ./wheels/File2Package-0.CI_python-py3-none-any.whl
43+
- coverage run --source=File2Package --branch -m pytest --junitxml=./rspec.xml ./tests/tests.py
44+
- coverage report -m
45+
- coverage xml
46+
47+
coverage: /^TOTAL\\s+.+?(\\d{1,3}%)$/
48+
49+
cache:
50+
paths:
51+
- $PYTHONUSERBASE
52+
53+
artifacts:
54+
paths:
55+
- wheels
56+
reports:
57+
junit: ./rspec.xml
58+
cobertura: ./coverage.xml
59+
60+
# TODO: What we'll we do when more backends are available? We need a way to triger a single job only!
61+
test_dpkg_backend:
62+
only:
63+
- master
64+
stage: trigger
65+
allow_failure: true
66+
trigger:
67+
project: File2Package.py/File2Package.backend.dpkg
68+
strategy: depend

Code_Of_Conduct.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No codes of conduct!

File2Package/BackendsDiscoverer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import warnings
2+
3+
from . import interfaces
4+
5+
6+
def discoverBackends():
7+
import pkg_resources
8+
9+
pts = list(pkg_resources.iter_entry_points(group="file_2_package"))
10+
return dict(((b.name, b) for b in pts))
11+
12+
13+
discoveredBackends = discoverBackends()
14+
15+
16+
def selectBackend(name: str):
17+
b = discoveredBackends[name]
18+
init = b.load()
19+
cls = init(interfaces)
20+
cls.ID = name
21+
return cls

File2Package/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
import sqlite3
3+
import threading
4+
import typing
5+
from collections import defaultdict
6+
from pathlib import Path
7+
8+
import datrie
9+
from MempipedPath import *
10+
11+
from .database import File2Package
12+
from .interfaces import *

File2Package/__main__.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import sys
2+
import typing
3+
4+
from plumbum import cli
5+
6+
from . import *
7+
from .BackendsDiscoverer import discoveredBackends
8+
9+
10+
class File2PackageCLI(cli.Application):
11+
pass
12+
13+
14+
@File2PackageCLI.subcommand("backends")
15+
class File2PackageCLIListBackends(cli.Application):
16+
def main(self):
17+
from pprint import pprint
18+
19+
pprint(discoveredBackends)
20+
21+
22+
cacheDBAttr = cli.SwitchAttr(["-D", "--db"], str, help="Either a path to SQLite db file or just a name. In the case of a name the file will be created in cache dir.")
23+
24+
25+
def file2PackageWithStringFilePath(backend: str, cacheDB: str):
26+
try:
27+
cacheDBPath = Path(cacheDB).absolute()
28+
if cacheDBPath.is_file() or cacheDBPath.suffix.lower in {".sqlite", ".db"}:
29+
return File2Package(backend, cacheDB=cacheDBPath)
30+
except BaseException:
31+
pass
32+
33+
return File2Package(backend, cacheDB=cacheDB)
34+
35+
36+
@File2PackageCLI.subcommand("refresh")
37+
class File2PackageCLIRefresh(cli.Application):
38+
"""Recreates the database for the backend"""
39+
40+
def main(self, backend: str, cacheDB: str = None):
41+
with file2PackageWithStringFilePath(backend, cacheDB=cacheDB) as f2p:
42+
f2p.createDB()
43+
44+
45+
@File2PackageCLI.subcommand("lookup")
46+
class File2PackageCLILookup(cli.Application):
47+
"""Prints list of packages to which files belong"""
48+
49+
cacheDb = cacheDBAttr
50+
json = cli.Flag(["-J", "--json"], help="print JSON")
51+
52+
def main(self, backend: str, *files):
53+
from collections import OrderedDict
54+
55+
res = OrderedDict()
56+
import json
57+
58+
with file2PackageWithStringFilePath(backend, cacheDB=self.cacheDb) as f2p:
59+
for f in files:
60+
fp = Path(f).absolute()
61+
pkg = f2p[fp]
62+
res[str(fp)] = (pkg.name, pkg.arch)
63+
64+
if self.json:
65+
print(json.dumps(res, indent="\t"))
66+
else:
67+
print("\n".join(":".join(v) for v in res.values()))
68+
69+
70+
if __name__ == "__main__":
71+
File2PackageCLI.run()

0 commit comments

Comments
 (0)