Skip to content

Commit

Permalink
[SCRIPTs]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Dec 21, 2023
1 parent 4e7fcb9 commit 37f9877
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 22 deletions.
19 changes: 0 additions & 19 deletions code_quality.sh

This file was deleted.

3 changes: 0 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ copyright: "© APAC Corp, Inc."
extra_css:
- docs/assets/css/extra.css
extra:
# analytics:
# provider: google
# property: G-QM8EDPSCB6
social:
- icon: fontawesome/solid/house
link: assets/img/ZetaLogoIcon.png
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pandas
zetascale
mamba-ssm
causal-conv1d
pytest



Expand Down
19 changes: 19 additions & 0 deletions scripts/code_quality.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Navigate to the directory containing the 'swarms' folder
# cd /path/to/your/code/directory

# Run autopep8 with max aggressiveness (-aaa) and in-place modification (-i)
# on all Python files (*.py) under the 'swarms' directory.
autopep8 --in-place --aggressive --aggressive --recursive --experimental --list-fixes swarms/

# Run black with default settings, since black does not have an aggressiveness level.
# Black will format all Python files it finds in the 'swarms' directory.
black --experimental-string-processing swarms/

# Run ruff on the 'swarms' directory.
# Add any additional flags if needed according to your version of ruff.
ruff --unsafe_fix

# YAPF
yapf --recursive --in-place --verbose --style=google --parallel swarms
39 changes: 39 additions & 0 deletions scripts/get_package_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pkg_resources


def get_package_versions(requirements_path, output_path):
try:
with open(requirements_path, "r") as file:
requirements = file.readlines()
except FileNotFoundError:
print(f"Error: The file '{requirements_path}' was not found.")
return

package_versions = []

for requirement in requirements:
# Skip empty lines and comments
if (
requirement.strip() == ""
or requirement.strip().startswith("#")
):
continue

# Extract package name
package_name = requirement.split("==")[0].strip()
try:
version = pkg_resources.get_distribution(
package_name
).version
package_versions.append(f"{package_name}=={version}")
except pkg_resources.DistributionNotFound:
package_versions.append(f"{package_name}: not installed")

with open(output_path, "w") as file:
for package_version in package_versions:
file.write(package_version + "\n")
print(f"Versions written to {output_path}")


# Usage
get_package_versions("requirements.txt", "installed_versions.txt")
40 changes: 40 additions & 0 deletions scripts/requirementstxt_to_pyproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import toml
import pkg_resources


def update_pyproject_versions(pyproject_path):
try:
with open(pyproject_path, "r") as file:
data = toml.load(file)
except FileNotFoundError:
print(f"Error: The file '{pyproject_path}' was not found.")
return
except toml.TomlDecodeError:
print(
f"Error: The file '{pyproject_path}' is not a valid TOML"
" file."
)
return

dependencies = (
data.get("tool", {}).get("poetry", {}).get("dependencies", {})
)

for package in dependencies:
if package.lower() == "python":
continue # Skip the Python version dependency

try:
version = pkg_resources.get_distribution(package).version
dependencies[package] = version
except pkg_resources.DistributionNotFound:
print(f"Warning: Package '{package}' not installed.")

with open(pyproject_path, "w") as file:
toml.dump(data, file)

print(f"Updated versions written to {pyproject_path}")


# Usage
update_pyproject_versions("pyproject.toml")
8 changes: 8 additions & 0 deletions scripts/test_name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
find ./tests -name "*.py" -type f | while read file
do
filename=$(basename "$file")
dir=$(dirname "$file")
if [[ $filename != test_* ]]; then
mv "$file" "$dir/test_$filename"
fi
done
1 change: 1 addition & 0 deletions scripts/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find ./tests -name '*.py' -exec pytest {} \;

0 comments on commit 37f9877

Please sign in to comment.