From a52b7afb131dd9960a6a080f3fbd5bbf1ae3edf5 Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Thu, 23 May 2024 16:59:15 +0200 Subject: [PATCH 1/6] Fix WORKDIR and COPY translations --- create_bash_script.py | 82 ++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/create_bash_script.py b/create_bash_script.py index 89004614..f83957c6 100644 --- a/create_bash_script.py +++ b/create_bash_script.py @@ -1,54 +1,70 @@ +import os import sys -with open('docker/Dockerfile', 'r') as f: + +with open("docker/Dockerfile", "r") as f: dockerfile_lines = f.readlines() -bash_instructions = ['#!/bin/bash'] -docker_command = '' +claasp_directory = os.path.abspath(".") +bash_instructions = ["#!/bin/bash"] environment_variables = [] +docker_command = "" + for line in dockerfile_lines: line = line.strip() - if line.startswith("FROM claasp-base AS claasp-lib"): - break + if line.startswith("FROM"): + continue - is_a_comment = line.startswith('#') - is_split_command = line.endswith('\\') + is_a_comment = line.startswith("#") if not line or is_a_comment: continue + + is_split_command = line.endswith("\\") if is_split_command: docker_command += line[:-1] continue docker_command += line - bash_instruction = '' - if docker_command.startswith('RUN'): - bash_instruction = docker_command.split('RUN')[1].strip() - elif docker_command.startswith('ENV'): - command = docker_command.split('ENV')[1].strip() - environment_variable = command.split('=')[0] - if environment_variable not in environment_variables: - environment_variables.append(environment_variable) - bash_instruction = f'export {command}' - elif docker_command.startswith('ARG'): - command = docker_command.split('ARG')[1].strip() - bash_instruction = f'export {command}' - elif docker_command.startswith('WORKDIR'): - directory = docker_command.split('WORKDIR')[1].strip() - if directory != '/home/sage/tii-claasp': - bash_instruction = f'cd {directory}' - elif docker_command.startswith('COPY'): - command = docker_command.split('COPY')[1].strip() - bash_instruction = f'cp {command}' - else: - docker_command = '' - continue + + bash_instruction = "" + match docker_command.split()[0]: + case "RUN": + bash_instruction = docker_command.split("RUN")[1].strip() + case "ENV": + command = docker_command.split("ENV")[1].strip() + environment_variable = command.split("=")[0] + if environment_variable not in environment_variables: + environment_variables.append(environment_variable) + bash_instruction = f"export {command}" + case "ARG": + command = docker_command.split("ARG")[1].strip() + bash_instruction = f"export {command}" + case "WORKDIR": + directory = docker_command.split("WORKDIR")[1].strip() + if os.path.exists(directory): + bash_instruction = f"cd {directory}" + else: + bash_instruction = f"mkdir {directory} && cd {directory}" + case "COPY": + command = docker_command.split("COPY")[1].strip() + src, dst = command.split() + src = f"{claasp_directory}{os.sep}{src}" + bash_instruction = f"cp {src} {dst}" + if os.path.isdir(src): + bash_instruction += " -r" + case _: + docker_command = "" + continue bash_instructions.append(bash_instruction) - docker_command = '' + docker_command = "" + for environment_variable in environment_variables: - bash_instructions.append(f"echo 'export {environment_variable}='${environment_variable} >> ~/.bashrc") + bash_instructions.append( + f"echo 'export {environment_variable}='${environment_variable} >> ~/.bashrc" + ) -with open('dependencies_script.sh', 'w') as f: - f.write('\n\n'.join(bash_instructions)) +with open("dependencies_script.sh", "w") as f: + f.write("\n\n".join(bash_instructions)) From d553d8b0e05ed8e0ae42f27b88e21d295ced4b58 Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Thu, 23 May 2024 17:09:19 +0200 Subject: [PATCH 2/6] Add locale instructions and fix name typo in last section --- docs/USER_GUIDE.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/USER_GUIDE.md b/docs/USER_GUIDE.md index d0e875f4..280f46ed 100644 --- a/docs/USER_GUIDE.md +++ b/docs/USER_GUIDE.md @@ -12,8 +12,8 @@ implemented using [Python3](https://www.python.org/) and [Cython](https://www.cy Download the source from the git repository: ``` - $ git clone https://github.com/Crypto-TII/claasp.git - $ cd tii-claasp/ + $ git clone https://github.com/Crypto-TII/claasp.git + $ cd claasp/ ``` CLAASP library is built on the top of SageMath, and it will try to pick the `sage` binary from `PATH` @@ -46,15 +46,17 @@ After the installation, we need to enter to the sage terminal with the command: After that we are ready to go and can use the library as specified in the [usage](#usage) section. ### Manual installation + To install the dependencies manually, you can do it through make command or executing a script from the -root directory of the project. +root directory of the project. Before doing this, make sure that you have set up `locale` correctly. #### Make command -You need to have `make` installed for this execution. Run ```make local-installation``` + +You need to have `make` installed for this execution. Run ```make local-installation```. #### Script execution -- For m1 macs, run ```./configure.sh armlinux64``` -- For other machines, run ```./configure.sh``` + +Alternatively, you can run ```./configure.sh```. ## Documentation @@ -98,4 +100,4 @@ Once the package is installed, you can use it in Sage with: ## Contributing the library -To contribute to the library, please follow the instructions in `docs/DEVELOPER_GUIDE.md` file. +To contribute to the library, please follow the instructions in `docs/CONTRIBUTING.md` file. From ab6e134cb79ad6e2af9cccd8c3c09d28a25f6b94 Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Thu, 23 May 2024 17:10:35 +0200 Subject: [PATCH 3/6] Fix typo in last section --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 1cd89545..0a55c867 100644 --- a/docs/README.md +++ b/docs/README.md @@ -33,5 +33,5 @@ be documented. When a file do not need to be documented, it has to be added in ## Methods excluded -Remeber that methods whose name starts with at least one `_` are not +Remember that methods whose name starts with at least one `_` are not automatically documented. From b0d3de0860f0d32864d52f4d83e431ee89dfd989 Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Fri, 24 May 2024 08:47:26 +0200 Subject: [PATCH 4/6] Change branch name from master to main --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 212a12a4..c31ddb04 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ DOCKER_IMG_NAME=claasp CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` all: install - if [ $(CURRENT_BRANCH) == "master" ]; then\ + if [ $(CURRENT_BRANCH) == "main" ]; then\ $(SAGE_BIN) setup.py testall;\ else\ $(SAGE_BIN) -t `{ git diff --name-only "*.py" ; git diff --name-only --staged "*.py"; } | uniq`;\ From ea9eb9fcbbc18dbbda5a3a38ef066792511a47a4 Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Tue, 28 May 2024 14:22:15 +0200 Subject: [PATCH 5/6] Stop Dockerfile traduction at last FROM --- create_bash_script.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/create_bash_script.py b/create_bash_script.py index f83957c6..322ff127 100644 --- a/create_bash_script.py +++ b/create_bash_script.py @@ -14,6 +14,8 @@ line = line.strip() if line.startswith("FROM"): + if line.startswith("FROM claasp-base AS claasp-lib"): + break continue is_a_comment = line.startswith("#") @@ -42,10 +44,11 @@ bash_instruction = f"export {command}" case "WORKDIR": directory = docker_command.split("WORKDIR")[1].strip() - if os.path.exists(directory): - bash_instruction = f"cd {directory}" - else: - bash_instruction = f"mkdir {directory} && cd {directory}" + if directory != '/home/sage/tii-claasp': + if os.path.exists(directory): + bash_instruction = f"cd {directory}" + else: + bash_instruction = f"mkdir {directory} && cd {directory}" case "COPY": command = docker_command.split("COPY")[1].strip() src, dst = command.split() @@ -57,7 +60,8 @@ docker_command = "" continue - bash_instructions.append(bash_instruction) + if bash_instruction: + bash_instructions.append(bash_instruction) docker_command = "" From 8cffad81797a8688e90c5adb724060ce0d750c8a Mon Sep 17 00:00:00 2001 From: MattiaOldani Date: Thu, 30 May 2024 00:22:33 +0200 Subject: [PATCH 6/6] Remove useless if statement --- create_bash_script.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/create_bash_script.py b/create_bash_script.py index 322ff127..d78dd674 100644 --- a/create_bash_script.py +++ b/create_bash_script.py @@ -13,10 +13,8 @@ for line in dockerfile_lines: line = line.strip() - if line.startswith("FROM"): - if line.startswith("FROM claasp-base AS claasp-lib"): - break - continue + if line.startswith("FROM claasp-base AS claasp-lib"): + break is_a_comment = line.startswith("#") if not line or is_a_comment: