Skip to content

Commit

Permalink
Merge pull request #6 from ZLLentz/bld_pypi
Browse files Browse the repository at this point in the history
BLD: standards, enable pypi, simplify conda build
  • Loading branch information
ZLLentz authored May 8, 2023
2 parents 0dcf30f + cac807e commit f5fab05
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 242 deletions.
95 changes: 86 additions & 9 deletions .github/workflows/build_and_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:

jobs:
build-and-upload:
conda-build-and-upload:
defaults:
run:
shell: bash --login -eo pipefail {0}
Expand All @@ -14,42 +14,119 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: generate package
run: ./generate_minimal_package.sh

- name: download miniconda
run: |
run: |
wget -q https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p ~/miniconda
echo "source ~/miniconda/etc/profile.d/conda.sh" >> ~/.bash_profile
echo "conda activate base" >> ~/.bash_profile
echo "Conda version is $(conda --version)"
- name: configure miniconda
run: |
conda config --set always_yes yes --set changeps1 no
conda config --set channel_priority strict
conda config --add channels pcds-tag
conda config --add channels conda-forge
conda config --remove channels defaults
- name: install build tools
run: |
conda install -q mamba
mamba install -q anaconda-client boa
mamba install -q anaconda-client boa setuptools-scm
echo "Running using python $(which python)"
echo "Running using mamba $(mamba info -a)"
- name: update and build recipe
- name: Configure setuptools-scm
run: python -m setuptools_scm

- name: build conda recipe
run: |
pushd conda-recipe
./finalize_version.sh
popd
mkdir "${HOME}/conda-bld"
conda mambabuild conda-recipe \
--quiet \
--output-folder "$HOME/conda-bld" \
--no-anaconda-upload
--output-folder "${HOME}/conda-bld" \
--no-anaconda-upload \
--keep-old-work
- name: Upload the built package as an artifact
uses: actions/upload-artifact@v3
with:
name: psdaq-control-minimal conda package
path: ~/conda-bld
if-no-files-found: error

- name: pcds-dev deployment
if: github.event.pull_request.merged == true && github.ref == 'refs/heads/master'
env:
ANACONDA_API_TOKEN: ${{ secrets.CONDA_UPLOAD_TOKEN_DEV }}
run: anaconda upload "${HOME}"/conda-bld/noarch/*.tar.bz2

- name: pcds-tag deployment
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
env:
ANACONDA_API_TOKEN: ${{ secrets.CONDA_UPLOAD_TOKEN_TAG }}
run: anaconda upload "${HOME}"/conda-bld/noarch/*.tar.bz2

pypi-build-and-upload:
defaults:
run:
shell: bash --login -eo pipefail {0}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: generate package
run: ./generate_minimal_package.sh

- name: Upgrade pip
run: |
pip install --upgrade pip
- name: Build wheel and source distribution
run: |
python -m pip install twine build
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
echo "Source date epoch set to ${SOURCE_DATE_EPOCH} for reproducible build"
# See: https://github.com/python/cpython/pull/5200
# And: https://reproducible-builds.org/docs/source-date-epoch/
# (I learned about this from DLS)
python -m build --sdist --wheel --outdir ./dist
- name: Check the source distribution
run: |
python -m venv test-source-env
source test-source-env/bin/activate
python -m pip install ./dist/*.gz
python -c "import psdaq.control.BlueskyScan; print('Imported psdaq.control.BlueskyScan successfully')"
- name: Upload the package as an artifact
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: psdaq-control-minimal pypi package
path: dist
if-no-files-found: error

- name: PyPI deployment
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
if [ -z "$TWINE_PASSWORD" ]; then
echo "# No PYPI_TOKEN secret in job!" | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
fi
twine upload --verbose dist/*
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ ENV/
# Rope project settings
.ropeproject

# vim swap files
# vim swap and undo files
*.swp
*~

# None of the logs
/logs/*

# Generated package
lcls2
psdaq
17 changes: 7 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@
psdaq-control-minimal
===============================

.. image:: https://img.shields.io/travis/pcdshub/psdaq-control-minimal.svg
:target: https://travis-ci.org/pcdshub/psdaq-control-minimal

.. image:: https://img.shields.io/pypi/v/psdaq-control-minimal.svg
:target: https://pypi.python.org/pypi/psdaq-control-minimal

A simple repackaging of the lcls2 daq code at https://github.com/slac-lcls/lcls2 with minimal dependencies needed for controlling the LCLS2 daq from a script, as is done in TMO and RIX's hutch pythons.

A simple repackaging of the lcls2 daq code at https://github.com/slac-lcls/lcls2 with minimal dependencies needed for daq control in hutch python.

This pares down the requirements, unlinks the script entrypoints, and exposes the module ``psdaq.control``.
This pares down the requirements, unlinks the script entrypoints, and exposes only the ``psdaq.control`` submodule.

Requirements
------------

This works with any version of Python >= 3.6.

It requires only ``zmq`` for communicating with the DAQ, and ``ophyd`` and ``bluesky`` for hutch python scanning.
It requires only ``pyzmq`` for communicating with the DAQ, and ``ophyd`` and ``bluesky`` for hutch python scanning.

Installation
------------

``conda install psdaq-control-minimal -c pcds-tag``
or
``pip install psdaq-control-minimal``

Maintenance
-----------

- Push an empty commit to this repo, if none have been made since the last tag. The build currently doesn't work if multiple tags exist on the same commit.
- Create a new tag on this repo that matches a tag on https://github.com/slac-lcls/lcls2/releases to trigger a new build.
- If the setup.py patch gets out of sync, cd into the conda-recipe directory and run ``./generate_patch.sh 3.3.18``, replacing the number with the tag to sync with.
- To test a build locally, you must first cd to conda-recipe and run ``./finalize_version.sh`` to set the version string. This isn't done automatically with versioneer because this isn't a python package. This isn't done automaticaly with conda because I didn't figure out how to do it.
- To test a build locally, you must first run ``./generate_minimal_package.sh`` to clone and set up the minimal set of files.
If you've already done this before, you must manually clear the old ``lcls2`` and ``psdaq`` folders.

Directory Structure
-------------------
Expand Down
4 changes: 0 additions & 4 deletions conda-recipe/finalize_version.sh

This file was deleted.

7 changes: 0 additions & 7 deletions conda-recipe/generate_patch.sh

This file was deleted.

25 changes: 12 additions & 13 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{% set version = "CI_VERSION" %}
{% set package_name = "psdaq-control-minimal" %}
{% set import_name = "psdaq" %}
{% set version = load_file_regex(load_file=os.path.join(import_name, "_version.py"), regex_pattern=".*version = '(\S+)'").group(1) %}

package:
name : psdaq-control-minimal
version : {{ version.split('-')[0] }}
name: {{ package_name }}
version : {{ version }}

source:
git_url: https://github.com/slac-lcls/lcls2.git
git_rev: {{ version.split('-')[0] }}

patches:
- setup.patch
path: ..

build:
number: {{ version.split('-')[1] }}
noarch: python
script: {{ PYTHON }} -m pip install ./psdaq -vv
number: 0
noarch: python
script: {{ PYTHON }} -m pip install . -vv

requirements:
build:
- python >=3.6
- pip
- setuptools-scm
run:
- python >=3.6
- bluesky
- ophyd
- zeromq
- pyzmq

test:
imports:
Expand All @@ -35,4 +34,4 @@ test:
about:
home: https://github.com/pcdshub/psdaq-control-minimal
license: SLAC Open License
summary: A simple repackaging of the lcls2 daq code with minimal dependencies needed for daq control in hutch python.
summary: A minimal repackaging of the lcls2 daq control interface.
Loading

0 comments on commit f5fab05

Please sign in to comment.