Skip to content

Conversation

@bjlittle
Copy link
Member

@bjlittle bjlittle commented May 18, 2021

This PR shows some much needed love to python-stratify.

Namely, it performs the following:

  • migrates the code py2 to py3
  • migrates the CI from travis-ci to cirrus-ci
    • supports linux and osx
  • rationalises the setup.py into the setup.cfg
  • adopts isort
  • adopts pre-commit git hooks to primarily perform black, flake8, isort
  • uses setuptools-scm for version management

@bjlittle
Copy link
Member Author

closes #40

Copy link
Member

@jamesp jamesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I'm a little confused by the versioning system. Where is the version number actually stored/recalled?

populate_script:
- conda-lock --mamba --platform linux-64 --file ${CIRRUS_WORKING_DIR}/requirements/py$(echo ${PY_VER} | tr -d ".").yml
- mamba create --name py${PY_VER} --quiet --file conda-linux-64.lock
- cp conda-linux-64.lock ${HOME}/mambaforge/envs/py${PY_VER}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so you're caching the lock info in the CI 👍

@@ -1,3 +1,4 @@
_version.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file and why explicitly ignored?

Copy link
Member Author

@bjlittle bjlittle May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used by scm and you do not place it under source code control.

It's like a scratch file that scm uses, as per your configuration, to dump its versioning metadata, see pyproject.toml:line+14.

This is then parsed by stratify.init:line+2

fz_src_orig = list(fz_src_reshaped.shape)
shape = (
int(np.product(fz_src_reshaped.shape[:len(bdims)])),
int(np.product(fz_src_reshaped.shape[: len(bdims)])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why space here? seems less readable to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is blacks doing, not me guv

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int(np.product(fz_src_reshaped.shape[: len(bdims)])),
fz_src_reshaped.shape[len(bdims)],
int(np.product(fz_src_reshaped.shape[len(bdims)+1:])))
int(np.product(fz_src_reshaped.shape[len(bdims) + 1 :])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer [(len(bdims) + 1):], adding spaces around slice op is not idiomatic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these changes to the actual code are a result of black auto-fornatting. I trying not to touch the code, other than py2 migration

Copy link
Member Author

@bjlittle bjlittle May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah... what can I say 😱

@bjlittle
Copy link
Member Author

The magic of versioning is handled by setuptools-scm. Perhaps scan through https://github.com/pypa/setuptools_scm/#pyprojecttoml-usage, and that should answer your questions

@bjlittle
Copy link
Member Author

I'm going to push setuptools-scm into iris next btw

build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "stratify/_version.py"
Copy link
Member Author

@bjlittle bjlittle May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell scm where to dump its metadata - this nominated file must not be kept under source code control



__version__ = '0.2.dev0'
from ._version import version as __version__ # noqa: F401
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configure scm

Now we can do python setup.py --version and also get stratify.__version__ as usual

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so setuptools_scm is taking the version number from the latest tag and then applying logic to calculate a new one? Sorry, this is all new to me, I'm sure it makes sense once you've done it a couple of times but seems like magic! If I was to download the package without the .git repo, would it still be able to build/install from source?

Copy link
Member Author

@bjlittle bjlittle May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you've essentially got it. This following section in the pyproject.toml file is like a nominated scratch area for setuptools-scm:

[tool.setuptools_scm]
write_to = "stratify/_version.py"

It can be anything that you want. Also, you can control how scm generates the offset from the latest tag to create your version string, but what you get out the box is good enough for me.

Note that, there is also this plugin setuptools-scm-git-archive which might address your question, but I think the use case having the source code outside git is a bit rare - particularly when it comes to packaging IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesp I actually stumbled across the actual answer to your question regarding the necessity to have access to the .git repo... as I had to jump through that hoop when attempting to build the conda-forge package for the 0.2.post0 release.

You do need access to a .git repo and the associated artifacts for setuptools-scm to do its job of fathoming out what the version of the package. However, if that's not possible, for example this is exactly the case when attempting to conda-build your package from a .tar.gz archive from GitHub, then you need to instead hit the associated PyPI URL for your package as this contain the necessary metadata for setuptools-scm to do it's job i.e., see https://github.com/conda-forge/python-stratify-feedstock/blob/master/recipe/meta.yaml#L9.

Bingo. Just works 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is the use-case I was thinking about. Good to see there is a reasonable workaround, although having conda-forge hanging off of pypi does seem a little Rube Goldberg!

@codecov
Copy link

codecov bot commented May 18, 2021

Codecov Report

❗ No coverage uploaded for pull request base (master@a6749e6). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #41   +/-   ##
=========================================
  Coverage          ?   98.33%           
=========================================
  Files             ?        5           
  Lines             ?      480           
  Branches          ?        0           
=========================================
  Hits              ?      472           
  Misses            ?        8           
  Partials          ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6749e6...e09d203. Read the comment docs.

cpdef public z_target, orig_shape, axis, _zp_reshaped, _fp_reshaped
cpdef public _result_working_shape, result_shape
cdef public z_target, orig_shape, axis, _zp_reshaped, _fp_reshaped
cdef public _result_working_shape, result_shape
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed these from cpdef to cdef to avoid cython future warnings, but functionally a nop change.

@jamesp
Copy link
Member

jamesp commented May 19, 2021

All approved, but I don't have write access to this repo! @bjlittle feel free to merge

@bjlittle
Copy link
Member Author

@jamesp Let me fix that for you...

@bjlittle
Copy link
Member Author

@jamesp You should now have write access to the repo 👍

@jamesp jamesp merged commit d7c939d into SciTools:master May 19, 2021
@bjlittle
Copy link
Member Author

@jamesp Awesome, thanks 🎉

This was referenced May 19, 2021
@bjlittle bjlittle deleted the update branch April 25, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants