Skip to content
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

Revert "Update build configuration, use setuptools_scm" #202

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 2 additions & 8 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
name: CI

on:
push:
branches:
- master
tags:
- "**"
pull_request:
on: [push]

jobs:
build:
strategy:
matrix:
os: [ubuntu-22.04]
pyv: ['3.9', '3.10', '3.11', '3.12']
pyv: [3.9, '3.10', 3.11, 3.12]
max-parallel: 5
runs-on: ${{ matrix.os }}
steps:
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ctlearn/_version.py

*.swp
*.swo
*.gemini
Expand All @@ -17,8 +15,8 @@ ctlearn/_version.py
__pycache__/
*.py[cod]
.DS_Store
*.egg-info/
dist
ctlearn/.DS_Store
ctlearn.egg-info/

# Sphinx documentation
docs/build/
11 changes: 3 additions & 8 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.10"
version: 2

python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- docs
path: .
4 changes: 3 additions & 1 deletion ctlearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
from .run_model import *
from .utils import *

from ._version import __version__
from .version import get_version

__version__ = get_version(pep440=False)
8 changes: 4 additions & 4 deletions ctlearn/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import importlib
import logging
import os
import pkg_resources
import sys
import time

import numpy as np
import pandas as pd
import tables
import yaml

from importlib.metadata import version


def setup_logging(config, log_dir, debug, log_to_file):
# Log configuration to a text file in the log dir
time_str = time.strftime("%Y%m%d_%H%M%S")
config_filename = os.path.join(log_dir, time_str + "_config.yml")
with open(config_filename, "w") as outfile:
ctlearn_version = version("ctlearn")
tensorflow_version = version("tensorflow")
ctlearn_version = pkg_resources.get_distribution("ctlearn").version
tensorflow_version = pkg_resources.get_distribution("tensorflow").version
outfile.write(
"# Training performed with "
"CTLearn version {} and TensorFlow version {}.\n".format(
Expand Down
188 changes: 188 additions & 0 deletions ctlearn/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
"""
Get version identification from git.


The update_release_version() function writes the current version to the
VERSION file. This function should be called before packaging a release version.

Use the get_version() function to get the version string, including the latest
commit, from git.
If git is not available the VERSION file will be read.

Heres an example of such a version string:

v0.2.0.post58+git57440dc


This script was taken from here:
https://github.com/cta-observatory/ctapipe/blob/master/ctapipe/version.py

but the original code comes from here:
https://github.com/aebrahim/python-git-version

Combining ideas from
http://blogs.nopcode.org/brainstorm/2013/05/20/pragmatic-python-versioning-via-setuptools-and-git-tags/
and Python Versioneer
https://github.com/warner/python-versioneer
but being much more lightwheight

"""
import subprocess
from os import path, name, devnull, environ, listdir
from ast import literal_eval

__all__ = ("get_version", "get_version_pypi")

CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
VERSION_FILE = path.join(CURRENT_DIRECTORY, "_version_cache.py")

GIT_COMMAND = "git"

if name == "nt":

def find_git_on_windows():
"""find the path to the git executable on windows"""
# first see if git is in the path
try:
subprocess.check_output(["where", "/Q", "git"])
# if this command succeeded, git is in the path
return "git"
# catch the exception thrown if git was not found
except subprocess.CalledProcessError:
pass
# There are several locations git.exe may be hiding
possible_locations = []
# look in program files for msysgit
if "PROGRAMFILES(X86)" in environ:
possible_locations.append(
"%s/Git/cmd/git.exe" % environ["PROGRAMFILES(X86)"]
)
if "PROGRAMFILES" in environ:
possible_locations.append("%s/Git/cmd/git.exe" % environ["PROGRAMFILES"])
# look for the github version of git
if "LOCALAPPDATA" in environ:
github_dir = "%s/GitHub" % environ["LOCALAPPDATA"]
if path.isdir(github_dir):
for subdir in listdir(github_dir):
if not subdir.startswith("PortableGit"):
continue
possible_locations.append(
"%s/%s/bin/git.exe" % (github_dir, subdir)
)
for possible_location in possible_locations:
if path.isfile(possible_location):
return possible_location
# git was not found
return "git"

GIT_COMMAND = find_git_on_windows()


def get_git_describe_version():
"""return the string output of git desribe"""
try:
with open(devnull, "w") as fnull:
repo_url = "https://github.com/ctlearn-project/ctlearn"
output_lines = subprocess.check_output(
[
"git",
"ls-remote",
"--tags",
"--refs",
"--sort=version:refname",
repo_url,
],
encoding="utf-8",
).splitlines() #nosec
last_line_ref = output_lines[-1].rpartition("/")[-1]
return (last_line_ref)

except (OSError, subprocess.CalledProcessError):
return None


def format_git_describe(git_str, pep440=False):
"""format the result of calling 'git describe' as a python version"""

if "-" not in git_str: # currently at a tag
formatted_str = git_str
else:
# formatted as version-N-githash
# want to convert to version.postN-githash
git_str = git_str.replace("-", ".post", 1)
if pep440: # does not allow git hash afterwards
formatted_str = git_str.split("-")[0]
else:
formatted_str = git_str.replace("-g", "+git")

# need to remove the "v" to have a proper python version
if formatted_str.startswith("v"):
formatted_str = formatted_str[1:]

return formatted_str


def read_release_version():
"""Read version information from VERSION file"""
if not path.exists(VERSION_FILE):
return "unknown"
with open(VERSION_FILE) as f:
return literal_eval(f.read().replace("version=", "", 1))


def update_release_version(pep440=False):
"""Release versions are stored in a file called VERSION.
This method updates the version stored in the file.
This function should be called when creating new releases.
It is called by setup.py when building a package.


pep440: bool
When True, this function returns a version string suitable for
a release as defined by PEP 440. When False, the githash (if
available) will be appended to the version string.

"""
version = get_version(pep440=pep440)
with open(VERSION_FILE, "w") as outfile:
outfile.write(f"version='{version}'")
outfile.write("\n")


def get_version(pep440=False):
"""Tracks the version number.

pep440: bool
When True, this function returns a version string suitable for
a release as defined by PEP 440. When False, the githash (if
available) will be appended to the version string.

The file VERSION holds the version information. If this is not a git
repository, then it is reasonable to assume that the version is not
being incremented and the version returned will be the release version as
read from the file.

However, if the script is located within an active git repository,
git-describe is used to get the version information.

The file VERSION will need to be changed manually.
"""

raw_git_version = get_git_describe_version()
if not raw_git_version: # not a git repository
return read_release_version()

git_version = format_git_describe(raw_git_version, pep440=pep440)

return git_version


def get_version_pypi(abbrev=4):
version = get_version(abbrev)

# return the pure git version
return version.split("+")[0]


if __name__ == "__main__":
print(get_version())
8 changes: 8 additions & 0 deletions ctlearn/versionScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from version import get_version_pypi

def get_version():
return get_version_pypi()


if __name__ == "__main__":
print(get_version())
13 changes: 13 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
astropy
matplotlib
numpy
pandas
pip
pyyaml
scikit-learn
tensorflow
ctaplot
dl1_data_handler
numba
pydot
pyirf
Empty file removed docs/source/_static/.gitkeep
Empty file.
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
import os
import sys
import ctlearn
sys.path.insert(0, os.path.abspath('../../'))

# -- Project information -----------------------------------------------------

Expand All @@ -23,9 +23,9 @@
author = 'CTLearn devs'

# The short X.Y version
version = ctlearn.__version__
version = ''
# The full version, including alpha/beta/rc tags
release = version
release = '0.0.1'


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -62,7 +62,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
7 changes: 7 additions & 0 deletions docs/source/ctlearn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ ctlearn.utils module
:undoc-members:
:show-inheritance:

ctlearn.version module
----------------------

.. automodule:: ctlearn.version
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------
Expand Down
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CTLearn: Deep Learning for IACT Event Reconstruction
installation
usage
suplementary
modules

Documentation
==================
Expand Down
Loading