Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
14357dc
Update cli.py
RohanBhattaraiNP Dec 20, 2024
7f114e6
Update cli.py
RohanBhattaraiNP Dec 20, 2024
877b28d
Create bot.yaml
RohanBhattaraiNP Dec 20, 2024
2aadd34
Update cli.py
RohanBhattaraiNP Dec 20, 2024
3f83289
Update cli.py
RohanBhattaraiNP Dec 20, 2024
4691ac6
Create bot_yaml.py
RohanBhattaraiNP Dec 20, 2024
ab4153e
Update cli.py
RohanBhattaraiNP Dec 20, 2024
51322b7
Merge branch 'caltechlibrary:main' into tests
RohanBhattaraiNP Dec 20, 2024
5695213
Update bot.yaml
RohanBhattaraiNP Dec 20, 2024
4cfee65
Update cli.py
RohanBhattaraiNP Jan 6, 2025
d94ac45
Update cli.py
RohanBhattaraiNP Jan 6, 2025
f89248d
Update cli.py
RohanBhattaraiNP Jan 6, 2025
ef26d05
Create setup.cfg
RohanBhattaraiNP Jan 7, 2025
e80276e
Create pyproject.toml
RohanBhattaraiNP Jan 7, 2025
179467c
Update pyproject.toml
RohanBhattaraiNP Jan 7, 2025
54835c3
Update setup.cfg
RohanBhattaraiNP Jan 7, 2025
9e28684
Update setup.cfg
RohanBhattaraiNP Jan 7, 2025
78b114b
Update setup.py
RohanBhattaraiNP Jan 7, 2025
23dc291
Update setup.py
RohanBhattaraiNP Jan 7, 2025
e0c9469
Update setup.cfg
RohanBhattaraiNP Jan 7, 2025
ebe862e
Create update_setupcfg.yaml
RohanBhattaraiNP Jan 7, 2025
977a645
Update codemeta.json
RohanBhattaraiNP Jan 7, 2025
b5feedd
Sync setup.cfg with codemeta.json changes
github-actions[bot] Jan 7, 2025
eaea906
Update codemeta.json
RohanBhattaraiNP Jan 7, 2025
30e81e9
Add updated CITATION.cff from codemeta.json file
RohanBhattaraiNP Jan 7, 2025
8c2d8e3
Update update_setupcfg.yaml
RohanBhattaraiNP Jan 7, 2025
69f31d8
Update codemeta.json
RohanBhattaraiNP Jan 7, 2025
2ab560a
Sync setup.cfg with codemeta.json changes
github-actions[bot] Jan 7, 2025
232ec5f
Update codemeta.json
RohanBhattaraiNP Jan 7, 2025
f8c8743
Sync setup.cfg with codemeta.json changes
github-actions[bot] Jan 7, 2025
9cb0f05
Update codemeta.json
RohanBhattaraiNP Jan 8, 2025
970e58d
Sync setup.cfg with codemeta.json changes
github-actions[bot] Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ jobs:
with:
python-version: '3.x'

- name: Check for Required Environment Variables
env:
CALTECHDATA_TOKEN: ${{ secrets.CALTECHDATA_TOKEN }}
run: |
if [ -z "$CALTECHDATA_TOKEN" ]; then
echo "Error: CALTECHDATA_TOKEN environment variable is not set"
exit 1
fi

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/update_setupcfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Sync Codemeta with Setup

on:
push:
paths:
- codemeta.json

jobs:
sync-codemeta:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install jq for JSON parsing
run: sudo apt-get install -y jq

- name: Parse and update setup.cfg
run: |
# Extract values from codemeta.json
NAME=$(jq -r '.name' codemeta.json)
VERSION=$(jq -r '.version' codemeta.json)
AUTHORS=$(jq -r '[.author[] | .givenName + " " + .familyName] | join(", ")' codemeta.json)
AUTHOR_EMAILS=$(jq -r '[.author[] | .email // empty] | join(", ")' codemeta.json)
DESCRIPTION=$(jq -r '.description' codemeta.json)
URL=$(jq -r '.codeRepository // .url' codemeta.json)

# Update setup.cfg fields
sed -i "s/^name = .*/name = $NAME/" setup.cfg
sed -i "s/^version = .*/version = $VERSION/" setup.cfg
sed -i "s/^author = .*/author = $AUTHORS/" setup.cfg
sed -i "s/^author_email = .*/author_email = $AUTHOR_EMAILS/" setup.cfg
sed -i "s/^description = .*/description = $DESCRIPTION/" setup.cfg
sed -i "s|^url = .*|url = $URL|" setup.cfg

- name: Commit changes
run: |
if ! git diff --quiet; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add setup.cfg
git commit -m "Sync setup.cfg with codemeta.json changes"
git push
fi
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ keywords:
- metadata
- software
- InvenioRDM

date-released: 2025-01-07
137 changes: 110 additions & 27 deletions caltechdata_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def get_or_set_token(production=True):
print("Tokens do not match. Please try again.")


# Delete the saved token file.
def delete_saved_token():
token_file = os.path.join(caltechdata_directory, "token.txt")
if os.path.exists(token_file):
os.remove(token_file)
print("Token deleted successfully.")
else:
print("No token found to delete.")


def welcome_message():
print("Welcome to CaltechDATA CLI")

Expand Down Expand Up @@ -186,6 +196,61 @@ def get_funding_details():
}


# Add profile handling functions
def save_profile():
profile_file = os.path.join(caltechdata_directory, "profile.json")

# Get ORCID
while True:
orcid = get_user_input("Enter your ORCID identifier: ")
orcid = normalize_orcid(orcid)
family_name, given_name = get_names(orcid)
if family_name is not None and given_name is not None:
break
retry = input("Do you want to try again? (y/n): ")
if retry.lower() != "y":
return None

# Get funding details
funding_references = []
num_funding_entries = get_funding_entries()
for _ in range(num_funding_entries):
funding_references.append(get_funding_details())

profile_data = {
"orcid": orcid,
"family_name": family_name,
"given_name": given_name,
"funding_references": funding_references,
}

with open(profile_file, "w") as f:
json.dump(profile_data, f, indent=2)

print("Profile saved successfully!")
return profile_data


def load_profile():
profile_file = os.path.join(caltechdata_directory, "profile.json")
try:
with open(profile_file, "r") as f:
return json.load(f)
except FileNotFoundError:
return None


def get_or_create_profile():
profile = load_profile()
if profile:
use_saved = input("Use saved profile? (y/n): ").lower()
if use_saved == "y":
return profile

print("Creating new profile...")
return save_profile()


def parse_arguments():
welcome_message()
args = {}
Expand Down Expand Up @@ -222,23 +287,17 @@ def parse_arguments():
break
else:
print("Invalid input. Please enter a number between 1 and 8.")
# Load or create profile
profile = get_or_create_profile()
if profile:
args["orcid"] = profile["orcid"]
args["family_name"] = profile["family_name"]
args["given_name"] = profile["given_name"]
args["fundingReferences"] = profile["funding_references"]
else:
print("Failed to load or create profile. Exiting.")
return None

while True:
orcid = get_user_input("Enter your ORCID identifier: ")
family_name, given_name = get_names(orcid)
if family_name is not None and given_name is not None:
args["orcid"] = orcid
break # Break out of the loop if names are successfully retrieved
retry = input("Do you want to try again? (y/n): ")
if retry.lower() != "y":
print("Exiting program.")
return
# Optional arguments
num_funding_entries = get_funding_entries()
funding_references = []
for _ in range(num_funding_entries):
funding_references.append(get_funding_details())
args["fundingReferences"] = funding_references
return args


Expand Down Expand Up @@ -410,24 +469,48 @@ def parse_args():
parser.add_argument(
"-test", action="store_true", help="Use test mode, sets production to False"
)
parser.add_argument(
"--delete-token", action="store_true", help="Delete the saved token."
)
args = parser.parse_args()
return args


def normalize_orcid(val):
orcid_urls = ["https://orcid.org/", "http://orcid.org/", "orcid.org/"]
for orcid_url in orcid_urls:
if val.startswith(orcid_url):
val = val[len(orcid_url) :]
break

val = val.replace("-", "").replace(" ", "")
if len(val) != 16 or not val.isdigit():
raise ValueError(f"Invalid ORCID identifier: {val}")
return "-".join([val[0:4], val[4:8], val[8:12], val[12:16]])


def main():
args = parse_args()
production = not args.test
if args.delete_token:
delete_saved_token()
while True:
choice = get_user_input(
"What would you like to do? (create/edit/profile/exit): "
).lower()

production = not args.test # Set production to False if -test flag is provided

choice = get_user_input(
"Do you want to create or edit a CaltechDATA record? (create/edit): "
).lower()
if choice == "create":
create_record(production)
elif choice == "edit":
edit_record(production)
else:
print("Invalid choice. Please enter 'create' or 'edit'.")
if choice == "create":
create_record(production)
elif choice == "edit":
edit_record(production)
elif choice == "profile":
save_profile()
elif choice == "exit":
break
else:
print(
"Invalid choice. Please enter 'create', 'edit', 'profile', or 'exit'."
)


def create_record(production):
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
{
"@type": "Person",
"givenName": "Bhattarai",
"familyName": "Rohan ",
"givenName": "Rohan",
"familyName": "Bhattarai",
"affiliation": {
"@type": "Organization",
"name": "Caltech"
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
46 changes: 46 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[build-system]
requires = ["setuptools>=64.0","wheel"]
build-backend = "setuptools.build_meta"

[metadata]
name = caltechdata_api
version = 1.9.1
author = Thomas E Morrell, Rohan Bhattarai, Won Elizabeth, Alexander A Abakah
author_email = [email protected], [email protected]
description = Python wrapper for CaltechDATA API.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/caltechlibrary/caltechdata_api
license = MIT
classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: Implementation :: CPython
Operating System :: OS Independent

[options]
packages = find:
python_requires = >=3.6.0
install_requires =
requests
datacite>1.1.0
tqdm>=4.62.3
pyyaml
s3fs
cryptography
s3cmd
include_package_data = True

[options.packages.find]
exclude = tests

[options.entry_points]
console_scripts =
caltechdata_api=caltechdata_api.cli:main

[tool:pytest]
addopts = --verbose
Loading