Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH committed Oct 14, 2023
0 parents commit 2f7e415
Show file tree
Hide file tree
Showing 50 changed files with 2,114 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
end_of_line = lf

[*.{yml,yaml}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .github/.templateMarker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KOLANICH/python_project_boilerplate.py
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
15 changes: 15 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: typical python workflow
uses: KOLANICH-GHActions/typical-python-workflow@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
__pycache__
*.py[co]
/*.egg-info
/build
/dist
/.eggs
*.sqlite3
*.sqlite
/.mypy_cache
*.py,cover
/.coverage
/rspec.xml
/monkeytype.sqlite3
/*.srctrldb
/*.srctrlbm
/*.srctrlprj
/gpgme_home
/downloads
/brad.gpg
53 changes: 53 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#image: pypy:latest
image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest
stages:
- dependencies
- build
- test
- trigger

variables:
DOCKER_DRIVER: overlay2
SAST_ANALYZER_IMAGE_TAG: latest
SAST_DISABLE_DIND: "true"

include:
- template: SAST.gitlab-ci.yml
#- template: DAST.gitlab-ci.yml
#- template: License-Management.gitlab-ci.yml
#- template: Container-Scanning.gitlab-ci.yml
#- template: Dependency-Scanning.gitlab-ci.yml
- template: Code-Quality.gitlab-ci.yml


build:
tags:
- shared
stage: build
variables:
GIT_DEPTH: "1"
PYTHONUSERBASE: ${CI_PROJECT_DIR}/python_user_packages

before_script:
- export PYTHON_MODULES_DIR=${PYTHONUSERBASE}/lib/python3.8
- export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin
- export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered
- mkdir ./wheels

script:
- python3 ./setup.py bdist_wheel
- mv ./dist/*.whl ./wheels/fetchers-0.CI_python-py3-none-any.whl
- pip3 install --upgrade --pre --user ./wheels/fetchers-0.CI_python-py3-none-any.whl
- coverage run --source=fetchers --branch -m pytest --junitxml=./rspec.xml ./tests/tests.py
- coverage report -m
- coverage xml

coverage: /^TOTAL\s+.+?(\d{1,3}%)$/

artifacts:
paths:
- wheels
reports:
junit: ./rspec.xml
cobertura: ./coverage.xml

1 change: 1 addition & 0 deletions Code_Of_Conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No codes of conduct!
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include UNLICENSE
include *.md
include tests
include .editorconfig
41 changes: 41 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fetchers.py [![Unlicensed work](https://raw.githubusercontent.com/unlicense/unlicense.org/master/static/favicon.png)](https://unlicense.org/)
======
[![GitLab Build Status](https://gitlab.com/KOLANICH/fetchers.py/badges/master/pipeline.svg)](https://gitlab.com/KOLANICH/fetchers.py/pipelines/master/latest)
![GitLab Coverage](https://gitlab.com/KOLANICH/fetchers.py/badges/master/coverage.svg)
[![GitHub Actions](https://github.com/prebuilder/fetchers.py/workflows/CI/badge.svg)](https://github.com/prebuilder/fetchers.py/actions/)
[![Libraries.io Status](https://img.shields.io/librariesio/github/prebuilder/fetchers.py.svg)](https://libraries.io/github/prebuilder/fetchers.py)
[![Code style: antiflash](https://img.shields.io/badge/code%20style-antiflash-FFF.svg)](https://codeberg.org/KOLANICH-tools/antiflash.py)

Just a lib for fetching source code repositories and precompiled binaries from the net and putting them into FS somewhere.

Why do we need it? When building software you have to get their source code. This lib is mainly for that. It's an abstraction layer, allowing you to

* **discover** the latest release;
* **fetch** its source code and its metadata efficiently;
* **verify** its integrity and **extract version number** using the uniform interface;
* **unpack** the archive/installer if needed, populating the dir with sources.

The interface has 2 stages.
1. You create the object representing what is needed to be done.
2. You trigger the action.

This is done this way because the parts are usually done in differrent places: filling-in the info is done by build framework user, execution of the action is done by the framework itself.

The lib outputs some debug info into the stdout. It is by design - it informs the user on what is going on. Remember - the lib is designed to be used in CLI tools building packages. Some of info can be redirected - you need to select a differrent progress reporter. But other messages are not yet redirectable currently.

Supported ways to fetch the source code:

* Git. You usually need shallow clones, to fetch only what you need. But if you use shallow clones, you don't have tags names, which are an extremily popular way to encode software release version. So you either have to stop using shallow clones, which is inacceptible, or get this in another way. We get it via API of source code hostings. The following are implemented:

* [GitHub](https://github.com)
* [GitLab](https://gitlab.com)
* [Bitbucket](https://bitbucket.org)
* [Launchpad](https://launchpad.net)
* ~~[SourceForge](https://sourceforge.net)~~

* Just a https link to an archive. Archives are downloaded, then verified, then unpacked. Some CDNs are explicitly supported for more efficien downloading, using `aria2c` multistreaming:

* ~~[SourceForge](https://sourceforge.net)~~
* MirrorBrainz

For the tutorial see [`tutorial.ipynb`](./tutorial.ipynb).
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

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 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.

For more information, please refer to <https://unlicense.org/>
14 changes: 14 additions & 0 deletions fetchers/DownloadTarget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import typing
from datetime import datetime

from downloaders.DownloadTarget import DownloadTarget as _DownloadTarget, URIsT


class DownloadTarget(_DownloadTarget):
__slots__ = ("role", "name", "time")

def __init__(self, role: str, name: str, uris: URIsT, time: datetime, fsPath: None = None) -> None:
super().__init__(uris, fsPath)
self.role = role
self.name = name
self.time = time
49 changes: 49 additions & 0 deletions fetchers/FetchConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import typing
from pathlib import Path
from shutil import rmtree

from pantarei import ProgressReporter

from .enums import CleanFetch


class FetchConfig:
"""Encapsulates the shared info used to download the stuff"""

__slots__ = ("downloadsTmp", "progressReporter", "shallow", "dontFetch", "gpgmeHome", "rpmRoot")

def doCleanup(self):
if self.downloadsTmp.exists():
rmtree(self.downloadsTmp)

def doPreparations(self):
self.doCleanup()
self.downloadsTmp.mkdir(exist_ok=True, parents=True)

def __init__(self, downloadsTmp: typing.Optional[Path] = None, progressReporter: typing.Optional[ProgressReporter] = None, shallow: bool = True, dontFetch: bool = False, gpgmeHome: typing.Optional[Path] = None, rpmRoot: typing.Optional[Path] = None):
"""
`downloadsTmp` is a dir into which files that are not our final goals (`repomd.xml`, archives before unpacking, etc.) will be downloaded
`gpgme_home` is a dir to be used for crypto operations by gpgme. gpgme is a library wrapping widely used in package managers. Unfortunately, it disallows fully in-memory operations: gpg relies on keys databases on disk (and one has to create one before any meaningful operations), and gpgme relies on CLI gpg.
`rpmRoot` is a dir to be used as a librpm root. librpm will put shit into it. Wie dont wat it to put shit into the system."""

thisDir = Path(".").absolute()

self.shallow = shallow # True: shallow fetches without tags, False: full fetches + tags
self.dontFetch = dontFetch # don't fetch, only populate version

if downloadsTmp is None:
downloadsTmp = thisDir / "downloads"

if gpgmeHome is None:
gpgmeHome = thisDir / "gpgme_home"

if rpmRoot is None:
rpmRoot = thisDir / "rpm_root"

if progressReporter is None:
from pantarei import chosenProgressReporter as progressReporter # pylint:disable=import-outside-toplevel

self.downloadsTmp = downloadsTmp
self.gpgmeHome = gpgmeHome
self.rpmRoot = rpmRoot
self.progressReporter = progressReporter
61 changes: 61 additions & 0 deletions fetchers/Fetcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import typing
from abc import abstractmethod
from collections import OrderedDict

from AnyVer import AnyVer

from .FetchConfig import FetchConfig

from .utils.idded import IDded
from .utils.json import json
from .utils.ReprMixin import ReprMixin


class Fetched(ReprMixin):
__slots__ = ("time", "version", "fetcherID")

def __init__(self, time: float, version: AnyVer, iD: str) -> None:
self.time = time
self.version = version
self.fetcherID = iD

@property
def __dict__(self) -> OrderedDict:
return OrderedDict((k, getattr(self, k)) for k in self.__class__.__slots__)


class IFetcher(IDded):
__slots__ = ()

delimiter = "%"

@abstractmethod
def __call__(self, dir, fetchConfig: FetchConfig, versionNeeded: bool = True) -> Fetched:
raise NotImplementedError()


class IURIFetcher(IFetcher): # pylint:disable=abstract-method
__slots__ = ("uri",)

def __init__(self, uri: str, refspec: typing.Optional[str] = None) -> None:
self.uri = uri

@property
def idComponents(self):
return (self.uri,)


class IRepoFetcher(IURIFetcher): # pylint:disable=abstract-method
__slots__ = ("refspec", "repo")

@property
def idComponents(self):
return super().idComponents + (self.refspec,)

def __init__(self, uri: str, refspec: typing.Optional[str] = None) -> None:
super().__init__(uri)
self.refspec = refspec
self.repo = None


defaultRepoFetcher = None # set in tools.git
Loading

0 comments on commit 2f7e415

Please sign in to comment.