Skip to content

Commit

Permalink
Merge pull request #242 from Crypto-TII/fix/fix-create-bash-script-an…
Browse files Browse the repository at this point in the history
…d-documentation

Fix create_bash_script.py and documentation
  • Loading branch information
peacker authored Jun 10, 2024
2 parents 50736ba + 8cffad8 commit 3d71a1c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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`;\
Expand Down
82 changes: 50 additions & 32 deletions create_bash_script.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,72 @@
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

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_instructions.append(bash_instruction)
docker_command = ''
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 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()
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

if bash_instruction:
bash_instructions.append(bash_instruction)
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))
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 9 additions & 7 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.

0 comments on commit 3d71a1c

Please sign in to comment.