Skip to content

Commit

Permalink
🏷️ Archive name parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
VForiel committed Oct 22, 2022
1 parent 14298e9 commit b650c6e
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 222 deletions.
102 changes: 55 additions & 47 deletions LRFutils/archive.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
import datetime
import os
import git

number = None

def next_number(path):
global number
max_num = 0
for file in os.listdir(path):
if "_" in file: file = file.split("_")[0]
try:
if int(file) > max_num: max_num = int(file)
except: pass
number = max_num + 1
return number

def new(name = None):
global number

timestamp = str(datetime.datetime.now()).split(" ")

try:
repo = git.Repo(search_parent_directories=True)
sha = "_" + repo.head.object.hexsha[:7]
except: sha = ""

path = "./archives/" + timestamp[0] + sha

if not os.path.isdir(path): os.makedirs(path)

if path is not None: next_number(path)
else: number = 1

if name is not None: name = "_" + name

if not os.path.isdir(f"{path}/{number}{name}"): os.makedirs(f"{path}/{number}{name}")


return f"{path}/{number}{name}"

def description(**kwargs):
desc = ""
for key,value in kwargs.items():
if type(value) in [int, str, float, bool] : desc += f",{key}={value}"
else: print(f"⚠️ Your archive description contain a non-supported type: {type(value)}")
return desc[1:]
import datetime
import os
import git

number = None

def next_number(path):
global number
max_num = 0
for file in os.listdir(path):
if "_" in file: file = file.split("_")[0]
try:
if int(file) > max_num: max_num = int(file)
except: pass
number = max_num + 1
return number

def new(name = None, verbose=False, **kwargs):
global number

if kwargs:
name = name + "-" + description(**kwargs)

timestamp = str(datetime.datetime.now()).split(" ")

try:
repo = git.Repo(search_parent_directories=True)
sha = "_" + repo.head.object.hexsha[:7]
except: sha = ""

path = "./archives/" + timestamp[0] + sha

if not os.path.isdir(path): os.makedirs(path)

if path is not None: next_number(path)
else: number = 1

if name is not None: name = "_" + name
else: name = ""

if not os.path.isdir(f"{path}/{number}{name}"): os.makedirs(f"{path}/{number}{name}")

archive_name = f"{path}/{number}{name}"

if verbose:
print(f"Archive created at {archive_name}")

return archive_name

def description(**kwargs):
desc = ""
for key,value in kwargs.items():
if type(value) in [int, str, float, bool] : desc += f",{key}={value}"
else: print(f"⚠️ Your archive description contain a non-supported type: {type(value)}")
return desc[1:]
50 changes: 29 additions & 21 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# 0.0.11

> **Warning**
>
> This update include breaking changes 💥
## 📢 Announcements
- This module is now available on Pypi!
https://pypi.org/project/LRFutils/0.0.11/
- You can then install it using `pip install LRFutils`

## ➕ Additions
- Added `average_ETA` parameter on progress bar to prevent variating ETA. By default, this parameter is set to 10

## 🔧 Tweaks
- 💥 `LRFutils.progress.Bar()`'s `duration` parameter was renamed in `show_duration` to be more explicit.
- 💥 `LRFutils.log` module was renamed `LRFutils.logs` in order to have a conveniant import line (`from LRFutils import logs`) while avoiding conflict with mathematical log function.
- 💥 `LRFutils.color.Color` class, was removed. All the attribute are now directly in the module `LRFutils.color` (which allow to import the module on the same line than other ones `from LRFutils import color, logs, archive [...]`)

# 0.0.10

# 0.0.12

## 🩹 Fixes
- Fixed `LRFutils.archive.new()` without name leanding to "None" in the archive name.

## 🔧 Tweaks
- Now, if any other parameter than `name` or `verbose` is given to the `LRFutils.archive.ew()` function, this parameter will be added to the name using `LRFutils.archive.description()` method.

# 0.0.11

> **Warning**
>
> This update include breaking changes 💥
## 📢 Announcements
- This module is now available on Pypi!
https://pypi.org/project/LRFutils/0.0.11/
- You can then install it using `pip install LRFutils`

## ➕ Additions
- Added `average_ETA` parameter on progress bar to prevent variating ETA. By default, this parameter is set to 10

## 🔧 Tweaks
- 💥 `LRFutils.progress.Bar()`'s `duration` parameter was renamed in `show_duration` to be more explicit.
- 💥 `LRFutils.log` module was renamed `LRFutils.logs` in order to have a conveniant import line (`from LRFutils import logs`) while avoiding conflict with mathematical log function.
- 💥 `LRFutils.color.Color` class, was removed. All the attribute are now directly in the module `LRFutils.color` (which allow to import the module on the same line than other ones `from LRFutils import color, logs, archive [...]`)

# 0.0.10

> 🔎 Changelog doesn't go that far...
61 changes: 61 additions & 0 deletions docs/archive.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🗃️ Archive"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Archive created at ./archives/2022-10-22_14298e9/1_My archive-p1=3.14,p2=42,p3=hello\n"
]
}
],
"source": [
"from LRFutils import archive\n",
"\n",
"parameter_1 = 3.14\n",
"parameter_2 = 42\n",
"parameter_3 = \"hello\"\n",
"\n",
"path = archive.new(\"My_archive\", verbose=True, p1=parameter_1, p2=parameter_2, p3=parameter_3)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.8 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "97cc609b13305c559618ec78a438abc56230b9381f827f22d070313b9a1f3777"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 0 additions & 3 deletions docs/archive.md

This file was deleted.

125 changes: 0 additions & 125 deletions examples.ipynb

This file was deleted.

44 changes: 22 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from setuptools import setup

requirements = []
with open('requirements.txt') as f:
requirements = f.read().splitlines()

setup(
name="LRFutils",
version = "0.0.11",
description = 'Just a custom library to share with some colleagues. Use it at your own risks.',
author = 'Leirof',
author_email = 'vince.lrf@gmail.com',
url = 'https://github.com/LeiRoF/Utils',
packages=['LRFutils'],
install_requires=requirements,
python_requires='>=3.10.0',
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Intended Audience :: Developers'
]
from setuptools import setup

requirements = []
with open('requirements.txt') as f:
requirements = f.read().splitlines()

setup(
name="LRFutils",
version = "0.0.12",
description = 'Just a custom library to share with some colleagues. Use it at your own risks.',
author = 'Leirof',
author_email = 'vince.lrf@gmail.com',
url = 'https://github.com/LeiRoF/Utils',
packages=['LRFutils'],
install_requires=requirements,
python_requires='>=3.10.0',
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Intended Audience :: Developers'
]
)
Loading

0 comments on commit b650c6e

Please sign in to comment.