Skip to content

Commit f88d5e5

Browse files
nft_storage removed (#261)
* del : nft_storage method removed * del : Gateway enum removed * del : nft_upload_test.py removed * fix : test.yml updated * doc : README.md updated * fix : params.py updated * doc : CHANGELOG.md updated * fix : unused imports removed * fix : requirements.txt updated * fix : tests updated * fix : test.yml updated * fix : autopep8 * fix : save_fig_buf function coverage
1 parent 3aa970c commit f88d5e5

File tree

11 files changed

+13
-289
lines changed

11 files changed

+13
-289
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ jobs:
4949
python otherfiles/requirements-splitter.py
5050
pip install --upgrade --upgrade-strategy=only-if-needed -r test-requirements.txt
5151
- name: Test with pytest
52-
run: |
53-
python -m pytest --ignore-glob="*nft_upload_test.py" test --cov=samila --cov-report=term
54-
- name: Test with pytest (+ NFT upload test)
5552
run: |
5653
python -m pytest test --cov=samila --cov-report=term
57-
env:
58-
NFT_STORAGE_API_KEY: ${{ secrets.NFT_STORAGE_API_KEY }}
59-
if: matrix.python-version == env.TEST_PYTHON_VERSION && matrix.os == env.TEST_OS
6054
- name: Version check
6155
run: |
6256
python otherfiles/version_check.py

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
2. `F2_VS_F1F2`
1212
### Changed
1313
- `README.md` updated
14+
- `demo.ipynb` updated
1415
- Test system modified
1516
- `Python 3.6` support dropped
1617
- Python typing features added to all modules
18+
### Removed
19+
- `nft_storage` method
20+
- `Gateway` enum
1721
## [1.5] - 2025-01-22
1822
### Added
1923
- 3 new generation modes

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -245,38 +245,6 @@ You can make your custom color map and use it in Samila.
245245
```
246246
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/5.png">
247247

248-
### NFT.storage
249-
Upload generated image directly to [NFT.storage](https://NFT.storage)
250-
251-
```pycon
252-
>>> g.nft_storage(api_key="YOUR_API_KEY", timeout=5000)
253-
{'status': True, 'message': 'FILE_LINK'}
254-
```
255-
256-
You can also upload your config/data to nft storage as follows:
257-
```pycon
258-
>>> g.nft_storage(api_key="API_KEY", upload_config=True)
259-
{'status': {'image': True, 'config':True}, 'message': {'image':'IMAGE_FILE_LINK', 'config':'CONFIG_FILE_LINK'}
260-
```
261-
or
262-
```pycon
263-
>>> g.nft_storage(api_key="API_KEY", upload_data=True)
264-
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
265-
```
266-
267-
You have the option to choose a specific IPFS gateway:
268-
```pycon
269-
>>> from samila import Gateway
270-
>>> g.nft_storage(api_key="API_KEY", upload_data=True, gateway=Gateway.DWEB)
271-
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
272-
```
273-
274-
275-
⚠️ This method is deprecated and may be removed in future releases
276-
277-
ℹ️ Default timeout is `3000` seconds
278-
279-
ℹ️ Default gateway is `IPFS_IO`
280248

281249
### Save image
282250
Save generated image.

examples/demo.ipynb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -472,74 +472,6 @@
472472
"g1.generate()\n",
473473
"g1.plot()"
474474
]
475-
},
476-
{
477-
"cell_type": "markdown",
478-
"metadata": {},
479-
"source": [
480-
"## NFT.storage"
481-
]
482-
},
483-
{
484-
"cell_type": "markdown",
485-
"metadata": {},
486-
"source": [
487-
"Upload generated image directly to [NFT.storage](https://nft.storage)."
488-
]
489-
},
490-
{
491-
"cell_type": "code",
492-
"execution_count": null,
493-
"metadata": {},
494-
"outputs": [],
495-
"source": [
496-
"g1.nft_storage(api_key=\"YOUR_API_KEY\")"
497-
]
498-
},
499-
{
500-
"cell_type": "code",
501-
"execution_count": null,
502-
"metadata": {},
503-
"outputs": [],
504-
"source": [
505-
"g1.nft_storage(api_key=\"YOUR_API_KEY\", timeout=5000)"
506-
]
507-
},
508-
{
509-
"cell_type": "markdown",
510-
"metadata": {},
511-
"source": [
512-
"You can also upload your config/data to nft storage as follows:"
513-
]
514-
},
515-
{
516-
"cell_type": "code",
517-
"execution_count": null,
518-
"metadata": {},
519-
"outputs": [],
520-
"source": [
521-
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_config=True)"
522-
]
523-
},
524-
{
525-
"cell_type": "code",
526-
"execution_count": null,
527-
"metadata": {},
528-
"outputs": [],
529-
"source": [
530-
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_data=True)"
531-
]
532-
},
533-
{
534-
"cell_type": "markdown",
535-
"metadata": {},
536-
"source": [
537-
"⚠️ This method is deprecated and may be removed in future releases\n",
538-
"\n",
539-
"ℹ️ Default timeout is `3000` seconds\n",
540-
"\n",
541-
"ℹ️ Default gateway is `IPFS_IO`"
542-
]
543475
}
544476
],
545477
"metadata": {

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
matplotlib>=3.0.0
2-
requests>=2.20.0
32
art>=1.8
43
Pillow>=6.2

samila/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""Samila modules."""
33
from .genimage import GenerativeImage
4-
from .params import Projection, GenerateMode, Marker, Gateway, VALID_COLORS, SAMILA_VERSION
4+
from .params import Projection, GenerateMode, Marker, VALID_COLORS, SAMILA_VERSION
55
from .errors import samilaDataError, samilaGenerateError
66
__version__ = SAMILA_VERSION

samila/functions.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Callable, Tuple, Dict, Generator, List
44
from typing import Any, Union, Iterable
55
import sys
6-
import requests
76
import io
87
import os
98
import re
@@ -12,14 +11,14 @@
1211
import matplotlib
1312
from PIL import Image
1413
from functools import wraps
15-
from .params import Projection, GenerateMode, Marker, Gateway
14+
from .params import Projection, GenerateMode, Marker
1615
from .params import SAMILA_VERSION
1716
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
1817
from .params import DEFAULT_CMAP_NAME, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION, DEFAULT_GENERATE_MODE
1918
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
20-
from .params import VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, OVERVIEW
19+
from .params import VALID_COLORS, HEX_COLOR_PATTERN, OVERVIEW
2120
from .params import DATA_TYPE_ERROR, DATA_FORMAT_ERROR, CONFIG_TYPE_ERROR, CONFIG_FORMAT_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
22-
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
21+
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
2322
from .params import INVALID_COLOR_TYPE_ERROR, COLOR_SIZE_ERROR
2423
from .params import BOTH_COLOR_COMPLEMENT_WARNING, COLOR_NOT_FOUND_WARNING, DEPRECATION_WARNING
2524
from .params import DATA_SAVE_SUCCESS_MESSAGE, SEED_LOWER_BOUND, SEED_UPPER_BOUND
@@ -508,41 +507,6 @@ def _GI_initializer(g: "GenerativeImage", function1: Callable, function2: Callab
508507
g.missed_points_number = 0
509508

510509

511-
def nft_storage_upload(
512-
api_key: str,
513-
data: bytes,
514-
timeout: int,
515-
gateway: Gateway) -> Dict[str, Any]:
516-
"""
517-
Upload file to nft.storage.
518-
519-
:param api_key: API key
520-
:param data: image data
521-
:param timeout: upload timeout (in seconds)
522-
:param gateway: IPFS gateway
523-
"""
524-
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
525-
try:
526-
headers = {'Authorization': 'Bearer {0}'.format(api_key)}
527-
response = requests.post(
528-
url=NFT_STORAGE_API,
529-
data=data,
530-
headers=headers,
531-
timeout=timeout)
532-
response_json = response.json()
533-
if response_json["ok"]:
534-
result["message"] = gateway.value.format(
535-
response_json['value']['cid'])
536-
return result
537-
result["status"] = False
538-
result["message"] = response_json["error"]["message"]
539-
return result
540-
except Exception as e:
541-
result["status"] = False
542-
result["message"] = str(e)
543-
return result
544-
545-
546510
def save_data_file(g: "GenerativeImage", file_adr: str) -> Dict[str, Any]:
547511
"""
548512
Save data as file.
@@ -682,7 +646,7 @@ def save_fig_file(figure: matplotlib.figure.Figure, file_adr: str, depth: float)
682646
return result
683647

684648

685-
def save_fig_buf(figure: matplotlib.figure.Figure, depth: float) -> Dict[str, Any]:
649+
def save_fig_buf(figure: matplotlib.figure.Figure, depth: float) -> Dict[str, Any]: # pragma: no cover
686650
"""
687651
Save figure as buffer.
688652

samila/genimage.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
from typing import List, Tuple, Dict, Callable
44
from typing import Union, Iterable
55
from typing import Any
6-
import json
76
import random
87
import io
98
import gc
109
import itertools
1110
import matplotlib
1211
import matplotlib.pyplot as plt
1312
from .functions import _GI_initializer, plot_params_filter, generate_params_filter, save_params_filter
14-
from .functions import get_config, get_data, get_python_version
15-
from .functions import float_range, save_data_file, save_fig_file, save_fig_buf, save_config_file
16-
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload
17-
from .functions import set_background, rotate, deprecated
13+
from .functions import get_python_version
14+
from .functions import float_range, save_data_file, save_fig_file, save_config_file
15+
from .functions import load_data, load_config, random_equation_gen
16+
from .functions import set_background, rotate
1817
from .params import *
1918
from warnings import warn, catch_warnings, simplefilter
2019

@@ -216,56 +215,6 @@ def plot(
216215
ax = rotate(fig, ax, self.rotation)
217216
self.fig = fig
218217

219-
@deprecated
220-
def nft_storage(
221-
self,
222-
api_key: str,
223-
upload_data: bool = False,
224-
upload_config: bool = False,
225-
depth: float = None,
226-
timeout: int = 3000,
227-
gateway: Gateway = Gateway.IPFS_IO) -> Dict[str, Any]:
228-
"""
229-
Upload image to nft.storage.
230-
231-
:param api_key: API key
232-
:param upload_data: upload data flag
233-
:param upload_config: upload config flag
234-
:param depth: image depth
235-
:param timeout: upload timeout (in seconds)
236-
:param gateway: IPFS gateway
237-
"""
238-
save_params_filter(self, depth)
239-
response = save_fig_buf(self.fig, self.depth)
240-
if not response["status"]:
241-
return {"status": False, "message": response["message"]}
242-
buf = response["buffer"]
243-
response = nft_storage_upload(
244-
api_key=api_key,
245-
data=buf.getvalue(),
246-
timeout=timeout,
247-
gateway=gateway)
248-
if upload_config == False and upload_data == False:
249-
return response
250-
result = {key: {'image': value} for key, value in response.items()}
251-
if upload_config:
252-
response = nft_storage_upload(
253-
api_key=api_key,
254-
data=json.dumps(get_config(self)),
255-
timeout=timeout,
256-
gateway=gateway)
257-
for key, value in response.items():
258-
result[key]['config'] = value
259-
if upload_data:
260-
response = nft_storage_upload(
261-
api_key=api_key,
262-
data=json.dumps(get_data(self)),
263-
timeout=timeout,
264-
gateway=gateway)
265-
for key, value in response.items():
266-
result[key]['data'] = value
267-
return result
268-
269218
def save_image(self, file_adr: str, depth: float = None) -> Dict[str, Any]:
270219
"""
271220
Save generated image.

samila/params.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
matplotlib.colors.BASE_COLORS,
3737
**matplotlib.colors.CSS4_COLORS))
3838
HEX_COLOR_PATTERN = r'^#(?:[0-9a-fA-F]{3}){1,2}$'
39-
NFT_STORAGE_API = "https://api.nft.storage/upload"
40-
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good."
4139
FIG_SAVE_SUCCESS_MESSAGE = "Everything seems good."
4240
DATA_SAVE_SUCCESS_MESSAGE = "Everything seems good."
4341
NO_FIG_ERROR_MESSAGE = "No figure was found. First run `generate` and `plot` methods."
@@ -99,36 +97,6 @@ class GenerateMode(Enum):
9997
RANDOM = "random"
10098

10199

102-
class Gateway(Enum):
103-
"""
104-
IPFS gateway class.
105-
106-
>>> import samila
107-
>>> gateway = samila.Gateway.IPFS_IO
108-
"""
109-
110-
CID = "{0}"
111-
IPFS_IO = "https://ipfs.io/ipfs/{0}"
112-
GATEWAY_IPFS_IO = "https://gateway.ipfs.io/ipfs/{0}"
113-
VIA0 = "https://via0.com/ipfs/{0}"
114-
CLOUDFLARE_IPFS = "https://cloudflare-ipfs.com/ipfs/{0}"
115-
HARDBIN = "https://hardbin.com/ipfs/{0}"
116-
PINATA = "https://gateway.pinata.cloud/ipfs/{0}"
117-
JORROPO = "https://jorropo.net/ipfs/{0}"
118-
DWEB = "https://dweb.link/ipfs/{0}"
119-
BEST_PRACTICE = "https://ipfs.best-practice.se/ipfs/{0}"
120-
RUNFISSION = "https://ipfs.runfission.com/ipfs/{0}"
121-
ARAGON_NETWORK = "https://ipfs.eth.aragon.network/ipfs/{0}"
122-
TEXTILE = "https://hub.textile.io/ipfs/{0}"
123-
EVERLAND = "https://{0}.ipfs.4everland.io"
124-
CF_IPFS = "https://{0}.ipfs.cf-ipfs.com"
125-
LITNET = "https://ipfs.litnet.work/ipfs/{0}"
126-
JPU = "https://ipfs.jpu.jp/ipfs/{0}"
127-
CZIP = "https://ipfs.czip.it/ipfs/{0}"
128-
W3S = "https://{0}.ipfs.w3s.link"
129-
GW3 = "https://{0}.ipfs.gw3.io"
130-
131-
132100
class Projection(Enum):
133101
"""
134102
Samila Projection type class.

test/nft_upload_test.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)