Beispiel #1
0
def _find_venv_activate_script(in_dir, loop_count=1, max_count=5):
    if loop_count > max_count:
        return
    for dirname, folderlist, filelist in os.walk(in_dir):
        for file in filelist:
            if file == VENV_ACTIVATE_SCRIPT_NAME:
                return pathmaker(dirname, file)
    return _find_venv_activate_script(pathmaker(in_dir, '../'), loop_count + 1, max_count=max_count)
def test_base_attributes(functions_finder):
    func_holder, base_folder = functions_finder
    assert func_holder.functions_folder == pathmaker(base_folder,
                                                     'A3-Antistasi',
                                                     'functions')
    assert func_holder.functions_hpp_file == pathmaker(base_folder,
                                                       'A3-Antistasi',
                                                       'functions.hpp')
    assert func_holder.exclude == []
    assert func_holder.found_functions is None
Beispiel #3
0
 def __init__(self, base_folder, exclude: list = None):
     self.template_holder = TemplateHolderPackage(os.getenv('APP_NAME'),
                                                  'templates', 'as_arma')
     self.base_folder = pathmaker(base_folder)
     self.functions_folder = self._find_functions_folder()
     self.functions_hpp_file = self._find_functions_hpp_file()
     self.exclude = [item.casefold()
                     for item in exclude] if exclude is not None else []
     self.found_functions = None
class LanguageHolder:
    Pickle = LoadType.Pickle
    Json = LoadType.Pickle
    last_updated_file = pathmaker(STORAGE_FOLDER, 'last_updated.pkl')
    update_cooldown = timedelta(days=1)

    def __init__(self, type_to_load: LoadType = None, refresh=True):
        self.last_updated = self.get_last_updated()
        self.type_to_load = self.Pickle if type_to_load is None else type_to_load
        if refresh is True and (self.last_updated is None
                                or self.last_updated + self.update_cooldown <
                                datetime.utcnow()):
            update = _download_syntax_highlighting_yaml()
            if update is True:
                self.last_updated = datetime.utcnow()
                pickleit(self.last_updated, self.last_updated_file)

    @property
    def languages(self):
        if self.type_to_load is LoadType.Pickle:
            return get_pickled(STORAGE_FILE_PICKLE)
        elif self.type_to_load is LoadType.Json:
            _out = {}
            for item in _to_named_tuple(loadjson(STORAGE_FILE_JSON)):
                _out[item.name.casefold()] = item
            return _out

    def get_last_updated(self):
        if os.path.isfile(self.last_updated_file) is False:
            return None
        return get_pickled(self.last_updated_file)

    def __getattr__(self, name):
        language_items = self.languages
        _language_item = language_items.get(name, None)
        if _language_item is None:
            for _name, item in language_items.items():
                if name in item.aliases:
                    _language_item = item
        if _language_item is None:
            raise AttributeError(f"Language '{name}' not found")
        return _language_item
Beispiel #5
0
    def collect_functions(self):
        self.found_functions = {}
        for top_folder in os.scandir(self.functions_folder):
            if os.path.isdir(top_folder.path) is True:
                if top_folder.name not in self.found_functions:
                    self.found_functions[top_folder.name] = []
                for function_file in os.scandir(top_folder.path):
                    path = pathmaker(os.path.basename(self.functions_folder),
                                     top_folder.name, function_file.name)
                    class_name = os.path.splitext(function_file.name)[0]
                    if '_' in class_name:
                        class_name = class_name.split('_', 1)[1]
                    function_name = self.antistasi_prefix + '_fnc_' + class_name
                    if function_file.name.casefold(
                    ) not in self.exclude and class_name.casefold(
                    ) not in self.exclude:

                        self.found_functions[top_folder.name].append(
                            ASFunctionItem(function_file.name, path,
                                           class_name, function_name))
Beispiel #6
0
    def create_package_items(in_text: str):
        normal = []
        from_git = []
        from_personal = []
        for line in in_text.splitlines():

            if '==' in line:
                name, version = line.strip().split('==')
                normal.append(FreezeItem(name, version))

            elif '@' in line:
                name, location = line.strip().split('@', 1)
                name = name.strip()
                location = location.strip()
                if location.startswith('git+https') or location.startswith('https:'):
                    from_git.append(FreezeItem(name, location, True))
                elif location.startswith('file'):
                    from_personal.append(FreezeItem(name, pathmaker(location), False, True))
                else:
                    raise TypeError(f'unknown value with name: "{name}" and location: "{location}"!')
        return normal, from_git, from_personal
def test_init(dep_finder, fake_top_module, fake_package_dir, this_dir):
    assert dep_finder.target_dir == pathmaker(fake_top_module)
    assert dep_finder.dependency_excludes == []
    assert dep_finder.ignore_dirs == []
    assert dep_finder.follow_links is True
    assert dep_finder.pypi_server.url == "https://pypi.python.org/pypi/"
    assert dep_finder.pypi_server.proxy is None
    assert dep_finder.dependencies is None
    assert str(dep_finder) == 'DependencyFinder'
    assert repr(dep_finder) == f"DependencyFinder({pathmaker(fake_top_module)}, {str([])}, {str([])}, {str(True)})"

    os.chdir(this_dir)
    new_dep_finder = DependencyFinder(this_dir, excludes=["uvloop", 'DIScord'],
                                      ignore_dirs=[fake_package_dir, r"C:\Program Files\Python38"],
                                      follow_links=False)
    assert new_dep_finder.target_dir == this_dir
    assert set(new_dep_finder.dependency_excludes) == set(['uvloop', 'discord'])
    assert set(new_dep_finder.ignore_dirs) == set([fake_package_dir, 'C:/Program Files/Python38'])
    assert new_dep_finder.follow_links is False
    assert new_dep_finder.pypi_server.url == "https://pypi.python.org/pypi/"
    assert new_dep_finder.pypi_server.proxy is None
    assert new_dep_finder.dependencies is None
Beispiel #8
0
# endregion [TODO]

# region [AppUserData]

# endregion [AppUserData]

# region [Logging]

log = glog.aux_logger(__name__)
log.info(glog.imported(__name__))

# endregion[Logging]

# region [Constants]

THIS_FILE_DIR = pathmaker(os.path.abspath(os.path.dirname(__file__)))
AS_BASE_FOLDER = pathmaker(
    r"D:\Dropbox\hobby\Modding\Programs\Github\Foreign_Repos\A3-Antistasi\A3-Antistasi"
)

# endregion[Constants]


class FunctionsHppFinder(AbstractBaseWorkjob):
    config_section = 'functions_hpp_finder'
    template_name = 'functions'
    antistasi_prefix = 'A3A'
    replacement_table = {}

    def __init__(self, base_folder, exclude: list = None):
        self.template_holder = TemplateHolderPackage(os.getenv('APP_NAME'),
# endregion [TODO]

# region [AppUserData]

# endregion [AppUserData]

# region [Logging]

log = glog.aux_logger(__name__)
log.info(glog.imported(__name__))

# endregion[Logging]

# region [Constants]
STORAGE_FOLDER = pathmaker(
    os.path.dirname(syntax_highlighting_data_storage.__file__))
GITHUB_SYNTAX_HIGHLIGHTING_YAML_URL = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml"
STORAGE_FILE_BASE = pathmaker(STORAGE_FOLDER, "syntax_highlighting_languages")
STORAGE_FILE_YAML = STORAGE_FILE_BASE + '.yml'
STORAGE_FILE_JSON = STORAGE_FILE_BASE + '.json'
STORAGE_FILE_PICKLE = STORAGE_FILE_BASE + '.pkl'
# endregion[Constants]


def _to_named_tuple(content: dict):
    _out = []
    for key, value in content.items():
        _out.append(
            SyntaxHighlightingLanguage(name=key,
                                       aliases=value.get('aliases', []),
                                       group=value.get("group", 'misc'),
def test_set_target_dir(dep_finder, fake_top_module, this_dir):
    assert dep_finder.target_dir == pathmaker(fake_top_module)
    dep_finder.set_target_dir(this_dir)
    assert dep_finder.target_dir == this_dir
    with pytest.raises(FileExistsError):
        dep_finder.set_target_dir(r"C:\\fantasy\\folder")
Beispiel #11
0
def this_dir():
    return pathmaker(THIS_FILE_DIR)
Beispiel #12
0
def temp_requirement_file():
    with TemporaryDirectory() as tempdir:
        yield pathmaker(tempdir, 'requirements.txt')
Beispiel #13
0
def fake_pyproject_file():
    with TemporaryDirectory() as tempdir:
        path = pathmaker(tempdir, "pyproject.toml")
        writeit(path, FAKE_PYPROJECT_STRING)
        yield path, FAKE_PYPROJECT_STRING
Beispiel #14
0
import pytest
from gidpublish.dependencies_tool import DependencyFinder
from gidpublish.utility.gidtools_functions import pathmaker, writeit
import os
from tempfile import TemporaryDirectory

THIS_FILE_DIR = os.path.abspath(os.path.dirname(__file__))
FAKE_PACKAGE_DIR = pathmaker(THIS_FILE_DIR, '../fake_package')
FAKE_PACKAGE_TOP_MODULE = pathmaker(FAKE_PACKAGE_DIR, 'fake_gidappdata')

FAKE_PYPROJECT_STRING = """[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "fake_gidappdata"
author = "Giddius"
home-page = "https://github.com/Giddius/GidAppData"
classifiers = ["License :: OSI Approved :: MIT License"]
description-file = "readme.md"
requires = [

]

[tool.flit.scripts]

"""


@pytest.fixture()
def fake_pyproject_file():
Beispiel #15
0
 def _find_functions_folder(self):
     for dirname, folderlist, filelist in os.walk(self.base_folder):
         for folder in folderlist:
             if folder.casefold() == 'functions':
                 return pathmaker(dirname, folder)
Beispiel #16
0
def _add_missing_files(existing_files, in_folder):
    for missing_file in VENV_SETTINGS_MANDATORY_FILES.difference(set(existing_files)):
        writeit(pathmaker(in_folder, missing_file), '')
Beispiel #17
0
 def _find_functions_hpp_file(self):
     for dirname, folderlist, filelist in os.walk(self.base_folder):
         for file in filelist:
             if file.casefold() == 'functions.hpp':
                 return pathmaker(dirname, file)