Skip to content

Commit

Permalink
Add twine example
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Oct 14, 2024
1 parent 36e011d commit c992342
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python-example/pip-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This example demonstrates how to build a Python Pip project with Artifactory, wh
## Before Running the Example
### Set Up the Environment
1. Make sure **Python** is installed and the **python** command is in your PATH.
2. Install **pip**. You can use the [Pip Documentation](https://pip.pypa.io/en/stable/installing/) and also [Installing packages using pip and virtual environments](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)
2. Install **pip**. You can use the [Pip Documentation](https://pip.pypa.io/en/stable/installation/) and also [Installing packages using pip and virtual environments](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)
3. Create three Pypi repositories in Artifactory - a local, remote and a virtual repository. You can use the [PyPi Repositories Documentation](https://www.jfrog.com/confluence/display/RTF/PyPI+Repositories).
* The remote repository should proxy *https://files.pythonhosted.org* (the default when creating a Pypi remote repository).
* Name the virtual repository *pypi*.
Expand Down Expand Up @@ -74,4 +74,4 @@ Validate package successfully installed:
> pip show jfrog-python-example
```

Learn about [Building Python Packages with JFrog CLI](https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-BuildingPythonPackages).
Learn about [Building Python Packages with JFrog CLI](https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-for-jfrog-artifactory/package-managers-integration#building-python-packages).
2 changes: 1 addition & 1 deletion python-example/pipenv-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Publish the build info to Artifactory:
Install published package by installing it from Artifactory using pip:
> jf pipenv install jfrog-pipenv-example

Learn about [Building Python Packages with JFrog CLI](https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-BuildingPythonPackages).
Learn about [Building Python Packages with JFrog CLI](https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-for-jfrog-artifactory/package-managers-integration#building-python-packages).
68 changes: 68 additions & 0 deletions python-example/twine-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Pip Example

## Overview
This example demonstrates how to build a Python Pip project with Artifactory, deploying it using Twine, while collecting build-info.

## Before Running the Example
### Set Up the Environment
1. Make sure **Python** is installed and the **python** command is in your PATH.
2. Install **pip**. You can use the [Pip Documentation](https://pip.pypa.io/en/stable/installation/) and also [Installing packages using pip and virtual environments](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)
3. Install **twine** by running `pip install twine`.
4. Create three Pypi repositories in Artifactory - a local, remote and a virtual repository. You can use the [PyPi Repositories Documentation](https://www.jfrog.com/confluence/display/RTF/PyPI+Repositories).
* The remote repository should proxy *https://files.pythonhosted.org* (the default when creating a Pypi remote repository).
* Name the virtual repository *pypi*.
* The virtual repository should include the remote repository.
* The virtual repository should have the local repository set as the *Default Deployment Repository*.
5. Make sure version 2.68.0 or above of [JFrog CLI](https://jfrog.com/getcli/) is installed.

### Validate the Setup
In your terminal, validate that the following commands work.
```console
Output Python version:
> python --version

Output pip version:
> pip --version

Verify twine is installed:
> twine --version

Verify that virtual-environment is activated:
> echo $VIRTUAL_ENV

Output JFrog CLI version:
> jf --version
```

## Running the Example
'cd' to the root project directory

```console
Configure Artifactory:
> jf c add --url=<JFROG_PLATFORM_URL> [credentials flags]

Configure the project's resolution repository. You shoud set the virtual repository you created.
> jf pip-config --repo-resolve=<PYPI_REPO> --repo-deploy=<PYPI_REPO>

Install project dependencies with pip from Artifactory:

Using toml:
> jf pip install .
> python -m build --sdist --wheel

Using Setup.py:
> jf pip install . --build-name=my-pip-build --build-number=1 --module=jfrog-python-example
Package the project, create distribution archives (tar.gz and whl):
> python setup.py sdist bdist_wheel

Upload the packages to the pypi repository in Artifactory:
> jf twine upload "dist/*" --build-name=my-pip-build --build-number=1

Collect environment variables and add them to the build info:
> jf rt bce my-pip-build 1

Publish the build info to Artifactory:
> jf rt bp my-pip-build 1
```

Learn about [Building Python Packages with JFrog CLI](https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-for-jfrog-artifactory/package-managers-integration#building-python-packages).
15 changes: 15 additions & 0 deletions python-example/twine-example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "jfrog-python-example"
version = "1.0"
description = "Project example for building Python project with JFrog products"
authors = [
{ name="JFrog", email="[email protected]" }
]
dependencies = [
"PyYAML>3.11",
"nltk"
]
Empty file.
10 changes: 10 additions & 0 deletions python-example/twine-example/pythonExample/pythonProj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/python

# Function definition is here
def printme( str ):
# This prints a passed string into this function
print (str)
return;

# Now you can call printme function
printme("Hello from JFROG");

0 comments on commit c992342

Please sign in to comment.