Skip to content

Commit

Permalink
Merge pull request #21 from uclahs-cds/aholmes-create-pypi-packages
Browse files Browse the repository at this point in the history
Additional changes to prepare for releasing on PyPI
  • Loading branch information
aholmes authored Oct 18, 2023
2 parents ba6c5b8 + 427c597 commit c76bd7b
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 53 deletions.
22 changes: 18 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
All notable changes to the tool_name Docker file.
All notable changes to the BL_Python monorepo and individual packages contained within.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Expand All @@ -10,8 +10,22 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased]

### Added
- Base package setup configurations
- Libraries for merging dictionaries and profiling methods
- Setuptools package configurations for:
- `BL_Python`
- `BL_Python.AWS`
- `BL_Python.database`
- `BL_Python.development`
- `BL_Python.platform`
- `BL_Python.programming`
- `BL_Python.testing`
- `BL_Python.testing`
- `BL_Python.web`
- Flask application scaffolding
- SQLite support
- Various software development tools
- Various utility classes and methods
- PyPI package metadata
- Documentation for usage and development

### Changed
- Updated template files to fit this repo
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,23 @@ A collection of Python libraries for creating web applications, working with dat

* Create a BL_Python [web application](src/web/README.md)

# Using `BL_Python` in your projects

Currently these libraries are not available in any package repository, and so much be imported via other means.

The suggested method is to use the `git+ssh` [VCS URL](https://pip.pypa.io/en/stable/topics/vcs-support/) with `pip`.

As an example, include the `BL_Python.programming` library like this within `pyproject.toml`:

```toml
[project]
dependencies = [
"bl-python-programming@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/programming"
]
```

Make note of the following:
* The library name is prefixed with `bl-python-` followed by the library name, which is `programming` in this example. This is due to how Python namespaces packages, and the pattern is necessary for the other libraries as well.
* The Git URL is followed by `@`, then `main`. Use this if you want the _unstable_ features in the `main` Git branch. Any Git [ref](https://git-scm.com/book/en/v2/Git-Internals-Git-References) can be used, which is helpful to lock the dependency to a specific version. The `@` is always needed when specifying a ref.
* The Git URL ends with `#subdirectory=src/programming`. This is necessary to specify that the dependency `bl-python-programming` exists at `src/programming`.

## Important requirement!

Due to limitations in `pip`, some `BL_Python` libraries that depend on other `BL_Python` libraries need those dependencies explicitly defined in applications using those libraries.

The libraries that require this will outline their explicit dependencies in their respective readme files. `pip` will also show an error if these requirements are not met, which will aid in discovery of invalid dependency configurations in your applications.

# Available Libraries

Following are each of the libraries in this repository.

They can be used in Python under the `BL_Python` namespace. For example, to use the database libraries you would import from `BL_Python.database`.

To use these packages during development of `BL_Python` itself, please refer to [Development](#development).

## AWS [ `BL_Python.aws` ]
Libraries for working with AWS.

Review the `BL_Python.AWS` [readme](src/AWS/README.md)

#### PyPI Package Name
`bl-python.aws`

#### Git VCS URL
`bl-python-aws@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/AWS`

Expand All @@ -53,6 +33,9 @@ Libraries for working with SQLite and PostgreSQL databases.

Review the `BL_Python.database` [readme](src/database/README.md)

#### PyPI Package Name
`bl-python.database`

#### Git VCS URL
`bl-python-database@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/database`

Expand All @@ -61,6 +44,9 @@ Utilities and tools for assisting in development of software.

Review the `BL_Python.development` [readme](src/development/README.md)

#### PyPI Package Name
`bl-python.development`

#### Git VCS URL
`bl-python-development@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/development`

Expand All @@ -69,6 +55,9 @@ Libraries for PaaS offerings such as tools for altering application configuratio

Review the `BL_Python.platform` [readme](src/platform/README.md)

#### PyPI Package Name
`bl-python.platform`

#### Git VCS URL
`bl-python-platform@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/platform`

Expand All @@ -77,6 +66,9 @@ Libraries used for writing software, such as pattern implementations so wheels d

Review the `BL_Python.programming` [readme](src/programming/README.md)

#### PyPI Package Name
`bl-python.programming`

#### Git VCS URL
`bl-python-programming@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/programming`

Expand All @@ -85,6 +77,9 @@ Libraries used to aid in automated testing.

Review the `BL_Python.testing` [readme](src/testing/README.md)

#### PyPI Package Name
`bl-python.testing`

#### Git VCS URL
`bl-python-testing@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/testing`

Expand All @@ -93,6 +88,9 @@ Libraries used to building web applications.

Review the `BL_Python.web` [readme](src/web/README.md)

#### PyPI Package Name
`bl-python.web`

#### Git VCS URL
`bl-python-web@ git+ssh://[email protected]/uclahs-cds/private-BL-python-libraries.git@main#subdirectory=src/web`

Expand All @@ -104,4 +102,10 @@ When developing from within the mono-repo, the libraries can be individually ins

To install the base dependencies, run `pip install -e .` from the mono-repo root. Development dependencies can be installed with `pip install -e .[dev-dependencies]`

To install the library dependencies, run, for example, `pip install -e src/web` to install `BL_Python.web`. Similar to the mono-repo, development dependencies can be installed with `pip install -e src/web[dev-dependencies]`.
To install the library dependencies, run, for example, `pip install -e src/web` to install `BL_Python.web`. Similar to the mono-repo, development dependencies can be installed with `pip install -e src/web[dev-dependencies]`.

## Important requirement!

Due to limitations in `pip`, some `BL_Python` libraries that depend on other `BL_Python` libraries need those dependencies explicitly defined in applications using those libraries.

The libraries that require this will outline their explicit dependencies in their respective readme files. `pip` will also show an error if these requirements are not met, which will aid in discovery of invalid dependency configurations in your software.
97 changes: 97 additions & 0 deletions publish_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
set -eEo pipefail

spinwait_pid=
spinwait_col=
spinwait() {
IFS=';'
# inspiration https://unix.stackexchange.com/a/183121
read -sdR -p $'\E[6n' spinwait_row spinwait_col
spinwait_row="${spinwait_row#*[}"

s=(\| / - \\)
i=0
while true; do
tput cup $((spinwait_row-1)) $spinwait_col 2> /dev/null
echo -en " ${s[i]}"; i=$(( (i + 1) % ${#s[@]}))
sleep 0.2
done &
spinwait_pid=$!
}
spinwait-stop() {
optional_msg=$1
kill $spinwait_pid 2> /dev/null
tput cup $((spinwait_row-1)) $spinwait_col 2> /dev/null
[ -n "$optional_msg" ] && echo -e " $optional_msg" || echo -e " "
}

project_name=
get-project-name() {
# inspiration https://stackoverflow.com/a/73519411
project_name=$(awk \
-F' = ' \
-v s="project" \
-v p="name" \
'
# process only sections (they start with ^[ )
/^\[/{
gsub(/[\[\]]/, "", $1)
f = ($1 == s)
next
}
# print only the value following the ` = `
# only for the line starting with `name = `
NF && f && $1==p{
gsub(/"/, "", $2)
print $2
}' pyproject.toml)
}

trap 'spinwait-stop' ERR
trap 'spinwait-stop; exit' SIGINT SIGTERM
build() {
dir="$1"
pushd $dir 1> /dev/null
get-project-name
echo -n Building $project_name
spinwait
rm -rf dist/
python -m build 1> /dev/null
spinwait-stop done
popd 1> /dev/null
}

publish() {
set +e
local dir="$1"
local repository
[ -n "$2" ] && repository="$2" || repository="testpypi"
pushd $dir 1> /dev/null
get-project-name
echo Publishing $project_name to $repository
python -m twine upload --repository $repository dist/*
popd 1> /dev/null
}

declare -a packages=( \
. \
src/AWS \
src/database \
src/development \
src/platform \
src/programming \
src/testing \
src/web
)

for package in ${packages[@]}; do
build $package
done

# default to testpypi
[ -n "$1" ] && repository="$1" || repository="testpypi"

tput init 2> /dev/null
for package in ${packages[@]}; do
publish $package $repository
done
19 changes: 17 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ description = 'Python libraries for use in Boutros Lab.'
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent"
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Development Status :: 4 - Beta",
"Natural Language :: English"
]
dependencies = []

dynamic = ["version", "readme"]
[tool.setuptools.dynamic]
version = {attr = "src.__version__"}
version = {attr = "BL_Python.__version__"}
readme = {file = ["README.md"], content-type = "text/markdown"}

[project.urls]
"Homepage" = "https://github.com/uclahs-cds/BL_Python"
"Bug Tracker" = "https://github.com/uclahs-cds/BL_Python/issues"
"Repository" = "https://github.com/uclahs-cds/BL_Python.git"
"Changelog" = "https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md"

[tool.setuptools.package-dir]
"BL_Python" = "src"
"BL_Python.AWS" = "src/AWS/BL_Python/AWS"
"BL_Python.database" = "src/database/BL_Python/database"
"BL_Python.development" = "src/development/BL_Python/development"
Expand All @@ -38,6 +52,7 @@ readme = {file = ["README.md"], content-type = "text/markdown"}

[tool.setuptools]
packages = [
"BL_Python",
"BL_Python.AWS",
"BL_Python.database",
"BL_Python.development",
Expand Down
3 changes: 3 additions & 0 deletions src/AWS/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

Review the `BL_Python` [CHANGELOG.md](https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md).
15 changes: 14 additions & 1 deletion src/AWS/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ description = 'Libraries for working with AWS services in Boutros Lab.'
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent"
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Development Status :: 4 - Beta",
"Natural Language :: English"
]

dependencies = [
Expand All @@ -29,6 +36,12 @@ dynamic = ["version", "readme"]
version = {attr = "BL_Python.AWS.__version__"}
readme = {file = ["README.md"], content-type = "text/markdown"}

[project.urls]
"Homepage" = "https://github.com/uclahs-cds/BL_Python"
"Bug Tracker" = "https://github.com/uclahs-cds/BL_Python/issues"
"Repository" = "https://github.com/uclahs-cds/BL_Python.git"
"Changelog" = "https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md"

[tool.setuptools.package-dir]
"BL_Python.AWS" = "BL_Python/AWS"

Expand Down
3 changes: 3 additions & 0 deletions src/database/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

Review the `BL_Python` [CHANGELOG.md](https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md).
15 changes: 14 additions & 1 deletion src/database/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ description = 'Libraries for working with databases in Boutros Lab.'
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent"
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Development Status :: 4 - Beta",
"Natural Language :: English"
]

dependencies = [
Expand All @@ -34,6 +41,12 @@ dynamic = ["version", "readme"]
version = {attr = "BL_Python.database.__version__"}
readme = {file = ["README.md"], content-type = "text/markdown"}

[project.urls]
"Homepage" = "https://github.com/uclahs-cds/BL_Python"
"Bug Tracker" = "https://github.com/uclahs-cds/BL_Python/issues"
"Repository" = "https://github.com/uclahs-cds/BL_Python.git"
"Changelog" = "https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md"

[tool.setuptools.package-dir]
"BL_Python.database" = "BL_Python/database"

Expand Down
3 changes: 3 additions & 0 deletions src/development/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

Review the `BL_Python` [CHANGELOG.md](https://github.com/uclahs-cds/BL_Python/blob/main/CHANGELOG.md).
Loading

0 comments on commit c76bd7b

Please sign in to comment.