Skip to content

[WIP] Extract ads.auth into standalone oracle-ads-auth package #1172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 26 additions & 20 deletions ads/__init__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*--

# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

from __future__ import print_function, division, absolute_import

import logging
import os
import sys
import logging
import json
from typing import Callable, Dict, Optional, Union
from pkgutil import extend_path

# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/#single-sourcing-the-package-version
if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata

__path__ = extend_path(__path__, __name__)
__version__ = metadata.version("oracle_ads")
import oci

import matplotlib.font_manager # causes matplotlib to regenerate its fonts
try:
import ads.auth # noqa: F401
except ImportError as ex:
raise ImportError(
"The `ads.auth` module is not available because the optional `oracle-ads-auth` package is missing.\n"
"To use authentication features in ADS, please install it using:\n"
" pip install oracle-ads-auth"
) from ex


import matplotlib.font_manager # causes matplotlib to regenerate its fonts
import oci
import ocifs

import ads.telemetry
from ads.auth import set_auth
from ads.common.config import Config
from ads.common.decorator.deprecate import deprecated
from ads.common.ipython import configure_plotting, _log_traceback
from ads.feature_engineering.accessor.series_accessor import ADSSeriesAccessor
from ads.common.ipython import _log_traceback, configure_plotting
from ads.feature_engineering.accessor.dataframe_accessor import ADSDataFrameAccessor
from ads.common import auth
from ads.common.auth import set_auth
from ads.common.config import Config
from ads.feature_engineering.accessor.series_accessor import ADSSeriesAccessor

os.environ["GIT_PYTHON_REFRESH"] = "quiet"


debug_mode = os.environ.get("DEBUG_MODE", False)
documentation_mode = os.environ.get("DOCUMENTATION_MODE", "False") == "True"
test_mode = os.environ.get("TEST_MODE", False)
resource_principal_mode = bool(
os.environ.get("RESOURCE_PRINCIPAL_MODE", False)
) # deprecated with is_resource_principal_mode() from ads.common.utils
resource_principal_mode = bool(os.environ.get("RESOURCE_PRINCIPAL_MODE", False))
orig_ipython_traceback = None

# Registers a global hook for enriching OCI client configuration with user agent metadata.
ads.auth.register_user_agent_hook(hook=ads.telemetry.update_oci_client_config)


def getLogger(name="ads"):
logger = logging.getLogger(name)
Expand Down Expand Up @@ -125,9 +134,6 @@ def _set_test_mode(mode=False):


def hello():
import oci
import ocifs

print(
f"""

Expand Down
165 changes: 165 additions & 0 deletions ads/ads_auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
./storage/
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
etc/
include/
lib/
lib64/
parts/
sdist/
share/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
notebooks/

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pyvenv.cfg

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Jetbrains
.idea
modules/
*.swp

# VsCode
.vscode

# pipenv
Pipfile
Pipfile.lock

# pyright
pyrightconfig.json

# persist dir for chromadb test
/data/

# vim
*.swp

# Python Wheel
*.whl

# The demo folder
.demo
62 changes: 62 additions & 0 deletions ads/ads_auth/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Contributing to Oracle Accelerated Data Science (ADS)

We welcome your contributions! There are multiple ways to contribute.

## Opening issues

For bugs or enhancement requests, file a GitHub issue unless it's
security related. When filing a bug, remember that the better written the bug is,
the more likely it is to be fixed. If you think you've found a security
vulnerability, don't raise a GitHub issue and follow the instructions in our
[security policy](./SECURITY.md).

## Contributing code

We welcome your code contributions. Before submitting code using a pull request,
you must sign the [Oracle Contributor Agreement](https://oca.opensource.oracle.com) (OCA) and
your commits need to include the following line using the name and e-mail
address you used to sign the OCA:

```text
Signed-off-by: Your Name <[email protected]>
```

This can be automatically added to pull requests by committing with `--sign-off`
or `-s`, for example:

```text
git commit --signoff
```

Only pull requests from committers that can be verified as having signed the OCA
are accepted.

## Branching strategy

Use GitHub flow branching strategy. With the GitHub flow, there are only 2 branches: main and feature.

1. Every change that is worked on is branched directly off of main into a feature branch.
2. Once a feature is ready it is tested on the feature branch and the code is reviewed before being merged to main.

Hotfixes, bugfixes are treated the same as feature branches.

## Pull request process

1. Ensure there is an issue created to track and discuss the fix or enhancement
you intend to submit.
2. Fork this repository.
3. Create a branch in your fork to implement the changes. We recommend using
the issue number as part of your branch name, for example `1234-fixes`.
4. Ensure that any documentation is updated with the changes that are required
by your change.
5. Ensure that any samples are updated if the base image has been changed.
6. Submit the pull request. *Don't leave the pull request blank*. Explain exactly
what your changes are meant to do and provide simple steps about how to validate
your changes. Ensure that you reference the issue you created as well.
7. We assign the pull request to 2-3 people for review before it is merged.

## Code of conduct

Follow the [Golden Rule](https://en.wikipedia.org/wiki/Golden_Rule). If you'd
like more specific guidelines, see the
[Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct/).
35 changes: 35 additions & 0 deletions ads/ads_auth/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Copyright (c) 2020, 2022 Oracle and/or its affiliates.

The Universal Permissive License (UPL), Version 1.0

Subject to the condition set forth below, permission is hereby granted to any
person obtaining a copy of this software, associated documentation and/or data
(collectively the "Software"), free of charge and under any and all copyright
rights in the Software, and any and all patent rights owned or freely
licensable by each licensor hereunder covering either (i) the unmodified
Software as contributed to or provided by such licensor, or (ii) the Larger
Works (as defined below), to deal in both

(a) the Software, and
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
one is included with the Software (each a "Larger Work" to which the Software
is contributed by such licensors),

without restriction, including without limitation the rights to copy, create
derivative works of, display, perform, and distribute the Software and make,
use, sell, offer for sale, import, export, have made, and have sold the
Software and the Larger Work(s), and to sublicense the foregoing rights on
either these or other terms.

This license is subject to the following condition:
The above copyright notice and either this complete permission notice or at
a minimum a reference to the UPL must be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions ads/ads_auth/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)

dist: clean
@python3 -m build

publish: dist
@twine upload dist/*

clean:
@echo "Cleaning - removing dist, *.pyc, Thumbs.db and other files"
@rm -rf dist build oracle_ads.egg-info
@find ./ -name '*.pyc' -exec rm -f {} \;
@find ./ -name 'Thumbs.db' -exec rm -f {} \;
@find ./ -name '*~' -exec rm -f {} \;
@find ./ -name '.DS_Store' -exec rm -f {} \;

help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'

format: ## Run code autoformatters (black).
pre-commit install
git ls-files | xargs pre-commit run black --files

lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files

test: ## Run tests via pytest.
pytest tests

watch-docs: ## Build and watch documentation.
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Loading
Loading