Skip to content

Commit

Permalink
Merge pull request #526 from singnet/development
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
kiruxaspb authored Nov 18, 2024
2 parents 53a28d7 + 10d2d7e commit 02cc84c
Show file tree
Hide file tree
Showing 27 changed files with 889 additions and 607 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ snet.cli.egg-info/
snet/cli/resources/node_modules
snet/cli/resources/proto/*.py
build/
*.rst
dist/
*.pyi
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SingularityNET CLI
# SingularityNET CLI

## Package

Expand Down Expand Up @@ -127,28 +127,45 @@ Backward compatibility for other Python versions is not guaranteed.
$ git clone https://github.com/singnet/snet-cli.git
$ cd snet-cli/packages/snet_cli
```

*

* Install the package in development/editable mode

```bash
$ pip3 install -e .
```

#### Building the Documentation
### Building the Documentation in Markdown files

* Clone repository and install dependencies

* Install sphinx, sphinx-argparse and the rtd theme
```bash
$ pip install sphinx
$ pip install sphinx-argparse
$ pip install sphinx-rtd-theme
```
$ git clone https://github.com/singnet/snet-cli.git
$ cd snet-cli
$ pip install -r docs/requirements.txt
```

#### On Linux

* Run the build-docs.sh in the docs directory

```bash
$ cd docs
$ sh build-docs.sh
```

The documentation is generated under the docs/build/html folder
#### On Windows

* Install `make` utility and run the build-docs.ps1 in the docs directory

```powershell
choco install make # install choco if it is not already installed
cd docs
powershell -file build-docs.ps1
```

The documentation is generated under the docs/build/markdown folder

### Release

Expand Down
34 changes: 0 additions & 34 deletions blockchain/package-lock.json

This file was deleted.

6 changes: 0 additions & 6 deletions blockchain/package.json

This file was deleted.

12 changes: 12 additions & 0 deletions docs/build-docs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cd source
python generate_rst.py
cd ..

make clean
make html
Copy-Item source/snet-cli-static/theme.css build/html/_static/css/

cd source
python generate_markdown.py ../build/html/ ../build/html/clean ../build/markdown
cd ..
Remove-Item -Path build/html/clean -Recurse
9 changes: 7 additions & 2 deletions docs/build-docs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
cd source
python generate_rst.py

cd ..

make clean
make html
cp source/snet-cli-static/theme.css build/html/_static/css/
cp source/snet-cli-static/theme.css build/html/_static/css/

cd source
python generate_markdown.py ../build/html/ ../build/html/clean ../build/markdown
cd ..
rm -rf build/html/clean
5 changes: 5 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sphinx~=8.1.3
sphinx-argparse~=0.5.2
sphinx-rtd-theme~=3.0.1
bs4~=0.0.2
html2text~=2024.2.26
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -189,4 +189,4 @@
# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
# intersphinx_mapping = {'https://docs.python.org/': None}
150 changes: 150 additions & 0 deletions docs/source/generate_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import os
import sys
import re
from bs4 import BeautifulSoup


def process_html_file(file_path, output_dir, markdown_dir):
with open(file_path, 'r', encoding='utf-8') as file:
html_content = file.read()

soup = BeautifulSoup(html_content, 'html.parser')

footers = soup.find_all('footer')
for footer in footers:
footer.decompose()

navigations = soup.find_all('nav')
for navigation in navigations:
navigation.decompose()

hr = soup.find('hr')
if hr:
hr.decompose()

ul = soup.find('ul', class_='wy-breadcrumbs')
if ul:
ul.decompose()

headerlinks = soup.find_all('a', class_='headerlink')
for headerlink in headerlinks:
headerlink.decompose()

code_blocks = soup.find_all('div', class_='highlight-default notranslate')
for block in code_blocks:
pre_tag = soup.new_tag("p")
pre_tag.append("start ")
pre_tag.append(block.get_text().strip())
pre_tag.append(" finish")
block.replace_with(pre_tag)

clean_html = str(soup)

base_filename = os.path.basename(file_path)
output_path = os.path.join(output_dir, base_filename)

with open(output_path, 'w', encoding='utf-8') as file:
file.write(clean_html)
print(f"Processed: {file_path} -> {output_path}")

clean_filename = os.path.splitext(base_filename)[0] + ".md"
md_output_path = os.path.join(markdown_dir, clean_filename)

os.system(f"html2text --ignore-images {output_path} > {md_output_path}")

if sys.platform.startswith('win'):
with open(md_output_path, 'r') as file:
md_content = file.read()
else:
with open(md_output_path, 'r', encoding='utf-8') as file:
md_content = file.read()

clean_md = format_code_elements(md_content)
clean_md = clean_md.replace("\n### ", "\n## ")
clean_md = clean_md.replace("<", "\<") # fix tags errors
clean_md = clean_md.replace(">", "\>") # fix tags errors
clean_md = clean_md.replace("````", "```")
clean_md = delete_beginning(clean_md)

with open(md_output_path, 'w', encoding='utf-8') as file:
file.write(clean_md)

print(f"Processed: {output_path} -> {md_output_path}\n")


def format_code_elements(text: str):
substrings = []
start_index = 0
while True:
start_index = text.find("start", start_index)
if start_index == -1:
break

end_index = text.find("finish", start_index + 5)
if end_index == -1:
break

substrings.append(text[start_index + 5:end_index])
start_index = end_index + 6

results = []
for code in substrings:
res = re.sub(r'\s+', ' ', code).strip()

res_split = list(res.split())
length = len(res_split[0]) + len(res_split[1]) + len(res_split[2]) + 3
ind = ' ' * length
res = res.replace('] [', ']\n' + ind + '[')

results.append(res)

for i in range(len(results)):
text = text.replace("start" + substrings[i] + "finish", "```sh\n" + results[i] + "\n```")

return text


def delete_beginning(text: str):
start_index = text.find("## Commands")
end_index = text.find("## Sub-commands")
if start_index == -1 or end_index == -1:
return text

return text.replace(text[start_index + 11:end_index + 15], "")


def process_html_files_in_directory(directory, output_dir, markdown_dir):
if not os.path.exists(output_dir):
os.makedirs(output_dir)

if not os.path.exists(markdown_dir):
os.makedirs(markdown_dir)

for file in os.listdir(directory):
if file.endswith('.html'):
file_path = os.path.join(directory, file)
process_html_file(file_path, output_dir, markdown_dir)


def main():
if len(sys.argv) == 4:
input_html_directory: str = sys.argv[1]
output_html_directory: str = sys.argv[2]
output_md_directory: str = sys.argv[3]
else:
raise Exception("""
You can only pass 3 parameters:
- input_html_directory
- output_html_directory
- output_md_directory
""")

process_html_files_in_directory(
input_html_directory,
output_html_directory,
output_md_directory
)


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mnemonic==0.20
pycoin==0.92.20230326
pyyaml==6.0.1
ipfshttpclient==0.4.13.2
rfc3986==2.0.0
pymultihash==0.8.2
base58==2.1.1
argcomplete==3.1.2
Expand Down
Loading

0 comments on commit 02cc84c

Please sign in to comment.