Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ install_requires =
importlib-resources
psutil
packaging
sio3pack==1.0.0.dev1

[options.packages.find]
where = src
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sinol_make.task_type.interactive import InteractiveTaskType # noqa


__version__ = "1.9.7"
__version__ = "2.0.0.dev1"


def configure_parsers():
Expand Down
7 changes: 4 additions & 3 deletions src/sinol_make/commands/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sinol_make import util
from sinol_make.helpers import package_util, paths
from sinol_make.interfaces.BaseCommand import BaseCommand
from sinol_make.sio3pack.package import Sio3Package


class Command(BaseCommand):
Expand Down Expand Up @@ -92,7 +93,7 @@ def run(self, args: argparse.Namespace):
# when it is not provided by the user, instead of using the default
# behavior of defaulting to None.
if not hasattr(args, 'latex_compiler'):
config = package_util.get_config()
config = Sio3Package().get_config()
args.latex_compiler = config.get('sinol_latex_compiler', 'auto')

if args.latex_compiler == 'pdflatex':
Expand All @@ -104,13 +105,13 @@ def run(self, args: argparse.Namespace):
elif args.latex_compiler == 'auto':
self.compilation_method = 'pdflatex'
for extension in ['ps', 'eps']:
if glob.glob(os.path.join(os.getcwd(), 'doc', f'*.{extension}')) != []:
if glob.glob(os.path.join(os.getcwd(), 'doc', f'*.{extension}')): #TODO: SIO3Pack?
self.compilation_method = 'latex_dvi'
else:
util.exit_with_error("Unrecognized latex compiler")

if args.files == []:
self.files = glob.glob(os.path.join(os.getcwd(), 'doc', '*.tex'))
self.files = glob.glob(os.path.join(os.getcwd(), 'doc', '*.tex')) #TODO: SIO3Pack?
else:
self.files = []
for file in args.files:
Expand Down
3 changes: 2 additions & 1 deletion src/sinol_make/contest_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from sinol_make.helpers.func_cache import cache_result
from sinol_make.helpers.package_util import get_config
from sinol_make.interfaces.Errors import UnknownContestType
from sinol_make.sio3pack.package import Sio3Package


@cache_result(cwd=True)
def get_contest_type():
config = get_config()
config = Sio3Package().get_config()
contest_type = config.get("sinol_contest_type", "default").lower()

if contest_type == "default":
Expand Down
21 changes: 3 additions & 18 deletions src/sinol_make/helpers/package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@
from sinol_make.helpers.func_cache import cache_result
from sinol_make import util, contest_types
from sinol_make.helpers import paths
from sinol_make.sio3pack.package import Sio3Package
from sinol_make.task_type import BaseTaskType


@cache_result(cwd=True)
def get_task_id() -> str:
config = get_config()
if "sinol_task_id" in config:
return config["sinol_task_id"]
else:
print(util.warning("sinol_task_id not specified in config.yml. Using task id from directory name."))
task_id = os.path.split(os.getcwd())[-1]
if len(task_id) == 3:
return task_id
else:
util.exit_with_error("Invalid task id. Task id should be 3 characters long.")
return Sio3Package().get_task_id()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sinol_task_id in config should still be handled



def extract_test_id(test_path, task_id):
Expand Down Expand Up @@ -53,14 +45,7 @@ def get_test_key(test, task_id):


def get_config():
try:
with open(os.path.join(os.getcwd(), "config.yml"), "r") as config_file:
return yaml.load(config_file, Loader=yaml.FullLoader) or {}
except FileNotFoundError:
# Potentially redundant with util:exit_if_not_package
util.exit_with_error("You are not in a package directory (couldn't find config.yml in current directory).")
except yaml.YAMLError as e:
util.exit_with_error("config.yml is not a valid YAML. Fix it before continuing:\n" + str(e))
return Sio3Package().get_config()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no error handling:(



def get_solutions_re(task_id: str) -> re.Pattern:
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions src/sinol_make/sio3pack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from sio3pack import Package
from sio3pack import LocalFile


def _get_local_file():
return LocalFile(os.getcwd())


class Sio3Package:
"""
Singleton class for package base class.
"""

_instance = None

def __new__(cls) -> Package:
if cls._instance is None:
cls._instance = Package.from_file(_get_local_file())
return cls._instance

10 changes: 9 additions & 1 deletion src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sinol_make.helpers import paths, cache
from sinol_make.helpers.func_cache import cache_result
from sinol_make.structs.status_structs import Status

from sinol_make.sio3pack.package import Sio3Package

@cache_result()
def get_commands():
Expand Down Expand Up @@ -55,12 +55,20 @@ def find_and_chdir_package():
return False


def instantiate_package():
"""
Function to instantiate package from current directory.
"""
Sio3Package()


def init_package_command(args):
"""
Updates arguments with contest specific overrides for commands
that require being in package directory
"""
exit_if_not_package()
instantiate_package()
contest = get_contest_type()
contest.verify_config()
return contest.argument_overrides(args)
Expand Down
Loading